Skip to content

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

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
LeftHandCold:sjw/fix-25232-logtail-read-fence
Jul 7, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
LeftHandCold:sjw/fix-25232-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.

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

@XuPeng-SH XuPeng-SH 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. 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...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
  • go 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.

@mergify mergify Bot added the queued label Jul 7, 2026
@mergify

mergify Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-07 13:00 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-07-07 14:24 UTC · at 6c09534e07945426df08674b106fc713c8e71595

This pull request spent 1 hour 23 minutes 48 seconds in the queue, with no time running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • github-review-decision = APPROVED [🛡 GitHub branch protection]

Reason

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

The author needs to enable "Allow edits from maintainers" on this pull request.

Failing checks:

Hint

You 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.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

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

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit 84e9bd8 into matrixorigin:main Jul 7, 2026
22 of 24 checks passed
@mergify mergify Bot added dequeued and removed queued labels Jul 7, 2026
LeftHandCold added a commit to LeftHandCold/matrixone that referenced this pull request Jul 13, 2026
…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>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…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>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…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>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…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>

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

3 participants