Skip to content

fix(tae): align late aobject visibility with parent txn - #26180

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:agent/revert-25534
Jul 26, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:agent/revert-25534

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

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

Which issue(s) this PR fixes:

N/A. This regression was isolated from the TestDelete3 failure after #25534. It is unrelated to #26175.

What this PR does / why we need it

Root cause

A flush/merge transaction can collect deletes again from flushTableTailEntry.PrepareCommit, after its prepare/commit timestamp has already been assigned. If that late transfer rolls over the current tombstone appender, prepareApplyANode creates one or more appendable tombstone objects.

Since #25534, appendable objects are committed catalog entries outside the transaction. The active append path is correct because the object create timestamp precedes the append transaction commit. In the late-transfer path, however, each object received a fresh timestamp later than the parent flush timestamp. A snapshot could therefore see the rewritten data while seeing none or only a prefix of its transferred tombstones.

The deterministic reproducer on unmodified main returned visible rows after the delete. The strengthened concurrent-snapshot mutation test returns 22 rows without this fix and 0 with it.

Fix

This PR keeps appendable objects outside transactions. It does not add object-create transaction entries or object-create WAL records.

When an appendable object is created while its append transaction is already Preparing, its committed catalog entry uses the parent prepare timestamp. The object remains only a carrier: its appended rows are still owned by the parent append MVCC node. Correctness scan paths that cross that timestamp wait on the parent's rewritten data/append MVCC before snapshotting transfer tombstones. WAL replay reconstructs a missing appendable object from the append command at the same timestamp.

The normal Active path remains on AllocateAndPublishCommitTS, preserving #25534's atomic timestamp allocation/catalog publication contract. The Preparing branch is a deliberate, narrow exception for parent-owned late-transfer rows; independently committed object state must continue to use the normal publication path.

Design and performance

  • aobjects remain outside transactions and may survive creator rollback as empty catalog shells;
  • an empty shell without append/delete state remains intentionally non-durable, as in Move appendable object creation outside transactions #25534;
  • rollback removes the parent-owned append MVCC rows, so transferred deletes cannot become visible after parent abort;
  • replay reconstructs committed carriers from append WAL without a format or upgrade change;
  • multiple carriers may share the parent timestamp; object name remains the catalog ordering tie-breaker;
  • the active path adds one transaction-state read per aobject creation, not per row or per commit;
  • the rare preparing path avoids the per-object global timestamp allocation;
  • no new I/O, WAL record, storage scan, allocation, or global publication fence is introduced;
  • tombstone-only incremental dedup remains a best-effort fallback rather than gaining a strict global catalog fence.

Coverage

The tests force multiple tombstone-object rollovers and cover:

  • snapshots immediately before, at, and after every relevant visibility boundary;
  • a reader snapshot explicitly greater than the parent prepare timestamp, fixed while the parent is Preparing and before any late transfer object exists;
  • cleanup that always releases the deterministic prepare barrier and waits for the commit goroutine, including assertion failures;
  • rollback after late transfer object creation;
  • restart/replay after both commit and rollback;
  • the existing outside-transaction aobject lifecycle through the full txnimpl suite.

Validation on the final diff:

  • enhanced concurrent-snapshot test: fails on unmodified main with 22 visible rows, passes with this fix;
  • focused regression set: -count=10;
  • TestDelete3 plus the new tests: -race -count=20;
  • full pkg/vm/engine/tae/db/test suite;
  • full pkg/vm/engine/tae/... suite with -p=1;
  • go vet for both modified packages;
  • go build for pkg/vm/engine/tae/txn/txnimpl;
  • git diff --check.

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

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

LGTM. The fix correctly aligns late-created appendable tombstone objects with the parent transaction’s prepare timestamp while
preserving the normal timestamp publication path for active transactions. The commit, rollback, snapshot visibility, and WAL replay
paths are well covered.

I also ran the three new regression tests five times; all passed. Ubuntu UT and BVT checks are green. Coverage and ARM SCA are
still pending.

@mergify

