Skip to content

test(cdc): stabilize watermark drop race observation - #28283

Merged
mergify[bot] merged 1 commit into
matrixorigin:mainfrom
gouhongshen:agent/issue-28282-83866b31
Sep 6, 2026
Merged

mergify[bot] merged 1 commit into
matrixorigin:mainfrom
gouhongshen:agent/issue-28282-83866b31

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR relates to:

Related to #28282

What this PR does / why we need it:

Root cause

The regression scanned IterLocks across CNs. That observer enumerates only local lock tables, so it can miss a waiter when the task-table lock is represented by a remote or bound table. The holder transaction itself has the authoritative wait graph.

Change

The two-CN regression obtains each executor CN lock service, captures both holder and contender transaction IDs immediately when ExecTxn enters its callback, and keeps the holder readiness barrier after its lock-producing statements. It queries GetWaitingList from the holder lock service, whose routed query reaches the authoritative owner, and accepts the observation only when the wait graph contains that exact contender ID.

The lock probe now uses a dedicated 30-second context and synchronous retry loop. Thus the budget bounds an in-flight remote query as well as the retry window; cleanup cannot overlap an orphaned observation goroutine. On failure it reports the last probe error and observed waiter IDs. The generic transaction helper API remains unchanged; transaction metadata is captured only for this lock-waiter scenario.

Issue-to-test proof

TestIssue27666CDCWatermarkWriteSerializesWithDrop directly proves #28282: in both drop-first and writer-first orderings, it holds the task-row lock, observes the exact competing transaction in the holder wait graph, then proves that neither the CDC task nor either watermark row survives. TestCDCWaiterProbe proves the oracle rejects an unrelated waiter and that cancellation joins an in-flight probe. TestCDCRaceTxn retains coverage of readiness, cancellation, cleanup, and transaction errors.

A BVT is not appropriate for this test-only failure: reproducing it requires pinned uncommitted internal transactions and inspecting the private lock-service wait graph. The embedded two-CN unit test is the boundary that can deterministically assert that state while also exercising the public SQL effects.

Tests run

  • Rebased onto origin/main at a6ee717132; the last base increment changes ordered-upsert DML/compiler paths, so the focused two-CN regression and full owning package were rerun.
  • .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=240s -run "^(TestIssue27666CDCWatermarkWriteSerializesWithDrop|TestCDCRaceTxn|TestCDCWaiterProbe)$" ./pkg/tests/issues (PASS on a6ee717132, 14.088s)
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=600s ./pkg/tests/issues (PASS on a6ee717132, 68.325s)
  • .agents/skills/mo-dev/scripts/mo-cgo-test -race -count=2 -timeout=300s -run "^(TestIssue27666CDCWatermarkWriteSerializesWithDrop|TestCDCRaceTxn|TestCDCWaiterProbe)$" ./pkg/tests/issues (PASS, 59.666s, before the final base-only rebase; the test change itself is identical)
  • A fresh GitHub CI run was triggered for 012d0b7ad4; results are pending.

Residual risk

This changes test observation only; no CDC or lock-service production path changes. Darwin/x86 UT and configured disabled variants are skipped by the workflow.

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

Deep-reviewed exact head 51bf19ff0fd24473c1c0b3b6911b329bd5e68b1f with the transaction/lock ownership and wait-for graph traced through GetWaitingList and its remote-owner path. Replacing IterLocks with the holder-rooted routed wait graph addresses the reported observation miss, but the new test still has two deterministic-test blockers.

[P1] Prove that the observed waiter is this tests contender

holder.waiterCount(...) > 0 accepts any transaction waiting on any lock held by the holder. The shared embedded cluster has background work and is reused across issue tests; the holder also executes more than one catalog statement and can own multiple table/index locks. An unrelated waiter can therefore satisfy readiness, after which the final empty-state assertions may pass without proving that the guarded watermark writer and drop actually reached the intended serialization edge.

Capture the contender transaction ID immediately after ExecTxn enters its callback and before executing the blocking statement, publish that through a separate started barrier, and require the holder waiting list to contain that exact ID. Keep the holder ready barrier after its lock-producing statements. This turns the oracle from existence-based to causal and directly proves both orderings.

