Skip to content

fix(disttae): recapture table state after pending logtail apply - #26009

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
LeftHandCold:fix/26006-stale-partition-snapshot
Jul 22, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
LeftHandCold:fix/26006-stale-partition-snapshot

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:

issue #26006

What this PR does / why we need it:

The latest subscribed-table read path captured an immutable PartitionState
before it checked the table's pending logtail marker. If the logtail consumer
published a newer state and cleared that marker between those two operations,
the reader saw pending=false and admitted its previously captured stale state.

This race caused the mo_ctl_merge BVT in job
https://github.com/matrixorigin/matrixone/actions/runs/29838470048/job/88667877201
to see fewer than two merge candidates and return no matching objects; one
second later, metadata_scan recaptured the state and saw both unmerged objects.
The job belonged to #25970, but that PR changes only backup file-index ordering
and does not touch the affected disttae/logtail path.

Capture the pending marker before the immutable partition snapshot while holding
the subscription generation. With this ordering, a cleared marker proves that
the later snapshot includes the applied update; a present marker continues to
use the existing applied-watermark wait. The no-pending fast path, historical
checkpoint fallback, cancellation, and PK-check reconnect fencing are unchanged.

Add a deterministic regression test that retains a pre-apply snapshot, publishes
a state covering the read timestamp, clears the pending marker, and verifies that
the admission path returns the refreshed state. The test failed on current main
with the stale applied watermark before the fix.

Tested with:

go test -count=1 ./pkg/vm/engine/disttae

go test -race -count=1 -run '^(TestCanServeTableSnapshotBlocksPendingUpdate|TestWaitCanServeTableSnapshotWaitsForPendingUpdate|TestWaitCanServeTableSnapshotRefreshesAfterPendingApply|TestPKCheckSnapshotRejectsResetSubscriptionGeneration|TestPKCheckSnapshotRefreshesAfterPendingApply|TestPKCheckSnapshotRejectsClosedPushClientAdmission)$' ./pkg/vm/engine/disttae

go vet ./pkg/vm/engine/disttae

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

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

Codex automated review

The stale-state race is correctly closed and CI is green. One non-blocking fast-path performance regression remains.

P2 - Avoid recapturing the partition twice on every table read (pkg/vm/engine/disttae/logtail_consumer.go:398)

getPartitionState first calls toSubscribeTable, which always captures a snapshot through isSubscribed on success. This new call immediately discards that snapshot and repeats the subscription lookup, timestamp sampling, and GetOrCreateLatestPart, including a globally serialized Engine.Lock. Thus even the common no-pending path now acquires the global engine mutex twice per table open. Carry the pending marker alongside the initial pending-before-snapshot capture, or provide a subscription-only path so the first admission attempt needs only one capture.

@mergify

mergify Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

@mergify

mergify Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-22 11:24 UTC · Rule: main · triggered by @LeftHandCold with the merge queue checkbox
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-07-22 11:46 UTC · at e5535fd37bd9046e49ec486bb6ab9d2336ad7b00

This pull request spent 21 minutes 56 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 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 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] (documentation)
  • github-review-decision = APPROVED [🛡 GitHub branch protection] (documentation)

Reason

Pull request #26009 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 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.

Re-reviewed exact head b79905f85338bc1883c05c6a916b578a70f2be8e. No remaining actionable findings.

The previous hot-path blocker is fixed: getPartitionState now reuses the pending-before-snapshot capture returned by toSubscribeTable, so the common subscribed/no-pending path performs one partition capture; recapture occurs only after a real pending wait/retry. The stale-state race remains closed because both the initial attempt and retries validate the subscription generation and read pendingTo before taking the immutable snapshot. Context cancellation, historical checkpoint fallback, and PK-check reconnect fencing are preserved.

Q1-Q3: no new resource ownership, all waits terminate via apply/recapture or caller cancellation, and pending state remains one bounded atomic marker per subscription.

Validation on this exact head passed: focused concurrency regressions under -race -count=20 -shuffle=on, the complete disttae package both normally and under -race, go build, go vet, and git diff --check. Current-head CI has no reported failure at review time.

@mergify mergify Bot added the queued label Jul 22, 2026
@XuPeng-SH
XuPeng-SH merged commit f6070a0 into matrixorigin:main Jul 22, 2026
30 checks passed
@mergify mergify Bot added dequeued and removed queued labels Jul 22, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…ixorigin#26009)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#26006

## What this PR does / why we need it:

The latest subscribed-table read path captured an immutable
`PartitionState`
before it checked the table's pending logtail marker. If the logtail
consumer
published a newer state and cleared that marker between those two
operations,
the reader saw `pending=false` and admitted its previously captured
stale state.

This race caused the `mo_ctl_merge` BVT in job

https://github.com/matrixorigin/matrixone/actions/runs/29838470048/job/88667877201
to see fewer than two merge candidates and return `no matching objects`;
one
second later, `metadata_scan` recaptured the state and saw both unmerged
objects.
The job belonged to matrixorigin#25970, but that PR changes only backup file-index
ordering
and does not touch the affected disttae/logtail path.