mergify Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@XuPeng-SH
XuPeng-SH merged commit d372ca2 into matrixorigin:main Jul 26, 2026
23 checks passed
@XuPeng-SH
XuPeng-SH deleted the agent/revert-25534 branch July 26, 2026 04:28
XuPeng-SH added a commit to XuPeng-SH/matrixone that referenced this pull request Jul 26, 2026
Resolve the db_test overlap with matrixorigin#26180 and harden incremental dedup to filter TN rewrites lazily by row commit timestamp, preserve the best-effort legacy fallback, and release result vectors on error.
XuPeng-SH added a commit that referenced this pull request Jul 26, 2026
## What this fixes

`CheckIncremental` selects committed objects in a timestamp window. For
a TN flush or merge output, however, `ObjectEntry.CreatedAt` is the
physical rewrite time, not the logical commit time of every row inside
it. Old rows rewritten after a transaction snapshot could therefore be
treated as new candidates and produce a false duplicate.

Fixes #26162.

The original flaky symptom was exposed by `TestDelete3`. Dedicated
deterministic tests now cover both sides of the rewrite window: old rows
must be ignored, while a row committed after the transaction snapshot
must still cause a WW conflict even if TN flushes it before pre-prepare.

## Design

For a TN-created nonappendable candidate:

1. Keep the existing object/zonemap/BF pruning.
2. Compare the primary key exactly.
3. Only after an exact match, lazily load the existing hidden row
commit-TS column.
4. Ignore rows before the inclusive dedup interval and retain rows
inside it.

The commit-TS vector is block-scoped, loaded at most once, and released
on success and error. `incrementalGetRowsByPK` now also closes and nils
its result vector when an error occurs, so ownership transfers to the
caller only on success.

Direct CN-created objects retain the existing object-level conservative
check because they do not carry TN row commit timestamps.

## Explicit fallback boundary

Incremental dedup on TN is a best-effort fallback, not the primary
correctness boundary for normal production DML. Pessimistic-RC
primary/unique-key locks serialize same-key writers, and `LockOp` calls
`PrimaryKeysMayBeModified` when the lock timestamp advances; `LOAD DATA`
uses a table lock.

Some legacy objects, and TN rewrites containing CN-created rows, have
missing/null row commit timestamps:

- `CheckIncremental` skips an unverifiable row to avoid upgrade/rewrite
false positives.
- Strict policies (`CheckAll` and `FullSkipWorkspaceDedup`) remain
conservative and report it as a duplicate.

This is deliberate. Making that rare incremental fallback independently
exact would require CN-origin lineage, merge propagation,
protobuf/opcode changes, and a rolling-upgrade protocol. This PR adds
none of those steady-state costs or format changes.

## Performance

- No commit-TS storage read occurs without an exact primary-key match;
this is covered by a regression test for fixed and varlen keys.
- A candidate block performs at most one commit-TS read.
- No extra column is written or propagated by flush/merge, and no
on-disk or wire format changes.
- Compared with current main, ordinary nonmatching scans keep the same
zonemap/BF/PK path. The extra read is limited to an exact matching
candidate where logical-time disambiguation is required.

## Validation

- `TestDelete3` plus all #26180 appendable-object visibility/rollback
tests.
- Incremental old-row rewrite, incremental concurrent-row rewrite,
direct CN-created object, and strict old/concurrent rewrite tests.
- Fixed and varlen PK tests for missing, short, null, lower-bound,
lazy-load, cached-error, and ownership behavior.
- Full tests for `pkg/objectio`, `pkg/vm/engine/tae/tables`,
`pkg/vm/engine/tae/txn/txnimpl`, and `pkg/vm/engine/tae/db/test`.
- Focused policy matrix passes `-race -count=10`; all four packages pass
full `-race`.
- CI-equivalent `go vet -mod=readonly -tags matrixone_test
-unsafeptr=false ./pkg/...` passes.
- `git diff --check` passes.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#26180)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

N/A. This regression was isolated from the `TestDelete3` failure after
matrixorigin#25534. It is unrelated to matrixorigin#26175.

## What this PR does / why we need it

### Root cause

