Skip to content

fix(backup): preserve hidden commitTS in rewritten tombstones - #27003

Merged
XuPeng-SH merged 7 commits into
matrixorigin:4.2-devfrom
LeftHandCold:fix/26991-backup-tombstone-committs-4.2
Aug 13, 2026
Merged

XuPeng-SH merged 7 commits into
matrixorigin:4.2-devfrom
LeftHandCold:fix/26991-backup-tombstone-committs-4.2

Conversation

@LeftHandCold

@LeftHandCold LeftHandCold commented Aug 12, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #26991

What this PR does / why we need it:

This is the 4.2-dev backport of #26998, adapted to the 4.2 tombstone reader and on-disk layout.

Backup rewrites appendable TN tombstones after filtering rows by the backup timestamp. The old rewrite path used a generic block writer, which assigned dense seqnums to the physical [rowid, pk, commitTS] batch. As a result, commitTS was persisted as ordinary seqnum 2 instead of hidden SEQNUM_COMMITTS.

The v4.1 reader inferred that trailing column by position, so a v4.1.4 backup restored by v4.1.4 still works. The stricter 4.2 reader treats commitTS as absent, synthesizes a const-null vector with no fixed backing values, and could panic, reject recovery, silently omit tombstones, or conservatively report false PK conflicts depending on the consumer.

This PR closes both the producer and every identified reader boundary.

For newly generated backups, the trim path now produces one canonical non-appendable TN tombstone layout:

physical columns: [rowid, pk, commitTS]
seqnums:          [0, 1, SEQNUM_COMMITTS]
meta columns:     3
max seqnum:       1

The producer implementation:

  • resolves commitTS, abort, and physical-rowid positions from source object metadata;
  • filters aborted rows and rows newer than the backup timestamp before rewriting;
  • drops the stale physical row address and the already-consumed abort column;
  • writes rewritten tombstones with explicit hidden-column seqnums;
  • materializes a valid N-row constant commitTS before BlockWriter, whose fixed-width metadata scan otherwise indexes beyond the one-value backing;
  • validates malformed source columns and releases rewritten batches on success and error paths without double-freeing shared objData references.

For existing malformed Backup artifacts, the reader implementation:

  • recognizes only the exact non-CN, non-appendable three-column signature (meta_columns=3, max_seq=2, [Rowid, PK, TS], and no strict hidden commitTS);
  • reloads physical column 2 as commitTS while keeping a timestamp-valued user PK distinct;
  • validates commitTS at shared reader boundaries and returns bounded errors for missing, null, wrong-type, length-mismatched, or short-backing vectors;
  • preserves valid non-null constant-vector broadcast semantics in point lookup, block-mask evaluation, stats readers, local tombstone application, PK-change checks, and TAE persisted scans;
  • routes persistedNode.Scan and CollectObjectTombstoneInRange through the compatibility mapping, while preserving the established two-column CN tombstone CreatedAt semantics;
  • releases the first cache lease and temporary vector wrappers before compatibility reload, then transfers or releases the final copy/zero-copy ownership exactly once;
  • propagates an initial merge-stats iterator read error instead of silently returning an undercount, while releasing previously admitted iterators.

4.2-dev predates the shared objectio.SpecialColumnLayout and still uses a reader layout without abort ([rowid, commitTS], or [rowid, pk, commitTS] when PK is requested). This backport preserves that 4.2 protocol and keeps an equivalent special-column resolver local to Backup instead of pulling later appendable-object/abort reader changes into the maintenance branch.

The fix is fileservice-backend independent, so DISK, DISK-V2, and S3 Backup rewrites use the same corrected metadata and reader paths.

