ソースを参照

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>
tags/v0.20.0
He Wang 4ヶ月前
コミット
695bfe34a2
コミッターのメールアドレスに関連付けられたアカウントが存在しません
2個のファイルの変更11行の追加14行の削除
  1. 1
    1
      conf/service_conf.yaml
  2. 10
    13
      rag/utils/opendal_conn.py

+ 1
- 1
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'

+ 10
- 13
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()

読み込み中…
キャンセル
保存