Repository navigation
fix(disttae): fence latest logtail reads with pending table apply - #25515
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
LGTM. I reviewed the latest head with focus on the logtail visibility invariant, pending-table state lifecycle, snapshot fallback, wait/cancel behavior, and race/unhappy paths.
The direction is sound: global logtail timestamp advancement is still preserved, while the latest-state fast path is fenced only when the table has a known pending update and its PartitionState has not applied through snapshot.Prev(). That keeps the normal no-pending fast path and checkpoint snapshot fallback intact.
Checks run locally:
git diff --check origin/main...HEADgo test -v -count=1 -run 'TestCanServeTableSnapshotBlocksPendingUpdate|TestWaitCanServeTableSnapshotWaitsForPendingUpdate|TestDispatchUpdateResponseAdvancesTimestampAfterLastLogtail|TestDispatchUpdateResponseCoalescesTimestampCommands' ./pkg/vm/engine/disttaego test -race -v -count=1 -run 'TestCanServeTableSnapshotBlocksPendingUpdate|TestWaitCanServeTableSnapshotWaitsForPendingUpdate|TestDispatchUpdateResponseAdvancesTimestampAfterLastLogtail|TestDispatchUpdateResponseCoalescesTimestampCommands' ./pkg/vm/engine/disttaego test ./pkg/vm/engine/disttae/logtailreplay -run 'Test' -count=1
CI Summary is green. The branch is behind main, so it still needs a normal refresh/rebase before merge.
Merge Queue Status
This pull request spent 1 hour 23 minutes 48 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonPull request #25515 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
Failing checks:
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Tick the box to put this pull request back in the merge queue (same as
|
…trixorigin#25515) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#25232 ## What this PR does / why we need it: When a CN receives a logtail update response, the global logtail timestamp can advance before every table logtail in that response has been applied to its latest `PartitionState`. The latest subscribed table state can still have a `[start, MaxTs]` serving range, so checking only `CanServe(snapshot)` can let a read use a table state that has not applied updates below `snapshot.Prev()`. In a cross-table consistency check, this can expose one updated table and one stale table from the same committed transaction. This PR fences that latest-state fast path: - tracks a per-table `appliedTo` watermark in `PartitionState` - marks subscribed tables as pending when an update response contains their logtail - clears the pending mark only after that table logtail has been consumed - makes `txnTable.getPartitionState` wait for the latest table state to apply through `snapshot.Prev()` when that table has a known pending update - preserves the original fast path when there is no pending update, and preserves snapshot checkpoint fallback when the latest state truly cannot serve the snapshot Validation: - `git diff --check base/main...HEAD` - `go test -v -count=1 -run 'TestCanServeTableSnapshotBlocksPendingUpdate|TestWaitCanServeTableSnapshotWaitsForPendingUpdate|TestDispatchUpdateResponseAdvancesTimestampAfterLastLogtail|TestDispatchUpdateResponseCoalescesTimestampCommands' ./pkg/vm/engine/disttae` - `go test -race -v -count=1 -run 'TestCanServeTableSnapshotBlocksPendingUpdate|TestWaitCanServeTableSnapshotWaitsForPendingUpdate|TestDispatchUpdateResponseAdvancesTimestampAfterLastLogtail|TestDispatchUpdateResponseCoalescesTimestampCommands' ./pkg/vm/engine/disttae` - verified on a 2-CN dev cluster with temporary fault-injection hooks that force the global logtail timestamp to advance before table apply; 3 runs all hit the new pending-table wait path and returned consistent `20/20` counts Note: full `./pkg/vm/engine/disttae` package test was also attempted locally, but the sandbox cannot bind the unix socket used by `TestWaitServerReady/ok` (`operation not permitted`), so it timed out on that unrelated test. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…trixorigin#25515) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#25232 ## What this PR does / why we need it: When a CN receives a logtail update response, the global logtail timestamp can advance before every table logtail in that response has been applied to its latest `PartitionState`. The latest subscribed table state can still have a `[start, MaxTs]` serving range, so checking only `CanServe(snapshot)` can let a read use a table state that has not applied updates below `snapshot.Prev()`. In a cross-table consistency check, this can expose one updated table and one stale table from the same committed transaction. This PR fences that latest-state fast path: - tracks a per-table `appliedTo` watermark in `PartitionState` - marks subscribed tables as pending when an update response contains their logtail - clears the pending mark only after that table logtail has been consumed - makes `txnTable.getPartitionState` wait for the latest table state to apply through `snapshot.Prev()` when that table has a known pending update - preserves the original fast path when there is no pending update, and preserves snapshot checkpoint fallback when the latest state truly cannot serve the snapshot Validation: - `git diff --check base/main...HEAD` - `go test -v -count=1 -run 'TestCanServeTableSnapshotBlocksPendingUpdate|TestWaitCanServeTableSnapshotWaitsForPendingUpdate|TestDispatchUpdateResponseAdvancesTimestampAfterLastLogtail|TestDispatchUpdateResponseCoalescesTimestampCommands' ./pkg/vm/engine/disttae` - `go test -race -v -count=1 -run 'TestCanServeTableSnapshotBlocksPendingUpdate|TestWaitCanServeTableSnapshotWaitsForPendingUpdate|TestDispatchUpdateResponseAdvancesTimestampAfterLastLogtail|TestDispatchUpdateResponseCoalescesTimestampCommands' ./pkg/vm/engine/disttae` - verified on a 2-CN dev cluster with temporary fault-injection hooks that force the global logtail timestamp to advance before table apply; 3 runs all hit the new pending-table wait path and returned consistent `20/20` counts Note: full `./pkg/vm/engine/disttae` package test was also attempted locally, but the sandbox cannot bind the unix socket used by `TestWaitServerReady/ok` (`operation not permitted`), so it timed out on that unrelated test. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…trixorigin#25515) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#25232 ## What this PR does / why we need it: When a CN receives a logtail update response, the global logtail timestamp can advance before every table logtail in that response has been applied to its latest `PartitionState`. The latest subscribed table state can still have a `[start, MaxTs]` serving range, so checking only `CanServe(snapshot)` can let a read use a table state that has not applied updates below `snapshot.Prev()`. In a cross-table consistency check, this can expose one updated table and one stale table from the same committed transaction. This PR fences that latest-state fast path: - tracks a per-table `appliedTo` watermark in `PartitionState` - marks subscribed tables as pending when an update response contains their logtail - clears the pending mark only after that table logtail has been consumed - makes `txnTable.getPartitionState` wait for the latest table state to apply through `snapshot.Prev()` when that table has a known pending update - preserves the original fast path when there is no pending update, and preserves snapshot checkpoint fallback when the latest state truly cannot serve the snapshot Validation: - `git diff --check base/main...HEAD` - `go test -v -count=1 -run 'TestCanServeTableSnapshotBlocksPendingUpdate|TestWaitCanServeTableSnapshotWaitsForPendingUpdate|TestDispatchUpdateResponseAdvancesTimestampAfterLastLogtail|TestDispatchUpdateResponseCoalescesTimestampCommands' ./pkg/vm/engine/disttae` - `go test -race -v -count=1 -run 'TestCanServeTableSnapshotBlocksPendingUpdate|TestWaitCanServeTableSnapshotWaitsForPendingUpdate|TestDispatchUpdateResponseAdvancesTimestampAfterLastLogtail|TestDispatchUpdateResponseCoalescesTimestampCommands' ./pkg/vm/engine/disttae` - verified on a 2-CN dev cluster with temporary fault-injection hooks that force the global logtail timestamp to advance before table apply; 3 runs all hit the new pending-table wait path and returned consistent `20/20` counts Note: full `./pkg/vm/engine/disttae` package test was also attempted locally, but the sandbox cannot bind the unix socket used by `TestWaitServerReady/ok` (`operation not permitted`), so it timed out on that unrelated test. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…trixorigin#25515) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#25232 ## What this PR does / why we need it: When a CN receives a logtail update response, the global logtail timestamp can advance before every table logtail in that response has been applied to its latest `PartitionState`. The latest subscribed table state can still have a `[start, MaxTs]` serving range, so checking only `CanServe(snapshot)` can let a read use a table state that has not applied updates below `snapshot.Prev()`. In a cross-table consistency check, this can expose one updated table and one stale table from the same committed transaction. This PR fences that latest-state fast path: - tracks a per-table `appliedTo` watermark in `PartitionState` - marks subscribed tables as pending when an update response contains their logtail - clears the pending mark only after that table logtail has been consumed - makes `txnTable.getPartitionState` wait for the latest table state to apply through `snapshot.Prev()` when that table has a known pending update - preserves the original fast path when there is no pending update, and preserves snapshot checkpoint fallback when the latest state truly cannot serve the snapshot Validation: - `git diff --check base/main...HEAD` - `go test -v -count=1 -run 'TestCanServeTableSnapshotBlocksPendingUpdate|TestWaitCanServeTableSnapshotWaitsForPendingUpdate|TestDispatchUpdateResponseAdvancesTimestampAfterLastLogtail|TestDispatchUpdateResponseCoalescesTimestampCommands' ./pkg/vm/engine/disttae` - `go test -race -v -count=1 -run 'TestCanServeTableSnapshotBlocksPendingUpdate|TestWaitCanServeTableSnapshotWaitsForPendingUpdate|TestDispatchUpdateResponseAdvancesTimestampAfterLastLogtail|TestDispatchUpdateResponseCoalescesTimestampCommands' ./pkg/vm/engine/disttae` - verified on a 2-CN dev cluster with temporary fault-injection hooks that force the global logtail timestamp to advance before table apply; 3 runs all hit the new pending-table wait path and returned consistent `20/20` counts Note: full `./pkg/vm/engine/disttae` package test was also attempted locally, but the sandbox cannot bind the unix socket used by `TestWaitServerReady/ok` (`operation not permitted`), so it timed out on that unrelated test. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #25232
What this PR does / why we need it:
When a CN receives a logtail update response, the global logtail timestamp can advance before every table logtail in that response has been applied to its latest
PartitionState. The latest subscribed table state can still have a[start, MaxTs]serving range, so checking onlyCanServe(snapshot)can let a read use a table state that has not applied updates belowsnapshot.Prev(). In a cross-table consistency check, this can expose one updated table and one stale table from the same committed transaction.This PR fences that latest-state fast path:
appliedTowatermark inPartitionStatetxnTable.getPartitionStatewait for the latest table state to apply throughsnapshot.Prev()when that table has a known pending updateValidation:
git diff --check base/main...HEADgo test -v -count=1 -run 'TestCanServeTableSnapshotBlocksPendingUpdate|TestWaitCanServeTableSnapshotWaitsForPendingUpdate|TestDispatchUpdateResponseAdvancesTimestampAfterLastLogtail|TestDispatchUpdateResponseCoalescesTimestampCommands' ./pkg/vm/engine/disttaego test -race -v -count=1 -run 'TestCanServeTableSnapshotBlocksPendingUpdate|TestWaitCanServeTableSnapshotWaitsForPendingUpdate|TestDispatchUpdateResponseAdvancesTimestampAfterLastLogtail|TestDispatchUpdateResponseCoalescesTimestampCommands' ./pkg/vm/engine/disttae20/20countsNote: full
./pkg/vm/engine/disttaepackage test was also attempted locally, but the sandbox cannot bind the unix socket used byTestWaitServerReady/ok(operation not permitted), so it timed out on that unrelated test.