Validation:

  • deterministic old generic-writer artifact consumed through point lookup, block mask, Backup datasource, varlen-PK search, TAE copy Scan, zero-copy Scan, and range collection;
  • CN-created two-column control proving Scan and range collection still derive commitTS from object CreatedAt;
  • timestamp-valued user-PK counterexample proving PK and trailing commitTS remain distinct;
  • exact compatibility-reload failure injection and non-legacy error paths with cache-lease accounting;
  • source layouts with commitTS only and physical rowid before/after commitTS;
  • abort metadata compatibility at the Backup rewrite boundary;
  • future, aborted, partially retained, and fully filtered row sets;
  • malformed/missing/short/null commitTS returns a bounded error;
  • persisted and producer-side N-row constant commitTS broadcast coverage, including canonicalize -> WriteBatch -> Sync -> ReadDeletes;
  • merge-stats initial reader-error propagation;
  • actual 4.2 checkpoint rewrite followed by metadata inspection and IsRowDeletedByLocation verification;
  • full tests for pkg/objectio/ioutil, pkg/vm/engine/tae/logtail, pkg/vm/engine/tae/tables, pkg/vm/engine/disttae, and pkg/vm/engine/disttae/logtailreplay;
  • affected-package go list, build, vet, and scoped golangci-lint (0 issues).

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Close the reader-side compatibility boundary for Backup artifacts already emitted by affected 4.2 builds

The new producer path is correct: newly rewritten tombstones get the canonical [0, 1, SEQNUM_COMMITTS] layout. However, this backport intentionally leaves existing affected Backup artifacts unchanged, so the concrete #26991 failure remains reachable after upgrading/restoring.

For an affected non-CN tombstone with meta_columns=3, max_seq=2, and a trailing physical TS column, objectio.ReadOneBlock still decides that no hidden commitTS exists and synthesizes a const-null TS vector. ReadDeletes returns that as success without validating availability or physical/logical row counts. IsRowDeletedByLocation then indexes tss by the non-empty rowid length, and FillBlockDeleteMask reaches the same failure through EvalDeleteMaskFromDNCreatedTombstones.

I reproduced both panics deterministically on this exact head using the old Backup generic writer and the exact physical [rowid, timestamp-valued PK, commitTS] / dense [0,1,2] metadata shape. The timestamp-PK control confirms that compatibility must be narrow and metadata-aware rather than a global “last TS column” fallback. The PR tests only read newly canonicalized output, so they cannot detect this remaining path.

This is a merge blocker because an affected Backup can be the only recovery copy; requiring it to be recreated is impossible precisely when restore is needed, and #26991 explicitly requires malformed/legacy metadata to produce bounded behavior instead of a recovered runtime panic.

Please add one shared reader boundary before either consumer indexes commitTS:

  • recover the physical trailing TS for the narrowly identifiable malformed Backup signature when unambiguous;
  • otherwise return an explicit bounded compatibility/corruption error;
  • cover both IsRowDeletedByLocation and EvalDeleteMaskFromDNCreatedTombstones/FillBlockDeleteMask, including the timestamp-valued PK control.

Validation performed on this head:

  • new focused Backup tests: pass;
  • full pkg/vm/engine/tae/logtail: pass;
  • pkg/objectio/ioutil: pass;
  • logtail build and vet: pass;
  • reviewer-only affected-artifact counterexample: both reader paths still panic (temporary test removed).

Q1-Q3 audit: the new producer cleanup/ownership paths are sound; no new wait or unbounded-growth edge found. The blocker is the still-open persisted-format read/restore terminal path.

@LeftHandCold

Copy link
Copy Markdown
Collaborator Author

Thanks. I reproduced the affected-artifact path and agree that the reader-side compatibility boundary is required. This PR is updated in commit e0367403e7.

The v4.1.4 same-version result is expected: the v4.1 reader still infers the trailing physical TS column by position. The durable artifact nevertheless has the generic-writer metadata ([0,1,2], meta_columns=3, max_seq=2), and the strict 4.2 reader reproduced both point-lookup and block-mask failures before this update.

The 4.2-specific implementation now:

  • validates commitTS at the shared ReadDeletes boundary;
  • compatibility-reloads physical column 2 only for the exact non-CN, non-appendable three-column Backup signature;
  • keeps a timestamp-valued user PK at physical column 1 distinct from trailing commitTS;
  • returns bounded errors for ambiguous/missing, null, wrong-type, length-mismatched, and short-backing vectors;
  • migrates all non-CN ReadDeletes consumers to constant-safe logical-row access;
  • releases the first lease before compatibility reload and closes reload/error ownership paths.

The backport intentionally preserves 4.2's reader protocol: without PK it reads [rowid, commitTS]; with PK it reads [rowid, pk, commitTS]. It does not pull the later main-branch abort reader format into 4.2.

