Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix opendal config 'oss_table' and 'max_allowed_packet' (#8611)

He Wang695bfe34a2ac
diff --git a/conf/service_conf.yaml b/conf/service_conf.yaml
index 4c0635770c..7a94a2a1de 100644
--- a/conf/service_conf.yaml
+++ b/conf/service_conf.yaml
@@ -62,7 +62,7 @@ redis:
# opendal:
# scheme: 'mysql' # Storage type, such as s3, oss, azure, etc.
# config:
-# oss_table: 'your_table_name'
+# oss_table: 'opendal_storage'
# user_default_llm:
# factory: 'Tongyi-Qianwen'
# api_key: 'sk-xxxxxxxxxxxxx'
diff --git a/rag/utils/opendal_conn.py b/rag/utils/opendal_conn.py
index 7a3b44f0d6..731abf6d6d 100644
--- a/rag/utils/opendal_conn.py
+++ b/rag/utils/opendal_conn.py
@@ -1,11 +1,10 @@
import opendal
import logging
import pymysql
-import yaml
+from api.utils import get_base_config
from rag.utils import singleton
-SERVICE_CONF_PATH = "conf/service_conf.yaml"
CREATE_TABLE_SQL = """
CREATE TABLE IF NOT EXISTS `{}` (
@@ -20,15 +19,12 @@ SET GLOBAL max_allowed_packet={}
"""
-def get_opendal_config_from_yaml(yaml_path=SERVICE_CONF_PATH):
+def get_opendal_config():
try:
- with open(yaml_path, 'r') as f:
- config = yaml.safe_load(f)
-
- opendal_config = config.get('opendal', {})
- kwargs = {}
+ opendal_config = get_base_config('opendal', {})
if opendal_config.get("scheme") == 'mysql':
- mysql_config = config.get('mysql', {})
+ mysql_config = get_base_config('mysql', {})
+ max_packet = mysql_config.get("max_allowed_packet", 134217728)
kwargs = {
"scheme": "mysql",
"host": mysql_config.get("host", "127.0.0.1"),
@@ -36,9 +32,10 @@ def get_opendal_config_from_yaml(yaml_path=SERVICE_CONF_PATH):
"user": mysql_config.get("user", "root"),
"password": mysql_config.get("password", ""),
"database": mysql_config.get("name", "test_open_dal"),
- "table": opendal_config.get("config").get("table", "opendal_storage")
+ "table": opendal_config.get("config").get("oss_table", "opendal_storage"),
+ "max_allowed_packet": str(max_packet)
}
- kwargs["connection_string"] = f"mysql://{kwargs['user']}:{kwargs['password']}@{kwargs['host']}:{kwargs['port']}/{kwargs['database']}"
+ kwargs["connection_string"] = f"mysql://{kwargs['user']}:{kwargs['password']}@{kwargs['host']}:{kwargs['port']}/{kwargs['database']}?max_allowed_packet={max_packet}"
else:
scheme = opendal_config.get("scheme")
config_data = opendal_config.get("config", {})
@@ -53,7 +50,7 @@ def get_opendal_config_from_yaml(yaml_path=SERVICE_CONF_PATH):
@singleton
class OpenDALStorage:
def __init__(self):
- self._kwargs = get_opendal_config_from_yaml()
+ self._kwargs = get_opendal_config()
self._scheme = self._kwargs.get('scheme', 'mysql')
if self._scheme == 'mysql':
self.init_db_config()
@@ -95,7 +92,7 @@ class OpenDALStorage:
)
cursor = conn.cursor()
max_packet = self._kwargs.get('max_allowed_packet', 4194304) # Default to 4MB if not specified
- cursor.execute(SET_MAX_ALLOWED_PACKET_SQL, (max_packet,))
+ cursor.execute(SET_MAX_ALLOWED_PACKET_SQL.format(max_packet))
conn.commit()
cursor.close()
conn.close()