Skip to content

fix(disttae): fence latest logtail reads with pending table apply - #25649

Merged
XuPeng-SH merged 1 commit into
matrixorigin:4.1-devfrom
LeftHandCold:fix-logtail-read-fence
Jul 13, 2026
Merged

XuPeng-SH merged 1 commit into
matrixorigin:4.1-devfrom
LeftHandCold:fix-logtail-read-fence

Conversation

@LeftHandCold

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:

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

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

@mergify mergify Bot added the kind/bug Something isn't working label Jul 13, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Jul 13, 2026
@XuPeng-SH
XuPeng-SH merged commit f88bc22 into matrixorigin:4.1-dev Jul 13, 2026
23 checks passed

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