A flush/merge transaction can collect deletes again from
`flushTableTailEntry.PrepareCommit`, after its prepare/commit timestamp
has already been assigned. If that late transfer rolls over the current
tombstone appender, `prepareApplyANode` creates one or more appendable
tombstone objects.

Since matrixorigin#25534, appendable objects are committed catalog entries outside
the transaction. The active append path is correct because the object
create timestamp precedes the append transaction commit. In the
late-transfer path, however, each object received a fresh timestamp
later than the parent flush timestamp. A snapshot could therefore see
the rewritten data while seeing none or only a prefix of its transferred
tombstones.

The deterministic reproducer on unmodified main returned visible rows
after the delete. The strengthened concurrent-snapshot mutation test
returns 22 rows without this fix and 0 with it.

### Fix

This PR keeps appendable objects outside transactions. It does not add
object-create transaction entries or object-create WAL records.

When an appendable object is created while its append transaction is
already `Preparing`, its committed catalog entry uses the parent prepare
timestamp. The object remains only a carrier: its appended rows are
still owned by the parent append MVCC node. Correctness scan paths that
cross that timestamp wait on the parent's rewritten data/append MVCC
before snapshotting transfer tombstones. WAL replay reconstructs a
missing appendable object from the append command at the same timestamp.

The normal `Active` path remains on `AllocateAndPublishCommitTS`,
preserving matrixorigin#25534's atomic timestamp allocation/catalog publication
contract. The `Preparing` branch is a deliberate, narrow exception for
parent-owned late-transfer rows; independently committed object state
must continue to use the normal publication path.

### Design and performance

- aobjects remain outside transactions and may survive creator rollback
as empty catalog shells;
- an empty shell without append/delete state remains intentionally
non-durable, as in matrixorigin#25534;
- rollback removes the parent-owned append MVCC rows, so transferred
deletes cannot become visible after parent abort;
- replay reconstructs committed carriers from append WAL without a
format or upgrade change;
- multiple carriers may share the parent timestamp; object name remains
the catalog ordering tie-breaker;
- the active path adds one transaction-state read per aobject creation,
not per row or per commit;
- the rare preparing path avoids the per-object global timestamp
allocation;
- no new I/O, WAL record, storage scan, allocation, or global
publication fence is introduced;
- tombstone-only incremental dedup remains a best-effort fallback rather
than gaining a strict global catalog fence.

## Coverage

The tests force multiple tombstone-object rollovers and cover:

- snapshots immediately before, at, and after every relevant visibility
boundary;
- a reader snapshot explicitly greater than the parent prepare
timestamp, fixed while the parent is `Preparing` and before any late
transfer object exists;
- cleanup that always releases the deterministic prepare barrier and
waits for the commit goroutine, including assertion failures;
- rollback after late transfer object creation;
- restart/replay after both commit and rollback;
- the existing outside-transaction aobject lifecycle through the full
txnimpl suite.

Validation on the final diff:

- enhanced concurrent-snapshot test: fails on unmodified main with 22
visible rows, passes with this fix;
- focused regression set: `-count=10`;
- `TestDelete3` plus the new tests: `-race -count=20`;
- full `pkg/vm/engine/tae/db/test` suite;
- full `pkg/vm/engine/tae/...` suite with `-p=1`;
- `go vet` for both modified packages;
- `go build` for `pkg/vm/engine/tae/txn/txnimpl`;
- `git diff --check`.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What this fixes

`CheckIncremental` selects committed objects in a timestamp window. For
a TN flush or merge output, however, `ObjectEntry.CreatedAt` is the
physical rewrite time, not the logical commit time of every row inside
it. Old rows rewritten after a transaction snapshot could therefore be
treated as new candidates and produce a false duplicate.

Fixes matrixorigin#26162.

The original flaky symptom was exposed by `TestDelete3`. Dedicated
deterministic tests now cover both sides of the rewrite window: old rows
must be ignored, while a row committed after the transaction snapshot
must still cause a WW conflict even if TN flushes it before pre-prepare.

## Design

For a TN-created nonappendable candidate:

