Skip to content

fix(cdc): replay failed target transactions and preserve error accounting - #29801

Merged
XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-29434-cdc-setup-retry
Oct 9, 2026
Merged

XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-29434-cdc-setup-retry

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Oct 9, 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 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 while sql.Tx remains 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 ExecContext execution 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 invoked ExecContext counts 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:

  • Both drivers, snapshot/incremental writes, 1213 and both 1205 rollback semantics: one failed B execution, no partial commit or checkpoint advance, retained rows, then successful complete replay.
  • Real frontend factory/owned diagnostic/next callback: failures occur at target SQL after connection establishment; R:1 through R:3 then permanent exhaustion, permanent errors, canceled/stale callbacks, and ambiguous lock-release disposal.
  • One existing public single-CN fixture with the production connector: transient setup recovery, permanent setup rejection, real target ROLLBACK at the INSERT of a primary-key update, retained target rows before recovery, first replay from the failed range start, durable progress bounded by that start while recovery is blocked, and durable progress covering the range end after recovery.
  • Counter deltas for transaction/single/standalone execution, zero/one/two failed attempts, success and pre-dispatch rejection, using existing lightweight sqlmock and Counter helpers.

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:

  • Exact public integration test: normal mode; coverage mode with CI -short -tags matrixone_test -covermode=set, scoped instrumentation across the four affected packages.
  • All four owning packages passed -race -count=1: pkg/cdc/retry (1.015s), pkg/cdc (9.871s), pkg/frontend (32.968s), and pkg/embed (448.197s). Frontend uses an NVMe temporary directory with adequate spill headroom (TMPDIR and Go 1.27 GOTMPDIR); this resolves local cap=1 admission failures without changing code.
  • Negative challenge: restoring old transaction statement retry through an external Go overlay makes the same public test fail. Mutation is excluded from the branch.
  • Complete-diff incremental golangci-lint, go vet, pinned molint, gofmt, diff check, and repository err-check. Molint reports pre-existing findings only in files byte-identical to the merge base.
  • Required gpt-6.1-sol / xhigh design 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.

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

Choose a reason for hiding this comment

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

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.

@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Oct 9, 2026
@XuPeng-SH XuPeng-SH changed the title fix(cdc): recognize production MySQL errors in retry classification fix(cdc): replay failed target transactions and preserve error accounting Oct 9, 2026

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

Reviewed commit 4e8e708. No actionable findings; the failed-execution counter is recorded once at the shared ExecContext boundary, with transactional, retry, and pre-dispatch cases covered.

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.

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

@XuPeng-SH
XuPeng-SH merged commit a6e19cc into matrixorigin:main Oct 9, 2026
@XuPeng-SH
XuPeng-SH deleted the codex/fix-29434-cdc-setup-retry branch October 9, 2026 19:46

This branch was previously deployed

1 inactive deployment
ci — d21e2bf9 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 size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: CDC persists transient target setup/release failures as permanent table errors

2 participants