Skip to content

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

Merged
mergify[bot] merged 7 commits into
matrixorigin:mainfrom
LeftHandCold:fix/26991-backup-tombstone-committs
Aug 13, 2026
Merged

mergify[bot] merged 7 commits into
matrixorigin:mainfrom
LeftHandCold:fix/26991-backup-tombstone-committs

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:

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. A current strict special-column reader, however, treats commitTS as absent, synthesizes a const-null vector with no fixed backing values, and could panic while evaluating a v4.1-generated recovery artifact.

This PR closes both sides of that 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 metadata, supporting both historical special-column orders;
  • filters aborted rows and rows newer than the backup timestamp before rewriting;
  • drops the now-stale physical row address and the already-consumed abort column;
  • writes rewritten tombstones with explicit hidden-column seqnums;
  • preserves constant-vector broadcast semantics so an N-row constant commitTS does not silently retain only row 0;
  • validates malformed source columns and releases rewritten batches on success and error paths without double-freeing shared objData references.

For existing v4.1-style artifacts, the reader implementation:

  • recognizes only the exact non-CN, non-appendable three-column Backup signature (meta_columns=3, max_seq=2, [Rowid, PK, TS], and no resolved hidden commitTS);
  • reloads physical column 2 as commitTS while keeping a timestamp-valued user PK distinct;
  • validates commitTS once at the shared ReadDeletes boundary 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, and PK-change checks;
  • releases the first cache lease before compatibility reload and closes all reload/error ownership paths.

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

Validation:

  • deterministic v4.1 generic-writer artifact consumed by the current reader through both point lookup and block-mask paths;
  • timestamp-valued user-PK counterexample proving PK and trailing commitTS remain distinct;
  • exact compatibility-reload failure injection proving the first cache lease is released;
  • source layouts with commitTS only, commitTS plus abort, and physical rowid before/after commitTS;
  • future, aborted, fully retained, partially retained, and fully filtered row sets;
  • malformed/missing/short/null commitTS and abort columns return bounded errors;
  • persisted and producer-side N-row constant commitTS broadcast coverage;
  • actual checkpoint rewrite followed by metadata inspection and IsRowDeletedByLocation verification;
  • focused regressions repeated 10 times;
  • full pkg/objectio/ioutil, pkg/vm/engine/tae/logtail, and pkg/vm/engine/disttae/... tests, plus build/vet for affected packages.

@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 already-generated malformed Backup tombstones

The producer rewrite in this PR is sound for newly generated backups, but the exact artifacts created by affected releases remain on the original crash path. For a non-CN tombstone with meta_columns=3, max_seq=2, and a trailing physical TS column, ResolveSpecialColumnLayout reports no hidden commitTS. The column reader then synthesizes a const-null TS vector with logical row count N but zero fixed backing elements. ReadDeletes validates only the abort vector, so both IsRowDeletedByLocation and EvalDeleteMaskFromDNCreatedTombstones still index tss[i] using the non-empty rowid length and panic.

That is not only a migration limitation: a backup may be the sole recovery copy, and it also leaves the explicit #26991 contract (malformed metadata returns a bounded error, never an index panic) unmet. Please add one shared commitTS validation/compatibility boundary before either consumer indexes it. For the narrowly identifiable malformed Backup signature, recover the physical trailing TS column when it is unambiguous; for ambiguous/corrupt layouts, return an explicit bounded error rather than weakening special-column detection globally. Add deterministic coverage through both consumer paths, including the timestamp-valued user-PK control. The producer-side canonical writer change should stay as-is.

@LeftHandCold

Copy link
Copy Markdown
Collaborator Author

Thanks. I rechecked the release boundary and history before deciding the scope here:

  • Neither the affected 4.2-dev commit (b83878b8e9f3) nor the stricter reader commit from fix(tae): filter TN rewrites by row commit time #26163 (3128259d4b) is contained in a release tag. The strict reader currently exists only on 4.2-dev/main.
  • Released v4.1.x does contain the long-lived generic Backup writer, but its released reader still accepts the trailing physical TS column. Therefore there is no released reader that currently rejects artifacts produced by a released writer; the confirmed crashing artifacts came from internal regression runs and can be regenerated.

Given that 4.2 has not shipped, I do not think compatibility recovery for artifacts generated by affected 4.2 development builds should block this producer fix. This PR closes the format invariant before the first 4.2 release and prevents all newly generated filesystem/S3 backups from creating the malformed layout.

I agree that two reader-side questions remain useful, but they are a separate compatibility/hardening boundary:

  1. whether restoring a v4.1-era Backup directly with a future 4.2 binary is a supported cross-version contract;
  2. returning a bounded corruption error instead of panicking on malformed metadata.

