Skip to content

perf(optools): bound race UT critical path safely - #29760

Merged
XuPeng-SH merged 9 commits into
mainfrom
test/race-ut-critical-path
Oct 9, 2026
Merged

XuPeng-SH merged 9 commits into
mainfrom
test/race-ut-critical-path

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • Improvement
  • Test and CI

Which issue(s) this PR fixes:

Related #29562
Fixes #29752

What this PR does / why we need it:

Reduce retained race UT work and scheduling copies while preserving runnable coverage, failure diagnostics and CDC replay correctness.

  • Build the issues binary once and execute exact Test/Fuzz/Example roots in four fresh serial processes. Preserve subtests, seeds and internal stress; share one execution deadline and never replay completed roots after runtime failure.
  • Reuse one prebuilt executor for serial embedded packages and the existing engine wave. Bound process-group termination and transfer one complete/recoverable JSON report representation.
  • Retain exclusive cluster admission, intentional same-process borrowing and retryable final release. Remove unused concurrency slots and unreachable acquisition cleanup.
  • Keep CDC batch scratch exclusively queue-worker owned. Preserve ACK versus delayed legacy read/insert/fallback publication.
  • Make fresh typed CDC reads and owner claims authoritative. A remote takeover can make guarded checkpoint SQL return success without advancing durable progress; its optimistic cache must not become a replay boundary. Detect overlapping ACK/owner changes using transient outstanding-read observations, discard stale results and allow at most one SELECT reread under the original deadline. Claim UPDATE is not repeated. Retirement/eviction detach observations, deletion blocks publication, and final-reader release checks identity before removing an entry.
  • Project HAKeeper scheduling snapshots without display configuration while retaining WAL recovery status and complete public queries. Cancel/join the engine fixture notifier before dependent cleanup and remove overwritten fileservice setup.

Design: pr29760-design-v4, bounded execution at existing owners. It replaces v2's invalid assumption that generation/timestamp comparison proves a cached checkpoint durable. No API, catalog, persisted-format or dependency change.

Performance and complexity

Prior author measurements for issues-only serial batching: wall 515.1 → 407.8 s, CPU 792.2 → 512.7 s, sampled peak RSS 3.42 → 2.26 GiB. Prior paired scheduling-copy measurement with two CNs/3,770 config items: full 251,021 ns / 561,424 B / 3,893 allocations; projection 8,095 ns / 9,848 B / 107 allocations. These are package/copy measurements, not a whole-job or TP-throughput claim.

CDC normal reads and claims retain their existing SQL count; checkpoint flush adds no SELECT. Only an overlapping publication causes one extra SELECT. Tracking stores no progress tuple or idle-key history and is bounded by outstanding calls. SQL and fence callbacks remain outside the updater mutex.

Validation

Final revision e855f9f991649077eca1330bef5a89cda02a3c6a, including the CDC retirement-state cleanup, merge base b6fa8cc; Go 1.27.1, darwin/arm64 CPU, fresh native build with verified provenance, repository CGo runner, count=1 for normal/race. Selections are named and non-empty.

  • Deterministic guarded-SQL A/B reproduced the regression: durable 100/local optimistic 200; both typed read and replacement claim returned 200 before the repair and 100 with the baseline. Fixed tests assert returned and installed 100, including after claim-loss eviction.

  • Complete CDC owning package: PASS normal 8.938 s / race 10.494 s, 474 roots, no failures/skips. Prior repair evidence for five exact concurrency roots individually repeated 100 times under race: PASS; retained as historical stress evidence. The representation cleanup refreshes complete owning-package normal/race. Covers lower-timestamp/new-generation ACK, ACK followed by guarded no-op, owner replacement, retirement/reuse, observation-only eviction, deletion, cancellation, unrelated-key publication and bounded repeated conflict.

  • Two-barrier retirement/reuse proves the old reader's release preserves an outstanding replacement observation. Original legacy ACK and scratch controls remain green.

  • Semantically unchanged consumer evidence reused: six frontend admission/recovery controls: PASS normal/race. Real TestCDCGenerationReplacementOnMO: PASS normal 129.871 s / race 123.802 s.

  • Full HAKeeper and protobuf owning packages: PASS normal/race. LogService: 16 focused normal roots and complete 361-root owning package race PASS. Three directly affected engine fixture consumers PASS normal/race.

  • Unchanged exact-head optools and cluster-admission complete race, plus a real four-process batch probe: retained PASS evidence. Original-head Linux UT, coverage, configured SCA and compose BVT completed successfully; this evidence applies to unchanged closures, not the new CDC repair.

  • Complete delivery diff's 10-package incremental closure: formatting, vet, pinned molint and configured golangci-lint 2.14.0 PASS. CDC static checks refreshed after final retirement-state cleanup; lint 0 issues. Existing off-diff molint diagnostics are unchanged. git diff --check clean.

  • Prior CDC repair gpt-6.1-sol / xhigh design session 01a11f9f-c469-7a63-be78-f3b489af1d8e and overall review/reconciliation session 01a11fda-1171-74b3-9124-c2b3ba3a5f4a: PASS, no unresolved material blockers. The review's optional identity-release test suggestion was implemented and revalidated.

  • Retirement-state cleanup removes the redundant retired flag and retirement-only revision increment; map identity already rejects detached readers. Admission/refcounts, ACK invalidation, SQL counts and errors are preserved. No new tests or abstractions. Actual gpt-6.1-sol / xhigh v4 design session 01a11ffd-0e30-7023-a940-fd129e8bd155 and final overall reconciliation session 01a12004-4d73-7763-b900-dc27c763635b: PASS.

