Repository navigation
fix(cdc): replay failed target transactions and preserve error accounting - #29801
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Review of ee1035fc72dd2575946b4c7cbad761615c583833 against merge-base d2a0055ebe1a0b2423368e046c1812c18f6face8 (fresh main 72d4a49db7d750520e1a1654cb6091fc7169882b). No blocking finding in this change. This is a self-authored PR, so this records a COMMENT, not independent approval. No subagent was used.
Design and responsibility. Read all six changed files/hunks and traced production target connection creation, target-identity wrapping, frontend pipeline admission, the owned diagnostic writer and the next callback, running-stream classification, and the executor's retry-policy consumer. The concrete production driver differs from the upstream driver; extracting both codes in the existing retry package closes that gap without another retry state machine, persistence format, worker or execution path. This is an ordinary bug fix, exempt from the large-feature design-document gate. The new helper has two real policy consumers; no unused abstraction was introduced.
Failure and control paths. Native MO errors retain precedence; cancellation and ownership loss are checked before backend classification. As an adjacent challenge, a production transient error combined with cancellation/ownership loss still terminates at those guards, and a native permanent control error combined with a production transient code still terminates at the native-code switch. A live-parent deadline combined with discarded-connection cleanup remains retryable; standalone ErrConnDone remains unclassified. The frontend checks parent cancellation and callback generation before reporting, and passes the captured owner fence to the existing writer. That writer advances R:1/R:2/R:3 to permanent exhaustion at attempt 4; the following callback prevents another target open. Runtime-only legacy fallback remains at its existing owner. The separate executor retry consumer still uses existing attempt/duration/circuit bounds and cancellable backoff.
The release test exercises the actual executor: a RELEASE_LOCK deadline discards the pinned physical connection before pool shutdown, preserves both error causes, clears executor ownership, and checks zero open connections. No new resource owner or wait is added by production code. The embedded fixture restores the global connection function only after cluster shutdown; CREATE CDC's two synchronous connection checks precede publication of background work.
Tests, evidence and performance. Implementation is +18/-7 across two files; tests are +217/-6 across four; no documentation files change. These are useful separate oracles: transport equivalence/permanent controls, physical-session disposal, real factory/callback/writer/exhaustion behavior, and public SQL/catalog visibility. The tests reuse existing fixtures; the frontend catalog extension now models owner-fenced diagnostic writes rather than asserting only a fake classifier result.
Reused the author's current-head owning-package and focused race evidence after checking the test selection and semantics. Also checked successful exact-head CI run 37945498551, including its race-UT execution log: TestCDCTargetSetupTransientDiagnosticOnMO actually passed in 46.44 seconds, and the embedded package completed successfully. The public test injects the production driver's error into the dependency; it is not a physical external-MySQL network reproduction. No additional local test run or throughput benchmark is claimed in this review.
Additional errors.As work is confined to classification of failures; the normal successful TP SQL path gains no new allocation, synchronization or I/O from this diff. Recovery now incurs the intended existing bounded retry work. This is source-level impact analysis, not a measured TP throughput claim.
Comments and scope. There were no prior submitted reviews or inline comments on this PR at the audited snapshot. Issue #29434's original joined deadline/closed-connection handling already exists in the base; this PR closes the remaining production-driver classification gap and strengthens its actual admission/cleanup coverage. Previously persisted permanent diagnostics are not automatically rewritten, as documented in the PR description.
Account failed ExecContext calls in the common executor closure so active transactions and single-attempt setup SQL remain visible to CDC monitoring. Remove retry-loop accounting to avoid double counting standalone retries. Extend existing SQL, control and circuit tests with counter deltas and register transaction rollback before assertions so regression failures also clean up.
4e8e708 to
7647b8d
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review completed for 7647b8d26fe49b19881ac831108e18f49f10b192. I found no blocking correctness or design issues.
The retry classifier reuses the existing retry package, and transactional execution hands failures back to the existing sinker, transaction manager, and stream recovery path. A failed statement cannot be retried in isolation while its transaction remains active, so later commit and watermark publication are suppressed; the unacknowledged range is replayed through the existing reader. This avoids a second retry state machine.
The added production code is small and focused (4 files, +60/-33). The larger test delta (5 files, +850/-6) covers both driver error types, statement-only versus whole-transaction rollback, snapshot and incremental writes, retry admission/diagnostics, metrics, and replay on the existing public fixture. The legacy statement-retry negative control fails at the replay-range assertion, showing that the integration oracle detects the original data-loss mode. The fixture cleanup correction also closes the previously identified assertion-failure teardown issue.
Local evidence on this revision: all four affected packages passed race validation; the CI coverage-mode public integration test passed; the negative control failed as expected; incremental lint and static checks found no new issues. The main operational tradeoff is additional reread work when a transaction must be replayed. Successful SQL execution adds no extra database round trip.
The current remote CI run is still in progress, so this review does not claim that the published revision is fully green. The public fixture models whole-transaction rollback on a real MatrixOne target; native external InnoDB and physical network-fault behavior were not tested.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #29434
What this PR does / why we need it:
CDC target connections use
matrixorigin/mysql, but retry classification recognized only the upstream driver's error type. Transient target SQL failures could therefore become permanent diagnostics. Recognizing production error 1213 also exposes unsafe statement retry: the target may roll back the entire transaction whilesql.Txremains usable. Retrying only B after A succeeded can commit incomplete data and advance the checkpoint.This change extracts error numbers from both drivers in the existing retry package and preserves classified backend/control causes through the sinker. Active-transaction statements execute once; their original error reaches the existing sticky error gate, transaction cleanup and stream recovery. Failed attempts cannot commit or acknowledge a checkpoint, and the existing stream recovery replays the unacknowledged range from retained reader progress. Target success precedes buffered watermark advancement; catalog persistence remains asynchronous. Cancellation, ownership loss and permanent errors retain their existing policy; target setup still uses the existing bounded admission budget.
MySQL sink errors are counted at the common
ExecContextexecution boundary, once per failed invocation. Transactional and no-retry SQL failures remain visible in the existing Grafana series. Standalone retry cannot double count; success, validation, stop checks and circuit rejection before dispatch count zero. A cancellation returned by an invokedExecContextcounts as an execution error. Statement retry counters retain their separate meaning.No new retry layer, transaction state, persistence, worker, wire format or configuration is introduced. Existing explicitly retry-safe standalone behavior is preserved. Transactional recovery uses complete replay rather than statement attempt/duration limits; default statement-only 1205 timeouts can therefore require more reread work. Successful SQL adds no metric work, and failed SQL uses the existing fixed-label counter.
Regression coverage reuses existing fixtures:
R:1throughR:3then permanent exhaustion, permanent errors, canceled/stale callbacks, and ambiguous lock-release disposal.The integration oracle follows the existing cached/durable watermark contract: SQL catalog progress may lag the live reader cursor or flush earlier successful rounds during blocked recovery. It captures the actual failed collection range and checks first replay against that range, rather than equating a sampled catalog value with the reader cursor. This removes the coverage-mode timing failure without forced persistence, sleeps, or new production retry paths. Only the first replay observation is retained. Fixture globals are restored after shared-cluster shutdown, including assertion failures.
Validation on Linux amd64 / Go 1.27.1 with freshly built matching repository CGo artifacts:
-short -tags matrixone_test -covermode=set, scoped instrumentation across the four affected packages.-race -count=1:pkg/cdc/retry(1.015s),pkg/cdc(9.871s),pkg/frontend(32.968s), andpkg/embed(448.197s). Frontend uses an NVMe temporary directory with adequate spill headroom (TMPDIRand Go 1.27GOTMPDIR); this resolves localcap=1admission failures without changing code.gpt-6.1-sol/xhighdesign and overall review, with revision and execution evidence recorded outside source.The public fixture models InnoDB transaction-abort semantics on a real MO target; native external InnoDB and physical network timeouts are not claimed. Previously persisted permanent diagnostics or lost data are not repaired automatically. Existing ambiguous-COMMIT/idempotency contracts are unchanged. CI for the published revision remains pending.