Repository navigation
fix(cdc): replay deadlocked target transactions on 4.2-dev - #32232
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
针对 pkg/cdc/sinker_v2_executor.go:320(if !needRetry || e.tx != nil):事务内所有失败现在都走单次执行+整段回滚重放。1205 在标准 InnoDB 语义下只回滚当前语句、事务仍有效,1213/20701 才隐式回滚整个事务。若目标端锁等待高发,每次 1205 都整段回滚重放会放大重做工作量、拖慢水位推进。ClassifyRetryableError 已能区分 1205 与 1213/20701,建议仅对确实终止事务的错误码强制整段重放;1205 若目标端只回滚当前语句(需先确认 MO 目标端 1205 语义),可在事务完整时允许单语句重试。本操作由LW授权的MOI智能体提交 |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: e272ce87e7a8dd5282d948066732b20af27651fc
Assessment: approve
Typed classification and complete-range replay coherently reuse existing recovery mechanisms. Conservative 1205 replay is an acceptable tradeoff; no actionable defects remain.
Model: gpt-6.1-sol / max
Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0
Validation:
-
Reviewed the complete 12-file delta, all three discussion entries, linked issue #32214 and affected consumers.
-
Static source/evidence audit passed; source remained unchanged. Receipt: checks/1793881948552155054-2.json.
-
Isolation preflight passed. Local retry-package validation timed out during dependency downloads before tests executed; this was neither a pass nor a product failure.
-
Reused supplied current-head CI successes and attributed author normal/race, wire-driver and controlled real-MO rollback results.
Limitations:
-
No local product tests completed; raw author and CI runtime logs were unavailable.
-
DN-chaos/ownership-failover reproduction and mo-tester BVT were not performed. Existing permanent N: records require manual recovery.
jiangxinmeng1
left a comment
There was a problem hiding this comment.
P2: Some transient MO errors are still persisted as permanent during CDC pipeline admission.
ClassifyRetryableError extracts a native or MySQL-wire code, but its switch only includes the MO transaction codes. For example, a wrapped moerr.ErrRPCTimeout or a mysql.MySQLError with number moerr.ErrRPCTimeout (20500) falls through: morpc.GetStatusCategory only recognizes a direct *moerr.Error for this code, and neither fallback classifier handles the wire number. The result is (false, false). handleNewTablesForGeneration then writes IsRetryable: false / an N: diagnostic, so the next admission treats this transient setup failure as permanent.
Please include the MO transport/unavailable codes in the typed switch (as the main-branch classifier already does) and cover wrapped native errors plus both MySQL drivers. The 20701 deadlock path itself looks covered.
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: e272ce87e7a8dd5282d948066732b20af27651fc
Assessment: request_changes
The new discussion exposes an incomplete typed-classification path, so the prior approval needs revision. Existing transaction replay and the accepted 1205 policy remain valid.
Model: gpt-6.1-sol / max
Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0
- P2
pkg/cdc/error_handler.go:55: Pipeline admission receives a wrapped native ErrRPCTimeout (20500), or either supported MySQL error type carries that code.
Impact: These known transient representations return (false, false), while a direct native 20500 returns (true, true). Admission persists N:, so the next attempt fails the task and requires manual recovery instead of using the retry budget.
Evidence: The extracted code omits transport/unavailable cases in this switch. GetStatusCategory receives the original wrapper, and moerr.IsMoErrCode only recognizes a direct *moerr.Error; neither fallback classifier handles 20500. frontend/cdc_exector.go:2207 persists the false result, and GetTableErrMsg/ShouldRetry subsequently blocks admission. Apply the existing transport semantics to the extracted native/wire code and cover wrapped/both-driver admission cases. Baseline admission also used false: this is incomplete new representation-consistency behavior, not a demonstrated newly introduced regression.
Validation:
-
Compared authenticated review 5785019643 with the new discussion; assessed all six indexed items and linked issue #32214.
-
Traced classification through status/unwrapping, admission persistence and subsequent blocking, including the baseline control.
-
Follow-up source/evidence audit passed (checks/1793936749759981810-2.json; followup-audit.log). Reconciled prior same-head receipts and reused supplied CI/author evidence.
Limitations:
-
No new Go or MatrixOne execution. The prior local test attempt timed out during dependency downloads before tests ran; raw CI/author runtime logs were unavailable.
-
The finding is source-established; live transport-fault/DN-chaos reproduction and automatic recovery of existing N: records are not claimed.
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: f7364230dbc7f1714dda03a78bee923a5c77e9cd
Assessment: approve
The prior transport-admission finding is resolved. Typed classification and whole-range replay coherently reuse existing recovery mechanisms. Conservative 1205 replay remains acceptable; no actionable findings remain.
Model: gpt-6.1-sol / max
Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0
Validation:
-
Reviewed all 12 changed files, eight discussion entries and linked issue #32214; source remained unchanged.
-
Normal and race runs of CDC, retry and frontend packages each recorded 4,060 test/subtest passes and one skip.
-
Five focused regressions each passed 100 race repetitions using measured adaptive budgets.
-
Build, vet, isolation preflight and native provenance checks passed. validation-ledger.json matches commands, source fingerprints, exits and retained logs; final audit receipt: checks/1793953635355434125-2.json.
Limitations:
-
No new local embedded-MO or DN-chaos execution. Relevant author evidence was source-qualified; raw author and CI logs were unavailable.
-
Existing permanent N: diagnostics still require manual recovery.
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Related to #32214 ## What this PR does / why we need it: Main already preserves typed target errors, replays complete failed transactions, and exposes new target deadlocks as MySQL 1213/40001. However, the shared CDC classifier still misses native and legacy-wire MO deadlock code 20701. These errors can lose their driver identity, be persisted as non-retryable, and prevent automatic recovery. Add `ErrDeadLockDetected` to the existing transient classification. Extend existing tests for native/both drivers, wrapped/unwrapped errors, cause preservation, complete snapshot/incremental replay, and source/target admission through the owned diagnostic writer and subsequent catalog read. Cancellation and owner-loss precedence, permanent errors, and existing retry budgets remain unchanged. This is the minimal main counterpart to #32232, not a cherry-pick of the broader 4.2-dev repair. No wire mapping, catalog, ownership protocol, or transaction state-machine changes are included. Validation on Darwin/arm64 with Go 1.27.1: - The added scenarios fail against unmodified main; focused and CDC/frontend owning-package normal tests pass after the one-line fix. - Modified classifier statement coverage: 94.4%. Incremental golangci-lint 2.14.0 reports no issues. - CDC/frontend owning-package race tests pass. Complete-range replay, source-guard persistence/readmission, and target-setup admission each pass 100 focused race repetitions. Merged the latest main update (BETWEEN selectivity only) and reran both owning packages normally plus lint. Race and coverage evidence is reused for the unchanged CDC contract. No new cluster fixture or mo-tester BVT was added. Real DN chaos and historical `N:` task recovery remain outside this change. Approved-by: XuPeng-SH <[email protected]> Approved-by: jiangxinmeng1 <[email protected]>
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [x] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue #32157 (first batch only; keep the tracking issue open) ## What this PR does / why we need it: Backport six focused startup, RPC, and memory-lifetime fixes onto `4.2-dev@02fcfbc`. These old paths are still present on that release baseline. This is deliberately not a bulk backport of the tracking issue's 30 entries and is not release approval. | Source PR | Backported behavior | Failure/compatibility boundary | | --- | --- | --- | | #30761 | Hand off a first-catalog-replay disconnect to the existing reconnect owner; do not publish readiness while paused. | Before/during/after replay handoff, retry and cancellation, then actual SQL after recovery. No Main worker-lifecycle refactor. | | #29586 | Preserve live user-unary Futures during idle GC and atomically seal admission when truly idle. | Heartbeats do not keep idle connections alive; completed/canceled work can be reclaimed; saturated cleanup remains capacity-accounted. Retains the source PR's logical-row-count/NULL correction in `readSingleTaskRunner`. | | #29559 | Claim FIN in the existing stream entry without holding its mutex over synchronous send; release rejected responses once. | Writer exit, full queue, invalid/duplicate FIN and later requests; update the CN drop-release callback at the same ownership boundary. | | #30536 | Public session close disconnects transport; only the writer finalizer or failed-start path releases the writer's Goetty reference. | Active Encode/Flush, blocked socket output and failed writer startup; tested together with FIN. | | #28384 | Detach address-keyed ownership/profile state before off-heap realloc can recycle the old address; restore it if allocation fails. | No change to accounted allocation or allocate-copy-free ownership paths; allocator failure and address reuse are explicit oracles. | | #29352 | Drop a completed non-constant Scope's Reader reference after pipeline cleanup. | The existing TableScan/Pipeline owner still closes the Reader; no additional Close call; prepared reuse must rebuild/read correctly. | Each source retains an independent `cherry-pick -x` commit. Release-adaptation commit `72fb70919a9b98213af778cc7a4d6525e97dd7c4` uses 4.2's existing Future predicate and queue instrumentation rather than importing unrelated Main machinery. The real first-replay regression uses 4.2's existing `pkg/embed` cluster owner, with process-wide faults isolated in a dedicated test package, and also checks real MySQL prepared-statement reuse. ### Scope and design review - No wire, catalog or persisted-data format changes, new configuration, external dependency versions, SQL optimization rules, or background cleanup subsystem. - MORPC and mpool are shared code: their changes also affect other roles that use them, not only CN. Excluding TN storage/WAL changes is not a claim that TN executes no changed code. - Resource ownership remains with the existing Pipeline, RPC writer, client cleanup pool, allocator and connector. FIN adds one terminal bit to an existing live stream entry; replay adds one notification channel per connector, not a second recovery state machine. - Idle GC scans existing Futures only after the idle-age check; it does not add per-request bookkeeping. The other changes replace cleanup ordering or remove references. No throughput improvement or zero-regression guarantee is claimed. - Q1: response/Future/transport/Reader cleanup owners checked, including rejected admission and failed startup. Q2: FIN no longer holds the receive-state lock over send completion; disconnect interrupts socket I/O; first replay wakes the existing reconnect path. Q3: no new growing registry or queue; bounded backend cleanup is retained. ### Deliberately not included - #29725: 4.2 already enters allocator recovery on Unlock errors; Main's bypass guard is absent. Do not label this as the same confirmed release-branch Unlock leak. - #29448, the NULL-completeness subset of #29558, and #28693 remain follow-up candidates with separate authentication/planner/transaction-helper validation; absence here does not mean they are unimportant. - The TN/WAL, mixed-lock, HNSW and ISCP task-lifecycle changes need dedicated adaptation and upgrade/recovery coverage. CDC already has #32232; do not duplicate it. No rollback/upgrade of any running cluster is part of this PR. ### Tested with Original backport validation: `72fb70919a9b98213af778cc7a4d6525e97dd7c4`. Local runs used Go 1.26.4, Darwin arm64, native libraries built from this release tree, `GOMAXPROCS=2`, `-p=1` and normally `GOMEMLIMIT=2GiB`. Earlier pre-commit runs retain their working-tree identity; their relevant source content matches that original validation commit. No historical Main test result is presented as a test of this backport. | Evidence | Result | | --- | --- | | MORPC, mpool, ISCP, compile and disttae owning packages | Normal and race PASS. | | CN owning package | Normal and race PASS with the environment-sensitive scalar memory-limit test split as described below; all tests in that partition covered. | | New real embed regression | Normal and race PASS: inject disconnect during first catalog replay, recover startup, observe a fresh TN timestamp, and execute one actual MySQL prepared statement twice with results `[1,2]`, then `[2]`. The dedicated test package isolates faults from the shared embed cluster. | | Existing `TestSingleCNCluster` | Race PASS. | | Linux amd64 on server 50 | Both Linux-only realloc tests PASS in normal/race; full mpool (71 top-level tests) and MORPC (315 top-level tests) normal/race PASS. | | Matched Linux baseline controls | Clean `02fcfbc898` plus only regression probes reproduces three real failures: stale metadata at allocator-cache publication, queued-FIN close deadlock, and buffers freed during active Encode. Candidate passes the same oracles. The baseline physical-allocation-failure test already passes and is retained as compatibility coverage, not claimed as a new failing counterexample. | Linux used existing immutable build image `sha256:44069beb9d61e8d1d6766f1d214eb94843257616bc8c9291ee53fae1edbbd7fa`, fresh candidate/base native builds and separate source/cache directories. Containers had 2 CPUs, 4 GiB memory+swap limit, 512 PIDs and no network. Existing services on 50 were not changed. The first capped full CN runs failed `Test_service_handleGoMemLimit/set_4Gi`: that test assumes the initial Go memory limit is `MaxInt64`, but the explicit test environment supplied 2 GiB. The exact capped case on clean baseline `02fcfbc898` fails with the same expected-MaxInt64/actual-2147483648 signature. We did not weaken its assertion or change product code. The package is run with that one case excluded under the cap, and the exact scalar-only case is separately run in normal/race with `GOMEMLIMIT` unset. Original failed receipts remain failed. Stress: 21 individually selected MORPC/mpool/compile/disttae cases passed independent `-race -count=100` runs on Darwin. The isolated embed recovery case passed its proportional repeat (`T=17.25s`, `B=30s`, `N=1`). Linux cache-publication retirement passed `-race -count=100`; physical allocation failure passed `-race -count=29` (`T=1.03s`, `B=30s`). Selections are non-empty and recorded by individual test name. Commands use the repository CGo wrapper, with serial package builds: ```sh GOMAXPROCS=2 GOMEMLIMIT=2GiB .agents/skills/mo-dev/scripts/mo-cgo-test -p=1 -count=1 -timeout=240s ./pkg/common/morpc ./pkg/common/mpool ./pkg/iscp ./pkg/sql/compile ./pkg/vm/engine/disttae GOMAXPROCS=2 GOMEMLIMIT=2GiB .agents/skills/mo-dev/scripts/mo-cgo-test -p=1 -race -count=1 -timeout=240s ./pkg/common/morpc ./pkg/common/mpool ./pkg/iscp ./pkg/sql/compile ./pkg/vm/engine/disttae # CN package: normal/race separately, then the one default-limit oracle separately. GOMAXPROCS=2 GOMEMLIMIT=2GiB .agents/skills/mo-dev/scripts/mo-cgo-test -p=1 -count=1 -skip '^Test_service_handleGoMemLimit$' ./pkg/cnservice env -u GOMEMLIMIT GOMAXPROCS=2 .agents/skills/mo-dev/scripts/mo-cgo-test -p=1 -count=1 -run '^Test_service_handleGoMemLimit$' ./pkg/cnservice # Also repeated with -race; each stress command selects exactly one test. # Original test path at 72fb; the follow-up moves it to ./pkg/embed/firstreplay. GOMAXPROCS=2 GOMEMLIMIT=2GiB .agents/skills/mo-dev/scripts/mo-cgo-test -p=1 -race -count=1 -timeout=240s -run '^TestCNFirstReplayDisconnect$' ./pkg/embed ``` `go vet` passed for all seven affected production/test packages; `git diff --check` passed. Incremental golangci-lint was **not validated**: locally installed versions are incompatible with the repository's v2 config/Go 1.26 toolchain. No lint configuration or dependencies were changed to bypass this limitation. No full BVT, production workload benchmark or rolling-upgrade qualification is claimed; PR CI and release qualification remain separate. ### Incidental bug findings `pkg/tests/service.buildCNConfig` on the target baseline validates a newly generated CN UUID before registering its service runtime, causing a nil-runtime panic before the cluster starts. This is already addressed upstream by #30380 (`0723ae37b1`); disposition: **Duplicate / not included**. The new regression uses the existing embed fixture, which already registers the runtime and catalog definitions. It does not patch or claim validation of the legacy service fixture, and does not pull in the broader CN-drain changes from #30380. Ordinary off-heap profiling has a separate pre-existing enable/allocate/disable/free boundary: the pool returns to zero but the profile pointer/in-use sample remains recorded. An isolated baseline probe reproduced it; disposition: **Created #32334 / not included**. This is diagnostic metadata retention, not a demonstrated native-buffer leak or customer OOM, and does not change this batch's scope or review conclusion. ### CI test follow-up Follow-up commit: `6404268dae8b5d78a12fb0459b67991c8893a9cd`. After the 4.2-dev merge, [UT](https://github.com/matrixorigin/matrixone/actions/runs/42341756945/job/128310805969) and [coverage](https://github.com/matrixorigin/matrixone/actions/runs/42341756945/job/128310839394) exposed a process-admission deadlock in `TestCNFirstReplayDisconnect`: the shared embed fixture held the runner-wide lock while its test process waited for a child that needed the same lock. Move the existing recovery test into its own test package, remove the recursive subprocess, and acquire the existing process admission before starting replay deadlines. Fault injection remains process-isolated, and the real fresh-TN-timestamp and two prepared-execution result oracles are retained. The coverage run also failed an existing dropped-user authorization assertion across two CNs. The reader uses its locally applied statement snapshot, so the test now fences the committed DROP and verifies through independent CN1 SQL that the user is absent before checking that the already-authenticated session is denied. This establishes denial after visibility; it does not claim instantaneous cross-CN revocation or prove the precise cause of that CI failure. The unmodified 4.2-dev baseline passed three normal repetitions. Follow-up validation on Linux/amd64, Go 1.26.4, matching branch-local native libraries: - The original full-order reproduction fails on `6c7dca5d` after the shared cluster starts; the independent test passes with the same lock held by another process for over 40 seconds, then released, including under `-race`. A separate cancellation control confirms admission times out before faults or a cluster start. - Complete `pkg/embed` and `pkg/embed/firstreplay` suites run together with `-p=2`: PASS (230.547s and 17.923s). Existing process-admission exclusivity, reentrancy and cancellation tests also pass under `-race`. - Full `TestIssue29399AuthorizationScopeAndRevokedRole`: three normal repetitions and one `-race` run pass, including the CN1 public-SQL visibility and retained-session denial checks. - Scoped CI-style `-tags matrixone_test -short -covermode=set` execution of both scenarios passes with cnservice, MORPC, mpool, ISCP, compile, disttae and frontend instrumented. This is not the full CI coverage producer. - Incremental gofmt and `go vet` pass for the affected packages; repository-configured golangci-lint 2.6.2 built with Go 1.26.4 reports 0 issues for the follow-up diff. The original backport diff passed arm64 SCA on `6c7dca5d`. - Independent design: `gpt-6.1-terra/max`. Independent overall review: `gpt-6.1-sol/max`, no material code blocker; final evidence reconciled before delivery. The follow-up changes only tests; it adds no production hot-path work. Full post-push CI and release/upgrade qualification are separate and are not claimed as passed here. --------- Co-authored-by: XuPeng-SH <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #32214
What this PR does / why we need it:
CDC classified a target-side MO deadlock (20701) as permanent on its first attempt, persisted an
N:diagnostic, and stopped the task.Validation on Darwin/arm64 with Go 1.26.4:
4.2-devat02fcfbc898; CDC/retry/frontend normal suites passed 4060 tests/subtests. The expanded admission regression passed race validation and 100 repetitions. It verifies persistedR:and readmission, conversion toN:on retry exhaustion, and permanent-error controls.Limits: this does not repair duplicate-CN ownership or automatically clear existing
N:records. Real DN-kill/ownership-failover reproduction and mo-tester BVT were not run.