[P2] Bound and join the wait-graph probe itself

require.Eventually runs the condition in a goroutine. Its 30-second timer can return while GetWaitingList is still running, because each probe receives the outer 180-second context and may traverse remote owners. That leaves an observation goroutine overlapping transaction cleanup or the next subtest—the same lifecycle shape that can create a new flake. Use a dedicated 30-second probe context and a synchronous retry loop (or otherwise cancel and join the in-flight probe) so the advertised budget owns the RPC lifetime.

Also, the current failure text cannot report waiterErr: variadic arguments are evaluated before require.Eventually starts, so it captures the initial nil value. Report the last error/waiter IDs after the bounded loop exits. Add/retain race coverage for timeout/cancellation as well as both successful lock orderings.

No production CDC/lockservice change is needed; this is a test-oracle and lifecycle correction.

@gouhongshen

Copy link
Copy Markdown
Contributor Author

@XuPeng-SH Addressed both requested test-oracle/lifecycle corrections in e30ab531f5.

  • P1: both transactions publish IDs when their ExecTxn callbacks begin, before any potentially blocking statement. The holder remains ready only after its lock-producing statements; the probe now requires GetWaitingList(holderID) to contain the exact contender ID. TestCDCWaiterProbe explicitly rejects an unrelated waiter.
  • P2: the probe is a synchronous loop under its own 30-second context, so an in-flight routed query is bounded and joined before cleanup. It retains last observed IDs/errors for the failure. TestCDCWaiterProbe verifies cancellation joins an in-flight probe.

Current-head verification on cd0d9238f7: focused two-CN/lifecycle suite PASS (13.076s), the same suite -race -count=2 PASS (59.666s), and pkg/tests/issues PASS (121.210s). The PR description has the full evidence. Please re-review when convenient.

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

Deep-reviewed exact head 012d0b7ad49d6970bf9ccbeb7dfc09c74a640218 against base a6ee7171327e3999e33748d4c872994178fabcdf. The two blockers from the prior review are closed.

The regression now publishes both transaction IDs at callback entry, retains holder readiness after the lock-producing statements, and accepts the waiter observation only when the holder-rooted wait graph contains the exact contender ID. This rejects unrelated background waiters while preserving both drop-first and writer-first causal orderings. GetWaitingList follows the negotiated owner-local route for remote/bound lock tables, which addresses the observation gap in IterLocks.

The probe is synchronous under a dedicated 30-second context. I traced that context through GetWaitingList, remote snapshot RPCs, retry backoff, and morpc.Send; an in-flight probe therefore terminates before transaction cleanup. Last observed waiter IDs/errors are retained for failure diagnostics.

Unhappy-path closure:

  • Q1: each transaction goroutine has one registered cancel-and-join cleanup owner; LIFO cleanup joins contender and holder before catalog cleanup. Probe context and ticker are released locally.
  • Q2: holder release, transaction cancellation, probe RPC/backoff, finish joins, and fixture cleanup all have independent bounded termination paths.
  • Q3: one synchronous probe is in flight at a time; retry duration is bounded, and observed waiter state is replaced rather than accumulated.

No production path or hot-path cost changes. Counterexamples cover an unrelated waiter, cancellation of an in-flight probe, transaction startup/statement/commit failure, cancellation before/inside callback, repeated joins, and cleanup ordering. Exact-head Linux UT, coverage UT, SCA, standalone/compose BVT, and coverage merge are green; author evidence also includes the focused suite, full owning package, and focused -race -count=2. git diff --check and formatting checks are clean.

@gouhongshen

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-06 15:06 UTC · Rule: main · triggered by @gouhongshen with the @mergifyio queue command
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-09-06 15:06 UTC · at 9ae27d218dc952571ec2ce2b5575e2e61e844279 · squash

This pull request spent 23 seconds in the queue, including 2 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)

@mergify mergify Bot added the queued label Sep 6, 2026
@mergify
mergify Bot merged commit 9ae27d2 into matrixorigin:main Sep 6, 2026
33 checks passed
@mergify mergify Bot removed the queued label Sep 6, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
)