1. Keep the existing object/zonemap/BF pruning.
2. Compare the primary key exactly.
3. Only after an exact match, lazily load the existing hidden row
commit-TS column.
4. Ignore rows before the inclusive dedup interval and retain rows
inside it.

The commit-TS vector is block-scoped, loaded at most once, and released
on success and error. `incrementalGetRowsByPK` now also closes and nils
its result vector when an error occurs, so ownership transfers to the
caller only on success.

Direct CN-created objects retain the existing object-level conservative
check because they do not carry TN row commit timestamps.

## Explicit fallback boundary

Incremental dedup on TN is a best-effort fallback, not the primary
correctness boundary for normal production DML. Pessimistic-RC
primary/unique-key locks serialize same-key writers, and `LockOp` calls
`PrimaryKeysMayBeModified` when the lock timestamp advances; `LOAD DATA`
uses a table lock.

Some legacy objects, and TN rewrites containing CN-created rows, have
missing/null row commit timestamps:

- `CheckIncremental` skips an unverifiable row to avoid upgrade/rewrite
false positives.
- Strict policies (`CheckAll` and `FullSkipWorkspaceDedup`) remain
conservative and report it as a duplicate.

This is deliberate. Making that rare incremental fallback independently
exact would require CN-origin lineage, merge propagation,
protobuf/opcode changes, and a rolling-upgrade protocol. This PR adds
none of those steady-state costs or format changes.

## Performance

- No commit-TS storage read occurs without an exact primary-key match;
this is covered by a regression test for fixed and varlen keys.
- A candidate block performs at most one commit-TS read.
- No extra column is written or propagated by flush/merge, and no
on-disk or wire format changes.
- Compared with current main, ordinary nonmatching scans keep the same
zonemap/BF/PK path. The extra read is limited to an exact matching
candidate where logical-time disambiguation is required.

## Validation

- `TestDelete3` plus all matrixorigin#26180 appendable-object visibility/rollback
tests.
- Incremental old-row rewrite, incremental concurrent-row rewrite,
direct CN-created object, and strict old/concurrent rewrite tests.
- Fixed and varlen PK tests for missing, short, null, lower-bound,
lazy-load, cached-error, and ownership behavior.
- Full tests for `pkg/objectio`, `pkg/vm/engine/tae/tables`,
`pkg/vm/engine/tae/txn/txnimpl`, and `pkg/vm/engine/tae/db/test`.
- Focused policy matrix passes `-race -count=10`; all four packages pass
full `-race`.
- CI-equivalent `go vet -mod=readonly -tags matrixone_test
-unsafeptr=false ./pkg/...` passes.
- `git diff --check` passes.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#26180)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

N/A. This regression was isolated from the `TestDelete3` failure after
matrixorigin#25534. It is unrelated to matrixorigin#26175.

## What this PR does / why we need it

### Root cause

A flush/merge transaction can collect deletes again from
`flushTableTailEntry.PrepareCommit`, after its prepare/commit timestamp
has already been assigned. If that late transfer rolls over the current
tombstone appender, `prepareApplyANode` creates one or more appendable
tombstone objects.

Since matrixorigin#25534, appendable objects are committed catalog entries outside
the transaction. The active append path is correct because the object
create timestamp precedes the append transaction commit. In the
late-transfer path, however, each object received a fresh timestamp
later than the parent flush timestamp. A snapshot could therefore see
the rewritten data while seeing none or only a prefix of its transferred
tombstones.

The deterministic reproducer on unmodified main returned visible rows
after the delete. The strengthened concurrent-snapshot mutation test
returns 22 rows without this fix and 0 with it.

### Fix

This PR keeps appendable objects outside transactions. It does not add
object-create transaction entries or object-create WAL records.

When an appendable object is created while its append transaction is
already `Preparing`, its committed catalog entry uses the parent prepare
timestamp. The object remains only a carrier: its appended rows are
still owned by the parent append MVCC node. Correctness scan paths that
cross that timestamp wait on the parent's rewritten data/append MVCC
before snapshotting transfer tombstones. WAL replay reconstructs a
missing appendable object from the append command at the same timestamp.