The review also exposed two adjacent closure issues that are fixed here:

  1. Backup producer filtering iterated the physical backing of a valid N-row constant commitTS vector and could retain only row 0. It now iterates logical rows and has N=3 coverage.
  2. The merge-stats path could swallow an initial iterator reader error and return an undercount. It now returns the error immediately and releases both the failing iterator and previously admitted iterators.

Validation on the final frozen diff:

  • full pkg/objectio/ioutil: pass
  • full pkg/vm/engine/tae/logtail: pass
  • full pkg/vm/engine/disttae/...: pass
  • focused compatibility/constant/checkpoint/merge-error regressions with -count=10: pass
  • affected-package build/vet and git diff --check: pass

The PR description has also been updated with the same-version explanation, exact compatibility signature, and 4.2-specific layout boundary.

@gouhongshen gouhongshen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex automated review

The prior reviewer’s ReadDeletes point-lookup/block-mask panic is addressed, but legacy compatibility is incomplete in other readers. Focused tests pass; the findings below are distinct from the existing review finding.

P1 - Legacy generic-writer tombstones now fail through the snapshot datasource (pkg/vm/engine/tae/logtail/backup.go:409)

GetTombstones bypasses the new ReadDeletes compatibility reload and calls visibleAppendableRows directly. For an affected legacy object [rowid, pk, commitTS] with meta_columns=3 and max_seq=2, resolveBackupSpecialColumnLayout starts at position 3 and reports no commitTS, so validation returns appendable tombstone has no commit timestamp and the snapshot/PITR read fails. The base code read the trailing physical TS vector and succeeded. The compatibility mapping must also cover this path (and have a regression test).

P2 - Varlen-PK conflict checks still treat legacy tombstones as changed (pkg/vm/engine/disttae/txn_table.go:2988)

The cached-search branch for varchar/varlen PKs calls LoadColumnDataBySearchAndCheckTS, which reads SEQNUM_COMMITTS directly and never uses the legacy reload in ReadDeletes. On the same legacy layout, ObjectIO supplies a const-null commit vector; AnyCachedTSInRange returns usable=false, and lines 3005-3009 conservatively report the tombstone as changed. Thus a matching tombstone whose physical trailing commitTS is outside (from,to] causes a false transaction-conflict result. This is safe against missed conflicts but violates the PR’s stated PK-change compatibility and can cause avoidable aborts.

@gouhongshen gouhongshen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex automated review

The c96 snapshot/PITR and varlen-PK blockers are fixed; 51620 fixes the prior TAE persisted Scan/range under-delete blocker. A distinct normal table-scan blocker remains in FillBlockTombstones. The added tests do not cover this path; focused runtime tests were unavailable because native CGo dependencies are missing.

P1 - Apply per-row commitTS in FillBlockTombstones (pkg/vm/engine/tae/tables/pnode.go:390)

The normal table-read path calls FillBlockTombstones, but it requests only colIdxs := []int{0}. Therefore LoadPersistedColumnData receives isTombstone=true with committsIdx == -1, so the new validation and legacy-column reload never run. For non-appendable tombstones, this function only checks object CreatedAt and applies commitTS filtering only when IsAppendable(). Rewritten backup tombstones are explicitly non-appendable, while the rewrite preserves the source CreateTS; the test data creates the object at TS 5 and retains a row with commitTS 10 at backup TS 15. A snapshot at TS 7 can consequently see the tombstone object while the row-level delete is not yet committed, but this path adds its rowid to the delete mask and over-deletes the data row. This is distinct from the fixed Scan/range issue: those paths omitted or misread tombstones, whereas this path applies them too early. Load and validate the hidden commitTS here, preserve the two-column CN-created CreatedAt behavior, filter commitTS <= txn start, and add a HybridScan regression.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Preserve row-level commit visibility in normal TAE scans

The latest patch fixes the explicit Scan/range readers, but FillBlockTombstones in pkg/vm/engine/tae/tables/pnode.go still requests only column 0. LoadPersistedColumnData therefore never sees SEQNUM_COMMITTS, so neither the canonical nor legacy commitTS mapping participates in visibility. A backup-rewritten tombstone is nonappendable while retaining the original appendable object CreatedAt; checking only that object timestamp cannot prove every row delete is visible.