Those should be handled in a focused follow-up once the cross-version recovery policy is confirmed, rather than coupling reader reinterpretation of malformed on-disk metadata into this producer correction. Accordingly, I propose keeping the producer writer change in this PR as-is and treating the reader-side compatibility/error-hardening portion of #26991 as follow-up scope.

@LeftHandCold
LeftHandCold requested a review from XuPeng-SH August 12, 2026 06:30

@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] Reader compatibility/safety remains a blocking part of #26991

I re-reviewed the producer fix and the release-history argument. The canonical rewrite in this PR is correct for newly generated backups, and its focused tests pass. However, the release boundary does not make the remaining reader failure safe:

  • v4.1.4 already ships the same generic Backup writer at this path. It can persist the exact [0,1,2], meta_columns=3, max_seq=2, trailing-TS artifact. The v4.1 reader accepting that trailing TS only masks the malformed metadata; the durable backup artifact remains malformed.
  • On this PR head, ResolveSpecialColumnLayout rejects that layout, ReadOneBlock synthesizes a const-null commitTS vector with logical length N but no fixed backing values, and ReadDeletes validates only abort. Both IsRowDeletedByLocation and EvalDeleteMaskFromDNCreatedTombstones still index tss[i] using the non-empty rowid length and panic.
  • Therefore a v4.1-generated recovery copy can enter this failure after restoration with the 4.2 reader. Even if direct cross-version restore is ultimately declared unsupported, malformed metadata still violates #26991 explicit safety contract: return a bounded corruption/compatibility error rather than an index panic.

Please add one shared commitTS validation boundary before both consumers index it. Recover the narrow non-CN Backup signature only when the trailing TS is unambiguous; otherwise return a bounded explicit error. Add deterministic tests through both reader paths, including the timestamp-valued PK counterexample. The producer/canonical-writer changes in this PR should remain as they are.

@LeftHandCold

Copy link
Copy Markdown
Collaborator Author

Thanks for the second review. I reproduced the boundary directly and agree that the reader-side part is a P1 blocker, so I updated this PR in commit 873c009a74.

The apparent v4.1.4 counterexample is now explained: v4.1.4 -> v4.1.4 Backup/restore succeeds because that 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). Feeding that exact artifact to the current strict reader reproduced the reported IsRowDeletedByLocation index panic before this fix.

The update adds:

  • one shared commitTS validation boundary used before tombstone consumers index by rowid count;
  • a compatibility reload only for the exact non-CN, non-appendable v4.1 Backup signature;
  • a timestamp-valued user-PK control proving physical PK column 1 is not confused with trailing commitTS column 2;
  • bounded errors for ambiguous/missing, null, wrong-type, length-mismatched, and short-backing commitTS vectors;
  • coverage through point lookup and block-mask evaluation, including injected compatibility-reload failure and cache-lease accounting;
  • constant commitTS broadcast handling in every migrated consumer.

The review also exposed a related producer issue: visibleAppendableRows iterated the physical slice of a valid N-row constant commitTS vector, so it could retain only row 0. It now iterates the logical row count and broadcasts via vector access; the regression asserts all three rows survive canonicalization.

Validation completed on the updated diff:

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

The producer canonical-writer fix remains intact, and the PR description has been updated to document both the same-version behavior and the cross-version compatibility 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 current head canonicalizes rewritten tombstones with hidden commitTS and safely reloads the exact legacy layout. No independent blocking or non-blocking findings remain.

XuPeng-SH added a commit that referenced this pull request Aug 13, 2026
## What type of PR is this?

- [ ] API-change
- [x] 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:

```text
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).

---------

Co-authored-by: XuPeng-SH <[email protected]>

@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.

Deep-reviewed exact head 35f62d0. The prior reader-side blocker is closed: the compatibility path is restricted to the exact legacy Backup signature, reload ownership releases the first cache lease before retry and all error paths are bounded, timestamp-valued PK remains distinct, and every commitTS consumer now preserves constant-vector broadcast semantics. The producer writes the canonical [rowid, pk, hidden commitTS] layout and the checkpoint rewrite regression verifies the persisted metadata plus real delete lookup. Focused regressions passed 10x; full objectio/ioutil, tae/logtail, disttae, and logtailreplay tests, plus affected-package build/vet, all passed. No blocking findings.

@mergify mergify Bot added the queued label Aug 13, 2026
@mergify

mergify Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-13 19:36 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-08-13 21:04 UTC · at 74a02c5fceca0b559b18a518ac1b5d606e3672f0 · squash

This pull request spent 1 hour 27 minutes 48 seconds in the queue, including 48 minutes 13 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)

This branch was previously deployed

1 inactive deployment
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/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants