fix: Postgres store 自愈连接池 + 启用 PG checkpointer + 分析查询超时按服务端适配
- async_provider: AsyncPostgresStore 改用连接池(check_connection 校验), 避免单条长连接在服务重启/空闲超时后永久失效;池大小可经 DEER_FLOW_PG_POOL_MIN/MAX 环境变量调整 - admin_users: 排行榜分析查询的每语句超时按服务端区分 (MySQL>=5.7.4 max_execution_time / MariaDB max_statement_time / MySQL<=5.6 跳过 / PostgreSQL statement_timeout) - config.yaml: checkpointer.use_postgres 置为 true Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
50d70a5050
commit
40206dc94d
3 files changed
+66
-7
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