Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
4.2-dev
Commit ID
Other Environment Information
- CN logtail replay /
PartitionStatecopy-on-write ownership. - This report tracks the missing 4.2 backport of the RowEntry isolation fix already included in main PR fix(disttae): prune unflushed composite CLUSTER BY reads in CN logtail replay state #30617 (
b58d92746d619a9313fe48590eb1d491f5fe8056). It does not request the composite CLUSTER BY feature from that PR. - This is a source-level/replay-component correctness finding, not a confirmed root cause of a production incident. No customer data or production-log evidence is included.
Actual Behavior
Partition.MutateState() copies a PartitionState, and publication occurs only in the returned callback. Readers retain the previously published state. However, rows stores *RowEntry: copying the B-tree does not copy these pointed-to objects.
In both HandleRowsInsert and HandleRowsDelete, an existing entry matched by (BlockID, RowID, Time) is modified directly before rows.Set(entry):
- INSERT replaces
Batch,Offset, andPrimaryIndexBytes. - DELETE additionally sets
Deleted=true.
Consequently, replay into an unpublished state can mutate an entry retained by a published snapshot. A concurrent reader of those fields is not protected by the partition writer lock. Replaying the same rows in a different batch order changes the old snapshot's batch/offset; changing an existing insertion to a same-version deletion can change what its old row/PK iterators return.
Source:
- Partition mutation and publication
- Existing entry modified by DELETE
- Existing entry modified by INSERT
Trigger and impact boundary: the entry must already be shared with a published state. A repeated entry created only within the current unpublished mutation is not sufficient. Ordinary concurrent reads/writes alone do not prove this precondition. Duplicate delivery or overlapping replay in an actual production execution has not been established here. Incorrect reads depend on the affected fields and interleaving; these handlers do not directly rewrite TN/objects. This issue does not assert durable corruption or that this patch fixes an unrelated production incident.
Expected Behavior
Once published, a RowEntry remains immutable for readers retaining that state. Reapplying an existing physical version must update a private replacement, retain its identity/ID, preserve delete precedence, and leave both old and new iterators consistent with their own states.
Steps to Reproduce
At the production replay-component boundary, with two rows and no external service:
- Create a Partition, replay two rows into
MutateState(), and publish. - Retain
Snapshot()and the first RowEntry's batch/offset/ID/deletion flag. - Create the next mutable state and reapply those same physical row versions in reversed batch order using the actual handlers.
- Before publishing the new state, assert the retained entry is unchanged and check the old row/PK iterators. On the affected code, the original object is modified.
- Repeat for duplicate DELETE, same-version INSERT→DELETE and DELETE→INSERT, including
noData; retain the existing delete-wins semantics. - Exercise a reader of the retained entry concurrently with replay under the race detector.
This injected replay regression proves the component's isolation contract, not the frequency or delivery sequence of a production incident.
Baseline validation (macOS arm64, Go 1.26.4, native dependencies built from the stated 4.2 commit): TestPartitionStateRowEntrySnapshotIsolation fails all eight subcases with the test-only addition and unchanged production code. Failures show old Batch/Offset or Deleted changing, or the supposedly private replacement being the same RowEntry object. The test body completes in under 0.01 s; no SQL service or production environment was used.
Additional information
Proposed narrow fix: copy the existing RowEntry value in both handlers before modifying it, exactly as main already does. No reader lock, deep copy of immutable batch payloads, wire/storage-format change, new cache, or CLUSTER BY index is needed.
Acceptance: the unchanged regression fails on the affected baseline and passes with the fix; owning-package normal/race tests pass; old snapshot reads remain stable, physical-version IDs/index cardinality are preserved, and repeated replay does not resurrect deleted versions.
Activity
[4.2-dev] fix(disttae): preserve RowEntry snapshot isolation during r…