### Root cause

The regression scanned `IterLocks` across CNs. That observer enumerates only local lock tables, so it can miss a waiter when the task-table lock is represented by a remote or bound table. The holder transaction itself has the authoritative wait graph.

### Change

The two-CN regression obtains each executor CN lock service, captures both holder and contender transaction IDs immediately when `ExecTxn` enters its callback, and keeps the holder readiness barrier after its lock-producing statements. It queries `GetWaitingList` from the holder lock service, whose routed query reaches the authoritative owner, and accepts the observation only when the wait graph contains that exact contender ID.

The lock probe now uses a dedicated 30-second context and synchronous retry loop. Thus the budget bounds an in-flight remote query as well as the retry window; cleanup cannot overlap an orphaned observation goroutine. On failure it reports the last probe error and observed waiter IDs. The generic transaction helper API remains unchanged; transaction metadata is captured only for this lock-waiter scenario.

### Issue-to-test proof

`TestIssue27666CDCWatermarkWriteSerializesWithDrop` directly proves matrixorigin#28282: in both drop-first and writer-first orderings, it holds the task-row lock, observes the exact competing transaction in the holder wait graph, then proves that neither the CDC task nor either watermark row survives. `TestCDCWaiterProbe` proves the oracle rejects an unrelated waiter and that cancellation joins an in-flight probe. `TestCDCRaceTxn` retains coverage of readiness, cancellation, cleanup, and transaction errors.

A BVT is not appropriate for this test-only failure: reproducing it requires pinned uncommitted internal transactions and inspecting the private lock-service wait graph. The embedded two-CN unit test is the boundary that can deterministically assert that state while also exercising the public SQL effects.

### Tests run

- Rebased onto `origin/main` at `a6ee717132`; the last base increment changes ordered-upsert DML/compiler paths, so the focused two-CN regression and full owning package were rerun.
- `.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=240s -run "^(TestIssue27666CDCWatermarkWriteSerializesWithDrop|TestCDCRaceTxn|TestCDCWaiterProbe)$" ./pkg/tests/issues` (PASS on `a6ee717132`, 14.088s)
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=600s ./pkg/tests/issues` (PASS on `a6ee717132`, 68.325s)
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=2 -timeout=300s -run "^(TestIssue27666CDCWatermarkWriteSerializesWithDrop|TestCDCRaceTxn|TestCDCWaiterProbe)$" ./pkg/tests/issues` (PASS, 59.666s, before the final base-only rebase; the test change itself is identical)
- A fresh GitHub CI run was triggered for `012d0b7ad4`; results are pending.

### Residual risk

This changes test observation only; no CDC or lock-service production path changes. Darwin/x86 UT and configured disabled variants are skipped by the workflow.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
)

### Root cause

The regression scanned `IterLocks` across CNs. That observer enumerates only local lock tables, so it can miss a waiter when the task-table lock is represented by a remote or bound table. The holder transaction itself has the authoritative wait graph.

### Change

The two-CN regression obtains each executor CN lock service, captures both holder and contender transaction IDs immediately when `ExecTxn` enters its callback, and keeps the holder readiness barrier after its lock-producing statements. It queries `GetWaitingList` from the holder lock service, whose routed query reaches the authoritative owner, and accepts the observation only when the wait graph contains that exact contender ID.

The lock probe now uses a dedicated 30-second context and synchronous retry loop. Thus the budget bounds an in-flight remote query as well as the retry window; cleanup cannot overlap an orphaned observation goroutine. On failure it reports the last probe error and observed waiter IDs. The generic transaction helper API remains unchanged; transaction metadata is captured only for this lock-waiter scenario.

### Issue-to-test proof

`TestIssue27666CDCWatermarkWriteSerializesWithDrop` directly proves matrixorigin#28282: in both drop-first and writer-first orderings, it holds the task-row lock, observes the exact competing transaction in the holder wait graph, then proves that neither the CDC task nor either watermark row survives. `TestCDCWaiterProbe` proves the oracle rejects an unrelated waiter and that cancellation joins an in-flight probe. `TestCDCRaceTxn` retains coverage of readiness, cancellation, cleanup, and transaction errors.