The normal `Active` path remains on `AllocateAndPublishCommitTS`,
preserving matrixorigin#25534's atomic timestamp allocation/catalog publication
contract. The `Preparing` branch is a deliberate, narrow exception for
parent-owned late-transfer rows; independently committed object state
must continue to use the normal publication path.

### Design and performance

- aobjects remain outside transactions and may survive creator rollback
as empty catalog shells;
- an empty shell without append/delete state remains intentionally
non-durable, as in matrixorigin#25534;
- rollback removes the parent-owned append MVCC rows, so transferred
deletes cannot become visible after parent abort;
- replay reconstructs committed carriers from append WAL without a
format or upgrade change;
- multiple carriers may share the parent timestamp; object name remains
the catalog ordering tie-breaker;
- the active path adds one transaction-state read per aobject creation,
not per row or per commit;
- the rare preparing path avoids the per-object global timestamp
allocation;
- no new I/O, WAL record, storage scan, allocation, or global
publication fence is introduced;
- tombstone-only incremental dedup remains a best-effort fallback rather
than gaining a strict global catalog fence.

## Coverage

The tests force multiple tombstone-object rollovers and cover:

- snapshots immediately before, at, and after every relevant visibility
boundary;
- a reader snapshot explicitly greater than the parent prepare
timestamp, fixed while the parent is `Preparing` and before any late
transfer object exists;
- cleanup that always releases the deterministic prepare barrier and
waits for the commit goroutine, including assertion failures;
- rollback after late transfer object creation;
- restart/replay after both commit and rollback;
- the existing outside-transaction aobject lifecycle through the full
txnimpl suite.

Validation on the final diff:

- enhanced concurrent-snapshot test: fails on unmodified main with 22
visible rows, passes with this fix;
- focused regression set: `-count=10`;
- `TestDelete3` plus the new tests: `-race -count=20`;
- full `pkg/vm/engine/tae/db/test` suite;
- full `pkg/vm/engine/tae/...` suite with `-p=1`;
- `go vet` for both modified packages;
- `go build` for `pkg/vm/engine/tae/txn/txnimpl`;
- `git diff --check`.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What this fixes

`CheckIncremental` selects committed objects in a timestamp window. For
a TN flush or merge output, however, `ObjectEntry.CreatedAt` is the
physical rewrite time, not the logical commit time of every row inside
it. Old rows rewritten after a transaction snapshot could therefore be
treated as new candidates and produce a false duplicate.

Fixes matrixorigin#26162.

The original flaky symptom was exposed by `TestDelete3`. Dedicated
deterministic tests now cover both sides of the rewrite window: old rows
must be ignored, while a row committed after the transaction snapshot
must still cause a WW conflict even if TN flushes it before pre-prepare.

## Design

For a TN-created nonappendable candidate:

1. Keep the existing object/zonemap/BF pruning.
2. Compare the primary key exactly.
3. Only after an exact match, lazily load the existing hidden row
commit-TS column.
4. Ignore rows before the inclusive dedup interval and retain rows
inside it.

The commit-TS vector is block-scoped, loaded at most once, and released
on success and error. `incrementalGetRowsByPK` now also closes and nils
its result vector when an error occurs, so ownership transfers to the
caller only on success.

Direct CN-created objects retain the existing object-level conservative
check because they do not carry TN row commit timestamps.

## Explicit fallback boundary

Incremental dedup on TN is a best-effort fallback, not the primary
correctness boundary for normal production DML. Pessimistic-RC
primary/unique-key locks serialize same-key writers, and `LockOp` calls
`PrimaryKeysMayBeModified` when the lock timestamp advances; `LOAD DATA`
uses a table lock.

Some legacy objects, and TN rewrites containing CN-created rows, have
missing/null row commit timestamps:

- `CheckIncremental` skips an unverifiable row to avoid upgrade/rewrite
false positives.
- Strict policies (`CheckAll` and `FullSkipWorkspaceDedup`) remain
conservative and report it as a duplicate.

This is deliberate. Making that rare incremental fallback independently
exact would require CN-origin lineage, merge propagation,
protobuf/opcode changes, and a rolling-upgrade protocol. This PR adds
none of those steady-state costs or format changes.