Records: ~/.codex/issue-to-pr/matrixone/pr29760-cdc-takeover/ (design, overall review, final source fingerprint, complete scope and terminal validation logs).

CI triggered by the repair commit is separate and remains pending. The deterministic probe proves a component regression; it does not claim a reproduced live data-loss incident. Whole-job performance remains unmeasured.

@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

Copy link
Copy Markdown
Contributor Author

Request changes: close the design contract before approval

This change materially changes the race-UT execution and ownership model: it batches roots under a shared deadline, adds cancellation/report handoff paths, and introduces opt-in cross-process cluster admission with two slots. Please link the exact reviewed design revision and record its approval before implementation approval.

There is also a direct mismatch with the existing design contract: docs/design/ut-race-owner-costs.md says scheduling/recovery reads retain full snapshots, while this PR adds a scheduling projection in pkg/hakeeper/rsm.go. Update the versioned design to define the projection's owner/consumer contract and validation, and cover the new runner/admission lifecycle: cancellation, failed drain, cleanup ownership, compatibility, and the measured benefit/cost of enabling the two-participant mode.

Local checks completed: optools -race and clusteradmission -race pass; optools go vet passes. The CDC race test could not start because this review worktree lacks a matching CGo library. I found no confirmed runtime regression in the source paths reviewed. The request is for the missing design approval and the unresolved design/implementation mismatch.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Resolved the previous P2 design-contract review finding and simplified the implementation.

  • Added reviewed design revision pr29760-design-v1, reconciled the old full-scheduling-snapshot promise with the actual projection/WAL contract.
  • Removed optional embedded cross-process parallelism, participant modes/slots and concurrency overrides. The existing exclusive lifecycle owner and cleanup-only lease/caller retention remain. This correction deletes 85 net implementation/infrastructure lines and 64 test lines; documentation adds 124.
  • Complete affected-package configured vet/lint PASS. Owning normal and race UT PASS; affected embed/service lifecycle and real CDC generation replacement race PASS. Logservice ran in an isolated network namespace to avoid the host's occupied 9001 port.
  • Independent QA: 18 measured exact concurrency roots, 1,163 bounded race repetitions PASS, including engine report-open failure with earlier children and successful joined reports.
  • Design and final overall review explicitly use separate gpt-6.1-sol / xhigh sessions. Final overall review PASS, zero material blockers, candidate tree 06ceb6a7d08b340ec56615afadbf5a994a3d79c9. Delivered commit 817a2e053e4e89dda4a61af0ebd7801818e5008e; immutable approved design.

Issues batching savings remain historical scoped measurements; the current paired scheduling-copy benchmark confirms reduced copy work. Neither is a claim that the entire CI job has reached 600 seconds. No merge or CI rerun is requested by this update.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep review of e855f9f991649077eca1330bef5a89cda02a3c6a: no unresolved material blockers; recommend approval on code/design grounds.

All actionable existing comments are resolved. The CDC durable-progress regression and redundant retirement state are closed. The implementation uses the existing updater, executor and cleanup owners: map identity is the sole retirement state, ACK/owner changes retain revision invalidation, and delayed readers cannot republish retired results or remove replacement observations. SQL remains outside the updater mutex; rereads are bounded by one additional SELECT and the original deadline. Tracking follows outstanding reads rather than retaining idle-key history.

Reviewed implementation, tests and documentation separately. Existing tests use durable-result/error oracles and explicit interleaving barriers, including two-reader retirement/reuse, observation-only eviction, cancellation, backend failure and repeated conflicts. Design v4 matches the implementation. The unchanged runner, projection/WAL, admission and engine-fixture closures retain the previous complete review and valid evidence.

Verified the committed full-diff fingerprint against validation: CDC owning package 474 root tests PASS in each mode, normal 8.938s and race 10.494s, count=1, no failures/skips. Configured incremental static checks pass; lint reports zero issues. No redundant test rerun was needed for this review.

This recommendation does not certify full current-head CI. The whole-job 600-second performance goal remains unproven; historical batching/copy measurements support only their measured scope.

This branch had an error being deployed

1 failed deployment
ci — 5acf4948 Deployed Oct 9, 2026 by XuPeng-SH
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 kind/enhancement kind/test-ci size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: CDC target acknowledgement races with batch watermark scratch cleanup

2 participants