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

Abierto
#33,256 0 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@matrix-meow ya está trabajando en esto.

Desde el 26/11/2026.

  • #33327 de @VioletQwQ-0 — abierto

Evaluación

Este issue todavía no se ha evaluado.

Descripción

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
Lenguaje dominante
Go
Estrellas
1.9k
Forks
312
Merge medio
21 h 57 min
PR fusionados (30 d)
730

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de matrixorigin/matrixone

Todos los issues de matrixorigin/matrixone

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.