## Performance

- No commit-TS storage read occurs without an exact primary-key match;
this is covered by a regression test for fixed and varlen keys.
- A candidate block performs at most one commit-TS read.
- No extra column is written or propagated by flush/merge, and no
on-disk or wire format changes.
- Compared with current main, ordinary nonmatching scans keep the same
zonemap/BF/PK path. The extra read is limited to an exact matching
candidate where logical-time disambiguation is required.

## Validation

- `TestDelete3` plus all matrixorigin#26180 appendable-object visibility/rollback
tests.
- Incremental old-row rewrite, incremental concurrent-row rewrite,
direct CN-created object, and strict old/concurrent rewrite tests.
- Fixed and varlen PK tests for missing, short, null, lower-bound,
lazy-load, cached-error, and ownership behavior.
- Full tests for `pkg/objectio`, `pkg/vm/engine/tae/tables`,
`pkg/vm/engine/tae/txn/txnimpl`, and `pkg/vm/engine/tae/db/test`.
- Focused policy matrix passes `-race -count=10`; all four packages pass
full `-race`.
- CI-equivalent `go vet -mod=readonly -tags matrixone_test
-unsafeptr=false ./pkg/...` passes.
- `git diff --check` passes.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#26180)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

N/A. This regression was isolated from the `TestDelete3` failure after
matrixorigin#25534. It is unrelated to matrixorigin#26175.

## What this PR does / why we need it

### Root cause

A flush/merge transaction can collect deletes again from
`flushTableTailEntry.PrepareCommit`, after its prepare/commit timestamp
has already been assigned. If that late transfer rolls over the current
tombstone appender, `prepareApplyANode` creates one or more appendable
tombstone objects.

Since matrixorigin#25534, appendable objects are committed catalog entries outside
the transaction. The active append path is correct because the object
create timestamp precedes the append transaction commit. In the
late-transfer path, however, each object received a fresh timestamp
later than the parent flush timestamp. A snapshot could therefore see
the rewritten data while seeing none or only a prefix of its transferred
tombstones.

The deterministic reproducer on unmodified main returned visible rows
after the delete. The strengthened concurrent-snapshot mutation test
returns 22 rows without this fix and 0 with it.

### Fix

This PR keeps appendable objects outside transactions. It does not add
object-create transaction entries or object-create WAL records.

When an appendable object is created while its append transaction is
already `Preparing`, its committed catalog entry uses the parent prepare
timestamp. The object remains only a carrier: its appended rows are
still owned by the parent append MVCC node. Correctness scan paths that
cross that timestamp wait on the parent's rewritten data/append MVCC
before snapshotting transfer tombstones. WAL replay reconstructs a
missing appendable object from the append command at the same timestamp.

The normal `Active` path remains on `AllocateAndPublishCommitTS`,
preserving matrixorigin#25534's atomic timestamp allocation/catalog publication
contract. The `Preparing` branch is a deliberate, narrow exception for
parent-owned late-transfer rows; independently committed object state
must continue to use the normal publication path.

### Design and performance

- aobjects remain outside transactions and may survive creator rollback
as empty catalog shells;
- an empty shell without append/delete state remains intentionally
non-durable, as in matrixorigin#25534;
- rollback removes the parent-owned append MVCC rows, so transferred
deletes cannot become visible after parent abort;
- replay reconstructs committed carriers from append WAL without a
format or upgrade change;
- multiple carriers may share the parent timestamp; object name remains
the catalog ordering tie-breaker;
- the active path adds one transaction-state read per aobject creation,
not per row or per commit;
- the rare preparing path avoids the per-object global timestamp
allocation;
- no new I/O, WAL record, storage scan, allocation, or global
publication fence is introduced;
- tombstone-only incremental dedup remains a best-effort fallback rather
than gaining a strict global catalog fence.

## Coverage

The tests force multiple tombstone-object rollovers and cover:

