Repository navigation
fix: keep data branch diff after branch compaction and GC - #27464
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
aptend
left a comment
There was a problem hiding this comment.
Deep re-review completed on exact head 3869233. I re-read all historical reviews, replies, and resolved threads; checked the one-file increment after approved head 4eb4799 and re-evaluated the complete PR diff. The moerr drain sentinel is propagated by identity through shardCursor.ForEach, so the equality check preserves bounded drain semantics; the historical-schema, bounded-memory, and constructor-time recovery fixes remain closed. Validation passed under the required CGO setup: owning/dependent package list and build, full databranchutils and disttae tests, focused high-cardinality spill/drain under -race -count=20, go vet, and git diff --check.
|
The current CI blocker is unrelated to this PR and remains tracked by canonical issue #27408. On workflow run |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep re-review completed on exact head 73f7d35242f356f0fde534d1611ec3ed0d0fac18. The two prior P1 blockers are closed: historical snapshot scans now use the exact lineage boundary and schema-compatible Seqnum/type projection, while visible-state recovery uses a strict-capacity spillable store plus shared-throttler admission for buffered batches. Constructor-time FileNotFound now follows the same exact-recovery classifier as iteration-time failures. The latest commit only adds boundary/error lifecycle coverage and does not weaken behavior.
Unhappy-path audit: store/readers have one effective cleanup owner on constructor failure, exhaustion, and Close; buffer reservations are released on delivery, retry, capacity failure, and Close; accumulation is bounded by the shared Data Branch throttler and spill path, with controlled ErrMPoolCapacity for an unspillable entry.
Validation on this head: full tests for pkg/frontend/databranchutils, pkg/vm/engine, pkg/vm/engine/disttae, and pkg/vm/engine/disttae/logtailreplay; focused visible-state store and recovery/resource tests under -race -count=10.
Merge Queue Status
This pull request spent 26 minutes 52 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonThe merge conditions cannot be satisfied due to failing checks Failing checks:
HintYou may have to fix your CI before adding the pull request to the queue again. Requeued — the merge queue status continues in this comment ↓. |
Merge Queue Status
This pull request spent 28 minutes 24 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonThe merge conditions cannot be satisfied due to failing checks Failing checks:
HintYou may have to fix your CI before adding the pull request to the queue again. Requeued — the merge queue status continues in this comment ↓. |
Merge Queue Status
This pull request spent 34 seconds in the queue, including 2 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
Related to #27451
What this PR does / why we need it:
Root cause
After branch-side
mergeobjects, incremental replay can encounter a GC-removed post-clone predecessor object. Snapshot-range recovery reaches the live merge output, but that TN-created compacted object has no per-row commit timestamp metadata for evaluating the requested range. The replay layer previously reported this unevaluable condition asErrFileNotFound, conflating missing metadata with a missing file and re-entering strict replay.Exact recovery therefore has to compare visible rows at the range boundaries. Two additional constraints are required for correctness and safety:
A separate initialization gap remained after those recovery paths were added:
NewChangesHandlerWithPartitionStateRangecan synchronously returnErrFileNotFoundwhile resolving a delete chain or loading object metadata. This happens before a range handle exists, so the iteration-time recovery inbufferCurrentRangecannot run. The constructor path recognized only the distinct non-evaluable-metadata error and returned physical file loss directly.Changes
SnapshotReadPolicyVisibleState, rebuild an unevaluable range from its visible start and end states after normal replay and snapshot-range recovery are exhausted.ErrFileNotFoundor non-evaluable commit-ts metadata, initialize the exact boundary-state reader; preserve every unrelated constructor error unchanged.BETWEENlower bound advances inside the range, where it would no longer represent the requested boundary.TableDef. Match comparable columns by stable sequence number and exact type, compare by logical primary key/payload, project endpoint columns/defaults into output, and ignore physical RowID rewrites caused only by compaction.BranchHashmapadapter using the existing shared Data Branch 80% memory throttler. Strict-capacity mode returnsErrMPoolCapacityinstead of falling back to unaccounted heap memory.moerrsentinel for bounded drain termination; identity matching preserves callback and storage errors while satisfying the SCA error-construction policy.diff_9with both the original multi-object merge/GC reproduction and an ALTER-add-column variant that proves historical projection and default behavior through three forced-GC cycles.Issue-to-test proof
diff_9Case 4 reproduces [Bug]: DATA BRANCH DIFF loses history after branch-table mergeobjects and GC #27451 with six flushed source objects, changes on both sides, branch compaction, three checkpoint/GC cycles, exact four-row DIFF assertions, output count, table counts, and protection-row checks.diff_9Case 5 adds a branch-only defaulted column, changes only that column on an otherwise unchanged row, compacts the branch, runs three checkpoint/GC cycles, and proves the unchanged row is not emitted while the exact update/delete/update/insert rows and final table counts remain correct.TestInitializeVisibleStateRangeRecoversConstructorFileNotFoundproves constructor-time physical file loss selects exact visible-state recovery and forwards the original cause to that transition.TestInitializeVisibleStateRangePreservesNonRecoveryError,TestInitializeVisibleStateRangeKeepsSnapshotReaderOnSuccess, andTestInitializeVisibleStateRangePropagatesRecoveryFailurecover the other initializer transitions: unrelated errors remain visible, successful snapshot construction does not invoke recovery, and recovery-constructor failures propagate.TestVisibleStateChangesHandleProjectsHistoricalSchemaproves start and endpoint readers use compatible per-snapshot projections and that endpoint-only columns neither corrupt the historical scan nor create bogus updates.TestNewVisibleStateChangesHandleproves the supplied protected parent relation is the start boundary and verifies reader/RowID ownership.TestVisibleStateStoreSpillsAndDrainsHighCardinalityexercises 5,000 keys under a 256-byte allocator and verifies spill, lookup, bounded draining, cleanup, and zero retained allocation.TestVisibleStateStoreRejectsUnspillableEntryAtCapacityproves a single oversized entry fails with controlledErrMPoolCapacityand leaks no allocation.TestVisibleStateStoreBoundaryErrorscovers empty and invalid input, missing keys, exact callback-error propagation, zero-sized drain, idempotent close, allocator cleanup, and rejection after close.TestPartitionChangesHandleBufferCurrentRangeCapacityproves a later reservation failure cleans already-buffered batches, the failing batch, and all reservations.Verification
make buildgo test -count=1for./pkg/vm/engine,./pkg/vm/engine/disttae,./pkg/vm/engine/disttae/logtailreplay,./pkg/frontend/databranchutils, and./pkg/frontend; the full set passed again after merging currentmaingo test -race -count=20for disttae visible-state/partition recovery testsgo test -race -count=20for the spill/capacity store tests./pkg/vm/engine/disttae, focused initializer-race -count=20, full disttae-race -count=1, and disttaego vetmake err-check, controlled CGo build, vet, and full./pkg/frontend/databranchutilstestsTestVisibleStateStoreBoundaryErrorswith a focused coverage profile, full databranchutils tests, focused-race -count=100(measured duration below timer resolution), and full databranchutils-race; the focused profile covers 11 blocks that the failed CI profile missedgo vetfor all changed packagesmo-tester -p test/distributed/cases/git4data/branch/diff/diff_9.sql -m run -g -n: 133/133 statements passed; generated results were manually checked for exact SQL semantics before being accepted38692335d3passed build, UT, arm64 SCA, UT coverage, compose BVT, and standalone BVT. Changed-code coverage alone failed at 297/400 (74.25%, required >75%); the focused profile forTestVisibleStateStoreBoundaryErrorscovers 11 previously missed changed blocks. CI for73f7d35242is pending.Residual risk
Visible-state recovery scans both boundary snapshots and can spill the start side to local disk, so it is more I/O-intensive than incremental replay. It is restricted to the Data Branch visible-state policy and activates only after replay metadata cannot evaluate the compacted range or the snapshot-range constructor proves required physical history has already been removed. Memory is governed by the same admission budget as the downstream diff hashmaps; an unspillable entry or buffered batch returns a controlled capacity error with cleanup rather than risking CN OOM. Snapshot, catalog, schema, spill, reader, and unrelated constructor failures are propagated rather than interpreted as empty state.