A BVT is not appropriate for this test-only failure: reproducing it requires pinned uncommitted internal transactions and inspecting the private lock-service wait graph. The embedded two-CN unit test is the boundary that can deterministically assert that state while also exercising the public SQL effects.

### Tests run

- Rebased onto `origin/main` at `a6ee717132`; the last base increment changes ordered-upsert DML/compiler paths, so the focused two-CN regression and full owning package were rerun.
- `.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=240s -run "^(TestIssue27666CDCWatermarkWriteSerializesWithDrop|TestCDCRaceTxn|TestCDCWaiterProbe)$" ./pkg/tests/issues` (PASS on `a6ee717132`, 14.088s)
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=600s ./pkg/tests/issues` (PASS on `a6ee717132`, 68.325s)
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=2 -timeout=300s -run "^(TestIssue27666CDCWatermarkWriteSerializesWithDrop|TestCDCRaceTxn|TestCDCWaiterProbe)$" ./pkg/tests/issues` (PASS, 59.666s, before the final base-only rebase; the test change itself is identical)
- A fresh GitHub CI run was triggered for `012d0b7ad4`; results are pending.

### Residual risk

This changes test observation only; no CDC or lock-service production path changes. Darwin/x86 UT and configured disabled variants are skipped by the workflow.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
)

### Root cause

The regression scanned `IterLocks` across CNs. That observer enumerates only local lock tables, so it can miss a waiter when the task-table lock is represented by a remote or bound table. The holder transaction itself has the authoritative wait graph.

### Change

The two-CN regression obtains each executor CN lock service, captures both holder and contender transaction IDs immediately when `ExecTxn` enters its callback, and keeps the holder readiness barrier after its lock-producing statements. It queries `GetWaitingList` from the holder lock service, whose routed query reaches the authoritative owner, and accepts the observation only when the wait graph contains that exact contender ID.

The lock probe now uses a dedicated 30-second context and synchronous retry loop. Thus the budget bounds an in-flight remote query as well as the retry window; cleanup cannot overlap an orphaned observation goroutine. On failure it reports the last probe error and observed waiter IDs. The generic transaction helper API remains unchanged; transaction metadata is captured only for this lock-waiter scenario.

### Issue-to-test proof

`TestIssue27666CDCWatermarkWriteSerializesWithDrop` directly proves matrixorigin#28282: in both drop-first and writer-first orderings, it holds the task-row lock, observes the exact competing transaction in the holder wait graph, then proves that neither the CDC task nor either watermark row survives. `TestCDCWaiterProbe` proves the oracle rejects an unrelated waiter and that cancellation joins an in-flight probe. `TestCDCRaceTxn` retains coverage of readiness, cancellation, cleanup, and transaction errors.

A BVT is not appropriate for this test-only failure: reproducing it requires pinned uncommitted internal transactions and inspecting the private lock-service wait graph. The embedded two-CN unit test is the boundary that can deterministically assert that state while also exercising the public SQL effects.

### Tests run

- Rebased onto `origin/main` at `a6ee717132`; the last base increment changes ordered-upsert DML/compiler paths, so the focused two-CN regression and full owning package were rerun.
- `.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=240s -run "^(TestIssue27666CDCWatermarkWriteSerializesWithDrop|TestCDCRaceTxn|TestCDCWaiterProbe)$" ./pkg/tests/issues` (PASS on `a6ee717132`, 14.088s)
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=600s ./pkg/tests/issues` (PASS on `a6ee717132`, 68.325s)
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=2 -timeout=300s -run "^(TestIssue27666CDCWatermarkWriteSerializesWithDrop|TestCDCRaceTxn|TestCDCWaiterProbe)$" ./pkg/tests/issues` (PASS, 59.666s, before the final base-only rebase; the test change itself is identical)
- A fresh GitHub CI run was triggered for `012d0b7ad4`; results are pending.

### Residual risk

This changes test observation only; no CDC or lock-service production path changes. Darwin/x86 UT and configured disabled variants are skipped by the workflow.

Approved by: @XuPeng-SH

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/test-ci 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