Merge branch 'ji' of http://192.168.0.200/knowledge-base-bj/deerflow-server into ji
This commit is contained in:
commit
24db448cfd
10 files changed
+555
-146
No files matched your search
@@ -458,13 +458,36 @@ async def _try_set_session_value(session, sql: str) -> None:
|
||||
logger.debug("Failed to rollback after analytics session setting failure", exc_info=True)
|
||||
|
||||
|
||||
def _is_mariadb(dialect) -> bool:
|
||||
"""SQLAlchemy reports ``dialect.name == 'mysql'`` for MariaDB too."""
|
||||
if getattr(dialect, "_is_mariadb", False) or getattr(dialect, "is_mariadb", False):
|
||||
return True
|
||||
version_info = getattr(dialect, "server_version_info", None) or ()
|
||||
return any("mariadb" in str(part).lower() for part in version_info)
|
||||
|
||||
|
||||
async def _set_analytics_read_timeout(session) -> None:
|
||||
"""Best-effort per-statement read timeout for the analytics queries.
|
||||
|
||||
The right knob differs by server, and some servers have none at all:
|
||||
- MySQL >= 5.7.4: ``max_execution_time`` (milliseconds)
|
||||
- MariaDB: ``max_statement_time`` (seconds)
|
||||
- MySQL <= 5.6: no per-statement timeout variable — skip it entirely
|
||||
(5.6 raises "Unknown system variable" otherwise)
|
||||
- PostgreSQL: ``statement_timeout`` (milliseconds)
|
||||
"""
|
||||
conn = await session.connection()
|
||||
dialect = conn.dialect.name
|
||||
if dialect == "mysql":
|
||||
await _try_set_session_value(session, f"SET SESSION max_execution_time = {_LEADERBOARD_QUERY_TIMEOUT_MS}")
|
||||
dialect = conn.dialect
|
||||
name = dialect.name
|
||||
if name == "mysql":
|
||||
if _is_mariadb(dialect):
|
||||
# MariaDB: max_statement_time is in SECONDS (fractional ok).
|
||||
await _try_set_session_value(session, f"SET SESSION max_statement_time = {_LEADERBOARD_QUERY_TIMEOUT_MS / 1000}")
|
||||
elif (getattr(dialect, "server_version_info", None) or ()) >= (5, 7, 4):
|
||||
await _try_set_session_value(session, f"SET SESSION max_execution_time = {_LEADERBOARD_QUERY_TIMEOUT_MS}")
|
||||
# else: MySQL <= 5.6 has no statement-timeout variable — skip silently.
|
||||
await _try_set_session_value(session, f"SET SESSION innodb_lock_wait_timeout = {_LEADERBOARD_LOCK_WAIT_SECONDS}")
|
||||
elif dialect == "postgresql":
|
||||
elif name == "postgresql":
|
||||
await _try_set_session_value(session, f"SET LOCAL statement_timeout = {_LEADERBOARD_QUERY_TIMEOUT_MS}")
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user