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:
@ -62,7 +62,7 @@ redis:
|
|||||||
# opendal:
|
# opendal:
|
||||||
# scheme: 'mysql' # Storage type, such as s3, oss, azure, etc.
|
# scheme: 'mysql' # Storage type, such as s3, oss, azure, etc.
|
||||||
# config:
|
# config:
|
||||||
# oss_table: 'your_table_name'
|
# oss_table: 'opendal_storage'
|
||||||
# user_default_llm:
|
# user_default_llm:
|
||||||
# factory: 'Tongyi-Qianwen'
|
# factory: 'Tongyi-Qianwen'
|
||||||
# api_key: 'sk-xxxxxxxxxxxxx'
|
# api_key: 'sk-xxxxxxxxxxxxx'
|
||||||
|
|||||||
@ -1,11 +1,10 @@
|
|||||||
import opendal
|
import opendal
|
||||||
import logging
|
import logging
|
||||||
import pymysql
|
import pymysql
|
||||||
import yaml
|
|
||||||
|
|
||||||
|
from api.utils import get_base_config
|
||||||
from rag.utils import singleton
|
from rag.utils import singleton
|
||||||
|
|
||||||
SERVICE_CONF_PATH = "conf/service_conf.yaml"
|
|
||||||
|
|
||||||
CREATE_TABLE_SQL = """
|
CREATE_TABLE_SQL = """
|
||||||
CREATE TABLE IF NOT EXISTS `{}` (
|
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:
|
try:
|
||||||
with open(yaml_path, 'r') as f:
|
opendal_config = get_base_config('opendal', {})
|
||||||
config = yaml.safe_load(f)
|
|
||||||
|
|
||||||
opendal_config = config.get('opendal', {})
|
|
||||||
kwargs = {}
|
|
||||||
if opendal_config.get("scheme") == 'mysql':
|
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 = {
|
kwargs = {
|
||||||
"scheme": "mysql",
|
"scheme": "mysql",
|
||||||
"host": mysql_config.get("host", "127.0.0.1"),
|
"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"),
|
"user": mysql_config.get("user", "root"),
|
||||||
"password": mysql_config.get("password", ""),
|
"password": mysql_config.get("password", ""),
|
||||||
"database": mysql_config.get("name", "test_open_dal"),
|
"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:
|
else:
|
||||||
scheme = opendal_config.get("scheme")
|
scheme = opendal_config.get("scheme")
|
||||||
config_data = opendal_config.get("config", {})
|
config_data = opendal_config.get("config", {})
|
||||||
@ -53,7 +50,7 @@ def get_opendal_config_from_yaml(yaml_path=SERVICE_CONF_PATH):
|
|||||||
@singleton
|
@singleton
|
||||||
class OpenDALStorage:
|
class OpenDALStorage:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._kwargs = get_opendal_config_from_yaml()
|
self._kwargs = get_opendal_config()
|
||||||
self._scheme = self._kwargs.get('scheme', 'mysql')
|
self._scheme = self._kwargs.get('scheme', 'mysql')
|
||||||
if self._scheme == 'mysql':
|
if self._scheme == 'mysql':
|
||||||
self.init_db_config()
|
self.init_db_config()
|
||||||
@ -95,7 +92,7 @@ class OpenDALStorage:
|
|||||||
)
|
)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
max_packet = self._kwargs.get('max_allowed_packet', 4194304) # Default to 4MB if not specified
|
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()
|
conn.commit()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user