I reproduced this on exact head 51620de: using the existing TestPersistedNodeReadsLegacyBackupTombstone fixture with object CreatedAt=10, row commitTS values 10 and 20, and transaction start=15, FillBlockTombstones inserted both row offsets into the delete mask. The commitTS=20 row must remain visible. This is the path used by normal HybridScanByBlock, so snapshot reads can return a false deletion.

Please make this path load and validate per-row commitTS for rewritten/legacy TN tombstones that carry it, filter rows by commitTS <= transaction start, preserve the established CN-created two-column tombstone behavior, and add a FillBlockTombstones or HybridScan regression for the mixed-commitTS snapshot.

@LeftHandCold

Copy link
Copy Markdown
Collaborator Author

已处理 reviews 4918324241 / 4918483169,确认这是有效的正常 TAE scan 可见性缺口,修复提交为 29eff4237c。

本轮修复:

  • FillBlockTombstones 对 non-appendable TN tombstone 同时加载隐藏 commitTS,并按 commitTS <= txn.StartTS 逐行构造 delete mask;对象 CreatedAt 只保留为粗粒度 gate。
  • 继续支持受影响 Backup 的 dense [rowid, pk, commitTS] 兼容映射。
  • 精确的 CN-created 两列 [rowid, pk] 仍使用对象 CreatedAt;其它缺失或损坏的 commitTS 会返回错误。
  • appendable 路径保持原读取方式,并复用 commitTS 列校验,避免异常长度导致越界。

新增 FillBlockTombstones 回归矩阵覆盖:

  • canonical 三列 TN tombstone:row commitTS 10/20,snapshot 5/15/25;
  • legacy Backup dense 三列:同一组 snapshot 边界;
  • CN-created 两列控制组:snapshot 在 CreatedAt 前后。

本地验证通过:

  • mo-cgo-test -count=1 ./pkg/objectio/ioutil ./pkg/vm/engine/tae/tables
  • 目标三组测试 -race
  • golangci-lint 针对 pkg/vm/engine/tae/tables:0 issues
  • git diff --check

@XuPeng-SH @gouhongshen 已重新 request review,麻烦基于新 head 29eff4237c 继续 review。

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed exact head 29eff4237c6d042095522a798c04a262a326646a after the latest normal-scan visibility fix. No merge blocker found.

The previously open closure edges are now covered: canonical Backup production, the exact legacy dense [rowid, pk, commitTS] artifact, point lookup/block masks, Backup datasource, varlen-PK conflict checks, TAE copy/zero-copy/range readers, and normal FillBlockTombstones visibility. Non-appendable TN tombstones now apply row deletes only when commitTS <= txn.StartTS; the established two-column CN/legacy CreatedAt semantics remain intact. Constant vectors use logical broadcast access, malformed commit columns fail explicitly, and the compatibility reload/cache-lease and batch/vector ownership paths terminate exactly once.

Validation on this head:

  • full tests passed for pkg/objectio/ioutil, pkg/vm/engine/tae/logtail, pkg/vm/engine/tae/tables, pkg/vm/engine/disttae, and pkg/vm/engine/disttae/logtailreplay;
  • focused compatibility/visibility/resource regressions passed under -race;
  • affected-package go list, build, vet, and git diff --check passed;
  • Q1-Q3 unhappy-path audit found no new leak, double-cleanup, wait-for, or unbounded-growth edge.

Per reviewer direction, I did not wait for the four still-running remote CI jobs. At submission time they had no failures, and the PR head was unchanged.

@gouhongshen gouhongshen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex automated review

All prior blockers are resolved: legacy reader compatibility, snapshot/PITR and varlen-PK paths, persisted TAE scans/ranges, and per-row tombstone commitTS filtering. The latest change correctly covers canonical, legacy dense, and CN tombstone layouts. No remaining correctness, resource, concurrency, performance, or unhappy-path findings. Focused tests were blocked by missing native CGo headers.

This branch had an error being deployed

1 failed deployment
ci — 17e54642 Deployed Aug 13, 2026 by XuPeng-SH via Matrixone Utils CI / Coverage #46102
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants