Repository navigation
Description
版本信息
- MatrixOne 版本: prod / v3.0.11-6a0394c4f-2026-05-11(freetier-01 集群)
- 组件: CN (Compute Node)
- 涉及模块:
system.statement_info查询执行、连接迁移 (connection migration / draining) - 部署环境: prod freetier-01,DP 集群
ack-prod-unit-hz - 关联 Issue: https://github.com/matrixorigin/matrixflow/issues/11053 (上游调用方 moi-backend 缺超时保护)
Bug Description
Queries on system.statement_info with COUNT(*) aggregation get stuck indefinitely on a CN pod, blocking connection migration (draining) and triggering CNDrainingTooLong alert.
Environment
- Cluster: prod freetier-01
- CN Pod:
freetier-01-s2-56c954c888-cn-mwmhj - Node ID:
35313934-6664-6433-3939-613132616631 - Alert:
CNDrainingTooLong— CN stuck in draining state for 2+ hours
Symptoms
4 concurrent SELECT COUNT(*) queries on system.statement_info have been running for 2+ hours without returning:
-- Pattern 1: COUNT with request_at filter (3 sessions)
SELECT COUNT(*) FROM system.statement_info
WHERE 1=1
AND `account` = 'ws_d604d949'
AND `user` = 'u_a08698ecd6d142b891bb5bf57c41eeb9'
AND `request_at` >= '2026-06-07 11:36:11'
AND `sql_source_type` IN ('cloud_user_sql', 'external_sql')
-- Pattern 2: COUNT + SUM(CASE) aggregation (1 session)
SELECT COUNT(*) AS total,
COALESCE(SUM(CASE WHEN `status` = 'Success' THEN 1 ELSE 0 END), 0) AS success,
COALESCE(SUM(CASE WHEN `status` = 'Running' THEN 1 ELSE 0 END), 0) AS running,
COALESCE(SUM(CASE WHEN `status` = 'Failed' THEN 1 ELSE 0 END), 0) AS failed
FROM system.statement_info
WHERE 1=1
AND `account` = 'ws_d604d949'
AND `user` = 'u_a08698ecd6d142b891bb5bf57c41eeb9'
AND `sql_source_type` IN ('cloud_user_sql', 'external_sql')These queries block CN draining because active sessions cannot be migrated away.
Processlist Evidence
mysql> select * from processlist() p where p.node_id = '35313934-6664-6433-3939-613132616631'\G
-- Row 1: started 13:36:13, still running at 15:38+
node_id: 35313934-6664-6433-3939-613132616631
conn_id: 3879487042
session_id: 019ea24c-5916-7ebb-b898-667a8cb86517
account: ws_d604d949
query_start: 2026-06-07 13:36:13.949785
sql_source_type: cloud_nonuser_sql
-- Row 2: started 13:37:02
conn_id: 3879493716
query_start: 2026-06-07 13:37:02.043596
-- Row 3 (overview query): started 13:37:02
conn_id: 3879493394
query_start: 2026-06-07 13:37:02.221351
-- Row 4: started 13:37:05
conn_id: 3879493787
query_start: 2026-06-07 13:37:05.662776
CN Draining Status
NAME PHASE MIGRAT
freetier-01-s2-56c954c888-cn-mwmhj Terminating y Running 2026-06-04T09:30:04Z
Pod has been in Terminating with MIGRAT=y since 2026-06-04, stuck for 3+ days because these sessions cannot be migrated.
Impact
- CN pod cannot complete draining → resource leak (pod stuck in Terminating)
CNDrainingTooLongalert fires continuously- Potential cascading impact if more queries pile up on the same CN
Expected Behavior
- Queries on
system.statement_infowith account/user/request_at filters should complete in reasonable time (seconds, not hours) - If a query runs too long, the CN draining mechanism should be able to forcefully cancel stuck queries after a configurable timeout
Analysis
The system.statement_info table in prod environments accumulates massive amounts of data. A COUNT(*) without time-bounded partition pruning can result in full table scans that take extremely long. The query includes request_at >= '2026-06-07 11:36:11' (only ~2h window) but if partition/index pruning is not effective, the scan is unbounded.
Additionally, the CN draining logic appears to wait indefinitely for all active sessions to complete — there is no forced cancellation timeout for long-running queries during migration.
Suggested Fix
- Query performance: Ensure
system.statement_infoqueries withaccount + request_atfilters can leverage partition pruning effectively - Draining timeout: Add a configurable max-wait-time for CN draining; after the timeout, forcefully cancel remaining queries and proceed with migration
- Query timeout at engine level: Consider supporting a session-level or statement-level query timeout that the CN can enforce
Labels
- Type: Bug
- Component: CN, statement_info, connection migration
Activity
[-]system.statement_info COUNT queries stuck indefinitely, blocking CN draining[/-][+][bug] system.statement_info COUNT queries stuck indefinitely, blocking CN draining[/+]xzxiong commentedon Jun 7, 2026
遗留的Conn具体的 processlist info
aptend commentedon Jun 29, 2026
optimized in 4.0, #23149
slyunnn commentedon Aug 28, 2026
Regression and extended verification for #24872 (2026-08-28)
Verification Environment
origin/4.2-devcommit635de0535a21807c02ee49f37331406921c7889b:[4.2] Backport fixes for issues #26720 and #25114 (#27313).e3fd7fe1e83b251d0af13c86f072e10e85cbece2,Optimize CLUSTER BY for statement_info and metric tables; it is reachable from4.2-dev.1 Log + 1 TN + 1 CN; Log/Hakeeper127.0.0.1:62001, TN127.0.0.1:59100, CN SQL endpoint127.0.0.1:36001.issue24872:rootand actualCOM_STMT_PREPARE/COM_STMT_EXECUTE.What Was Covered
system.statement_infodefinition reportsCLUSTER BY (request_at, account_id).COUNT(*)SQL was executed concurrently in three sessions with the original account, user, time, andsql_source_typepredicate shape; all returned0in0-1 ms.COUNT(*)andSUM(CASE ...)was executed concurrently and returnedtotal=0,success=0,running=0, andfailed=0in1 ms.EXPLAINshowed automaticaccount_id = 10001injection and block filters on bothrequest_atandaccount_id.statement_infodata and the reported multi-hour execution were unavailable locally. Therefore no production-scale timing or CN draining completion measurement was made.Findings
The #23149 cluster-key and tenant predicate path is present in
4.2-dev. The original MySQL prepared-statement query shapes complete promptly on an ordinary tenant, and the plan exposes the expected(request_at, account_id)pruning predicates.MOTR / BVT Coverage
No MOTR test, branch, commit, or PR was created: this request was limited to dev-branch regression verification without extension.
Final Conclusion
Partially fixed. The original prepared-query functional path and the expected cluster/block pruning predicates passed on
4.2-dev. A large-data regression is required to fully close the production performance and CN-draining aspect, because those outcomes depend on the number of historical rows and blocks; increasing unrelated CI data is not useful, but a controlled large multi-blockstatement_infodataset is necessary.