Capture the pending marker before the immutable partition snapshot while
holding
the subscription generation. With this ordering, a cleared marker proves
that
the later snapshot includes the applied update; a present marker
continues to
use the existing applied-watermark wait. The no-pending fast path,
historical
checkpoint fallback, cancellation, and PK-check reconnect fencing are
unchanged.

Add a deterministic regression test that retains a pre-apply snapshot,
publishes
a state covering the read timestamp, clears the pending marker, and
verifies that
the admission path returns the refreshed state. The test failed on
current main
with the stale applied watermark before the fix.

Tested with:

`go test -count=1 ./pkg/vm/engine/disttae`

`go test -race -count=1 -run
'^(TestCanServeTableSnapshotBlocksPendingUpdate|TestWaitCanServeTableSnapshotWaitsForPendingUpdate|TestWaitCanServeTableSnapshotRefreshesAfterPendingApply|TestPKCheckSnapshotRejectsResetSubscriptionGeneration|TestPKCheckSnapshotRefreshesAfterPendingApply|TestPKCheckSnapshotRejectsClosedPushClientAdmission)$'
./pkg/vm/engine/disttae`

`go vet ./pkg/vm/engine/disttae`

---------

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
…ixorigin#26009)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#26006

## What this PR does / why we need it:

The latest subscribed-table read path captured an immutable
`PartitionState`
before it checked the table's pending logtail marker. If the logtail
consumer
published a newer state and cleared that marker between those two
operations,
the reader saw `pending=false` and admitted its previously captured
stale state.

This race caused the `mo_ctl_merge` BVT in job

https://github.com/matrixorigin/matrixone/actions/runs/29838470048/job/88667877201
to see fewer than two merge candidates and return `no matching objects`;
one
second later, `metadata_scan` recaptured the state and saw both unmerged
objects.
The job belonged to matrixorigin#25970, but that PR changes only backup file-index
ordering
and does not touch the affected disttae/logtail path.

Capture the pending marker before the immutable partition snapshot while
holding
the subscription generation. With this ordering, a cleared marker proves
that
the later snapshot includes the applied update; a present marker
continues to
use the existing applied-watermark wait. The no-pending fast path,
historical
checkpoint fallback, cancellation, and PK-check reconnect fencing are
unchanged.

Add a deterministic regression test that retains a pre-apply snapshot,
publishes
a state covering the read timestamp, clears the pending marker, and
verifies that
the admission path returns the refreshed state. The test failed on
current main
with the stale applied watermark before the fix.

Tested with:

`go test -count=1 ./pkg/vm/engine/disttae`

`go test -race -count=1 -run
'^(TestCanServeTableSnapshotBlocksPendingUpdate|TestWaitCanServeTableSnapshotWaitsForPendingUpdate|TestWaitCanServeTableSnapshotRefreshesAfterPendingApply|TestPKCheckSnapshotRejectsResetSubscriptionGeneration|TestPKCheckSnapshotRefreshesAfterPendingApply|TestPKCheckSnapshotRejectsClosedPushClientAdmission)$'
./pkg/vm/engine/disttae`

`go vet ./pkg/vm/engine/disttae`

---------

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
…ixorigin#26009)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#26006

## What this PR does / why we need it:

The latest subscribed-table read path captured an immutable
`PartitionState`
before it checked the table's pending logtail marker. If the logtail
consumer
published a newer state and cleared that marker between those two
operations,
the reader saw `pending=false` and admitted its previously captured
stale state.

This race caused the `mo_ctl_merge` BVT in job

https://github.com/matrixorigin/matrixone/actions/runs/29838470048/job/88667877201
to see fewer than two merge candidates and return `no matching objects`;
one
second later, `metadata_scan` recaptured the state and saw both unmerged
objects.
The job belonged to matrixorigin#25970, but that PR changes only backup file-index
ordering
and does not touch the affected disttae/logtail path.

Capture the pending marker before the immutable partition snapshot while
holding
the subscription generation. With this ordering, a cleared marker proves
that
the later snapshot includes the applied update; a present marker
continues to
use the existing applied-watermark wait. The no-pending fast path,
historical
checkpoint fallback, cancellation, and PK-check reconnect fencing are
unchanged.

Add a deterministic regression test that retains a pre-apply snapshot,
publishes
a state covering the read timestamp, clears the pending marker, and
verifies that
the admission path returns the refreshed state. The test failed on
current main
with the stale applied watermark before the fix.

Tested with:

`go test -count=1 ./pkg/vm/engine/disttae`

`go test -race -count=1 -run
'^(TestCanServeTableSnapshotBlocksPendingUpdate|TestWaitCanServeTableSnapshotWaitsForPendingUpdate|TestWaitCanServeTableSnapshotRefreshesAfterPendingApply|TestPKCheckSnapshotRejectsResetSubscriptionGeneration|TestPKCheckSnapshotRefreshesAfterPendingApply|TestPKCheckSnapshotRejectsClosedPushClientAdmission)$'
./pkg/vm/engine/disttae`

`go vet ./pkg/vm/engine/disttae`

---------

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

Development

Successfully merging this pull request may close these issues.

4 participants