mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
fix opendal config 'oss_table' and 'max_allowed_packet' (#8611)
### What problem does this PR solve? Fix the config option name of the opendal table name and setting of 'max_allowed_packet'. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) Signed-off-by: He Wang <wanghechn@qq.com>
This commit is contained in:
@ -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()
|
||||
|
||||
Reference in New Issue
Block a user