[Bug]: system_metrics.metric duplicate rows after commit-result-unknown triggers CSV fallback and ETL re-import

Open
#33,256 0 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@matrix-meow is already working on this.

Since Nov 26, 2026.

  • #33327 by @VioletQwQ-0 — open

Assessment

This issue has not been assessed yet.

Description

kind/bug
Is there an existing issue for the same bug?
  • I have checked the existing issues. Related closed issue: #22517 (same failing SQL assertion, previously closed without identifying the root cause); related upstream trigger: #19483 (too large wal message error handle, still open).
Branch Name

main

Commit ID

ca5325ce683 (observed in CI run 45584592765 on PR #32989, unrelated to the PR diff)

Actual Behavior

In Pessimistic multi-CN BVT, test/distributed/cases/log/column_metric.sql (line 3) fails with 693 duplicate metric groups (2 rows per group):

select count(1) cnt, metric_name, collecttime, `node`, role, account, type
from system_metrics.metric
group by metric_name, collecttime, `node`, role, account, account_id, type
having cnt > 1;
Root-cause evidence chain (CN + TN + ETL logs)
  1. Upstream TN commit queue stall (103s):
    • A background merge task [MT-18264]-275681-rfc_t (txn 01A2120FB5097037B7DB100F8F623FDA) stalled in TN PrePrepareDedup for 1m43.07s and then failed on oversized WAL:
      2026/11/25 09:35:49.001059 +0000 INFO mergesort/task.go:458 [MERGE-START] {"task": "[MT-18264]-275681-rfc_t", "txn-info": "ctx[01A2120FB5097037B7DB100F8F623FDA]..."}
      2026/11/25 09:37:51.088862 +0000 INFO txnimpl/txndb.go:558 SLOW-LOG-PrePrepareDedup {"txn": "ctx[01A2120FB5097037B7DB100F8F623FDA]...", "duration": "1m43.074878513s"}
      2026/11/25 09:37:51.088992 +0000 ERROR txnimpl/store.go:849 error: internal error: txn 01a2120fb5097037b7db100f8f623fda WAL entry approxSize 249561088 is too large, max is 73400320
      
  2. CN receives commit-result-unknown while TN commits:
    • While preWalQueue was blocked (09:36–09:38 UTC / 17:36–17:38 CST), 24 LOAD DATA INLINE transactions into system_metrics.metric (plus 5 into system_metrics.sql_statement_cu) timed out on CN with commit result unknown (pkg/txn/rpc/sender.go:193).
    • Once the stall cleared, TN logged all 29 transactions as Committed (commit latency 11–103s for the 24 metric writes).
  3. Unconditional CSV fallback + missing deduplication in ETL import:
    • On any err != nil from sqlFlusher.FlushBuffer, ContentWriter.FlushAndClose (pkg/util/export/etl/content.go:140-161) writes the same buffer to a fallback CSV file.
    • At 09:40:12 UTC, ETL (pkg/util/export/merge.go:404-461) processed and deleted all 24 metric CSV files.
    • db_holder.IsRecordExisted (pkg/util/export/etl/db/db_holder.go:423-462) only checks statement_info and unconditionally returns false, nil for system_metrics.metric (and sql_statement_cu), which have no primary key.
    • The 24 fallback CSV files match all 693 duplicate groups by (collecttime second, node, role), producing exact 2x duplicates when column_metric.sql ran at 09:46:33 UTC.
Expected Behavior
  1. When a metrics LOAD DATA INLINE returns an ambiguous/unknown commit outcome (ErrTxnResultUnknown / stream error after commit sent) and TN actually committed the transaction, the CSV fallback + ETL import path must not insert duplicate rows into system_metrics.metric (or sql_statement_cu).
  2. When the original transaction genuinely rolled back / failed before commit, the CSV fallback + ETL import path must still deliver the batch exactly once (no data loss).
Proposed Fix Direction
  1. Delivery / fallback boundary (pkg/util/export/etl/content.go, pkg/util/export/merge.go, pkg/util/export/etl/db/db_holder.go):
    • Distinguish definite rollback/failure from unknown commit outcome (moerr.IsMoErrCode(..., moerr.ErrTxnResultUnknown) or equivalent transport error after commit).
    • Ensure fallback CSV files written on unknown outcome cannot race ahead of an in-flight TN commit still draining in preWalQueue, and verify whether one CSV file corresponds to one atomic SQL LOAD batch or multiple batches.
    • Extend existence / idempotency protection in ETL import (e.g., db_holder.IsRecordExisted for system_metrics.metric leveraging CLUSTER BY (collecttime, account_id, metric_name) and system_metrics.sql_statement_cu leveraging CLUSTER BY (account, collecttime), or batch-level idempotent identity) so already-committed batches are skipped while genuinely rolled-back batches are still imported.
  2. Follow-up on upstream oversized WAL stall: Tracked under #19483 (MT-18264 249MB WAL failing after 103s in PrePrepareDedup).
Additional Information
Dominant language
Go
Stars
1.9k
Forks
312
Avg merge
22h 59m
Merged PRs (30d)
736

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from matrixorigin/matrixone

All issues in matrixorigin/matrixone

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.