- snapshots immediately before, at, and after every relevant visibility
boundary;
- a reader snapshot explicitly greater than the parent prepare
timestamp, fixed while the parent is `Preparing` and before any late
transfer object exists;
- cleanup that always releases the deterministic prepare barrier and
waits for the commit goroutine, including assertion failures;
- rollback after late transfer object creation;
- restart/replay after both commit and rollback;
- the existing outside-transaction aobject lifecycle through the full
txnimpl suite.

Validation on the final diff:

- enhanced concurrent-snapshot test: fails on unmodified main with 22
visible rows, passes with this fix;
- focused regression set: `-count=10`;
- `TestDelete3` plus the new tests: `-race -count=20`;
- full `pkg/vm/engine/tae/db/test` suite;
- full `pkg/vm/engine/tae/...` suite with `-p=1`;
- `go vet` for both modified packages;
- `go build` for `pkg/vm/engine/tae/txn/txnimpl`;
- `git diff --check`.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What this fixes

`CheckIncremental` selects committed objects in a timestamp window. For
a TN flush or merge output, however, `ObjectEntry.CreatedAt` is the
physical rewrite time, not the logical commit time of every row inside
it. Old rows rewritten after a transaction snapshot could therefore be
treated as new candidates and produce a false duplicate.

Fixes matrixorigin#26162.

The original flaky symptom was exposed by `TestDelete3`. Dedicated
deterministic tests now cover both sides of the rewrite window: old rows
must be ignored, while a row committed after the transaction snapshot
must still cause a WW conflict even if TN flushes it before pre-prepare.

## Design

For a TN-created nonappendable candidate:

1. Keep the existing object/zonemap/BF pruning.
2. Compare the primary key exactly.
3. Only after an exact match, lazily load the existing hidden row
commit-TS column.
4. Ignore rows before the inclusive dedup interval and retain rows
inside it.

The commit-TS vector is block-scoped, loaded at most once, and released
on success and error. `incrementalGetRowsByPK` now also closes and nils
its result vector when an error occurs, so ownership transfers to the
caller only on success.

Direct CN-created objects retain the existing object-level conservative
check because they do not carry TN row commit timestamps.

## Explicit fallback boundary

Incremental dedup on TN is a best-effort fallback, not the primary
correctness boundary for normal production DML. Pessimistic-RC
primary/unique-key locks serialize same-key writers, and `LockOp` calls
`PrimaryKeysMayBeModified` when the lock timestamp advances; `LOAD DATA`
uses a table lock.

Some legacy objects, and TN rewrites containing CN-created rows, have
missing/null row commit timestamps:

- `CheckIncremental` skips an unverifiable row to avoid upgrade/rewrite
false positives.
- Strict policies (`CheckAll` and `FullSkipWorkspaceDedup`) remain
conservative and report it as a duplicate.

This is deliberate. Making that rare incremental fallback independently
exact would require CN-origin lineage, merge propagation,
protobuf/opcode changes, and a rolling-upgrade protocol. This PR adds
none of those steady-state costs or format changes.

## Performance

- No commit-TS storage read occurs without an exact primary-key match;
this is covered by a regression test for fixed and varlen keys.
- A candidate block performs at most one commit-TS read.
- No extra column is written or propagated by flush/merge, and no
on-disk or wire format changes.
- Compared with current main, ordinary nonmatching scans keep the same
zonemap/BF/PK path. The extra read is limited to an exact matching
candidate where logical-time disambiguation is required.

## Validation

- `TestDelete3` plus all matrixorigin#26180 appendable-object visibility/rollback
tests.
- Incremental old-row rewrite, incremental concurrent-row rewrite,
direct CN-created object, and strict old/concurrent rewrite tests.
- Fixed and varlen PK tests for missing, short, null, lower-bound,
lazy-load, cached-error, and ownership behavior.
- Full tests for `pkg/objectio`, `pkg/vm/engine/tae/tables`,
`pkg/vm/engine/tae/txn/txnimpl`, and `pkg/vm/engine/tae/db/test`.
- Focused policy matrix passes `-race -count=10`; all four packages pass
full `-race`.
- CI-equivalent `go vet -mod=readonly -tags matrixone_test
-unsafeptr=false ./pkg/...` passes.
- `git diff --check` passes.

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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants