Skip to content

fix(proxy): preserve LAST_INSERT_ID across connection migration - #29192

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
Lundomn:fix/issue-29184-last-insert-id
Sep 22, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
Lundomn:fix/issue-29184-last-insert-id

Conversation

@Lundomn

@Lundomn Lundomn commented Sep 21, 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 #29184

What this PR does / why we need it:

After inserting an auto-increment row, a JDBC connection could observe LAST_INSERT_ID() = 0 when Proxy migrated it away from a draining CN. Preserve the session value through the migration snapshot and restore it in both Session and Process after statement replay, so the original connection retains its last generated ID.

  • Carry the value with an export marker that distinguishes an authoritative zero from a legacy source that omitted the field.
  • Require the Proxy capability at the source; reject a missing export marker before consuming one-shot migration admission or replaying target state.
  • Require protocol v93 for a nonzero value on the target. An explicitly exported zero retains the legacy-target behavior. Main's v92 scalar HLL contract is preserved.
  • Add a real two-CN + Proxy Connector/J regression with both useServerPrepStmts=false and true. It retains the same JDBC connection and prepared statements, confirms source/target CN IDs during drain, verifies LAST_INSERT_ID() through both direct SQL and a retained prepared query after handoff through a retry interval, and checks that another insert updates the value.
  • Assert the actual Connector/J prepared-statement class and disable server-prepared fallback. Bound connection, socket, query, test, and cleanup durations; preserve a primary test failure if database cleanup also fails.

Validation

Rebased onto 3727c5c5436ca136d7b0312f75bc223a11692a85.
Final validated revision: 7f0e9fb0100029eef22da9e8bf70804fe5710523.

Two-CN + Proxy JDBC regression

The corrected test passed twice on the same isolated native topology. Each run executed both modes: 2 tests, 0 failures, 0 errors, 0 skipped, with BUILD SUCCESS. Class elapsed times were 20.88 s and 29.83 s. After each run, both CNs were verified Working with no test databases remaining. The second run validates that teardown permits reuse, not just a fresh-cluster success.

The native service was rebuilt at cfaefd92dcdaa6d1a49b60dc150d2c760e2ae228; executable SHA-256: 0678a85d7fbf9ab8a77a37f06a22a2e7475293bb2f3b9330c54e6108c3437669. The later review correction changes only the Java test, leaving Go/native build inputs identical. The native build and Go race results are reused on that source-equivalence basis, not represented as newly executed CI.

The isolated local topology uses one LogService, one TN, two CNs, and Proxy. From xtool/jstfu, with the topology running:

MO_PROXY_TEMP_TABLE_E2E_URL='jdbc:mysql://127.0.0.1:6009/?user=root&password=111' \
MO_PROXY_TEMP_TABLE_E2E_CN1='dd1dccb4-4d3c-41f8-b482-5251dc7a41bf' \
MO_PROXY_TEMP_TABLE_E2E_CN2='dd2dccb4-4d3c-41f8-b482-5251dc7a41be' \
./mvnw -Dtest=ProxyLastInsertIdMigrationE2ETest test

Adaptive race stress

On macOS arm64 with CGO enabled, each test below was selected individually. Measure once with:

.agents/skills/mo-dev/scripts/mo-cgo-test -json -race -count=1 -timeout=120s -run '^TEST$' ./pkg/PACKAGE

T is the terminal test-event duration, excluding compilation/package startup. Repetition count is clamp(floor(30s/T),1,100); a completed measurement rounded to zero uses the cap of 100. Repeat the same exact selector separately in one process with -count=N and otherwise identical flags.

Package Exact test Measured T N Result
proxy TestMigrateConnToUsesTransferDeadline 0.04 s 100 PASS
proxy TestMigrateConnToPropagatesCancellation 0.02 s 100 PASS
proxy TestMigrateConnToContextCancelsReplay <0.01 s (JSON 0) 100 PASS
frontend TestCanceledMigrationAdmissionDoesNotConsumeMigrateOnce <0.01 s (JSON 0) 100 PASS
frontend TestMigrateConnectionFromRejectsClosedRoutineBeforeReadingSession <0.01 s (JSON 0) 100 PASS
frontend TestRoutineCleanupCancelsRequestBeforeWaitingForLifecycleOperation <0.01 s (JSON 0) 100 PASS
frontend TestRoutineManagerClosedCancelsActiveLifecycleOperation <0.01 s (JSON 0) 100 PASS

Every stress command exited 0; no race report occurred. Each of the four frontend runs also emitted exactly 100 passing terminal test events.

Affected packages

.agents/skills/mo-dev/scripts/mo-cgo-test -json -race -count=1 -timeout=240s ./pkg/proxy
.agents/skills/mo-dev/scripts/mo-cgo-test -json -race -count=1 -timeout=240s ./pkg/frontend

Both passed: Proxy 25.075 s, Frontend 48.036 s. These cover the v92 legacy-target rejection boundary, missing capability/marker handling, state restoration, cancellation, and lifecycle tests. These commands ran on cfaefd92d; the only change from that revision to the final head is the Java regression correction described above. gofmt -l on changed Go files was empty, git diff --check origin/main...HEAD passed, and the rebase range-diff was inspected.

Compatibility and remaining risk

Migration fails closed when a participating updated source or Proxy cannot prove that the value was exported. An entirely legacy Source/Proxy/Target path retains its existing behavior. The change adds bounded scalar fields and admission checks to migration; ordinary query execution is unchanged.

Shared build, general BVT, coverage, and Connector/J pool-reset CI passed on the previous published head. They have not yet run on the updated head; CI results after this push remain pending. The local JDBC regression is separate from pool-reset CI and requires the environment variables above to execute rather than skip.

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

@mergify mergify Bot added the kind/bug Something isn't working label Sep 21, 2026
@matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] lines label Sep 21, 2026
@Lundomn
Lundomn marked this pull request as draft September 21, 2026 07:10
@matrix-meow matrix-meow added size/M Denotes a PR that changes [100,499] lines and removed size/S Denotes a PR that changes [10,99] lines labels Sep 21, 2026
@Lundomn
Lundomn force-pushed the fix/issue-29184-last-insert-id branch from f0b56ec to 08a66cf Compare September 21, 2026 09:17

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

GPT-6 high review at exact head 7f0e9fb (base 3727c5c): APPROVE.

The migration contract correctly distinguishes an authoritative exported zero from an omitted legacy field, fails closed on missing capability/marker and incompatible v92 targets, preserves the scalar HLL contract, and restores LAST_INSERT_ID into both Session and Process after replay. One-shot admission, cancellation/deadline cleanup, failed-target closure, and bounded state are closed.

The real two-CN Proxy Connector/J regression retains the same connection and prepared statements across handoff, checks source/target CNs, direct and prepared LAST_INSERT_ID, and a subsequent insert; fallback and automatic reconnect are disabled. Current-head CI, UT/SCA, and both BVT jobs passed. Local native/race evidence was reused only where source-equivalence was verified, not presented as new CI. This review does not claim mixed-version upgrade acceptance or close broader QA gates.

@mergify mergify Bot added the queued label Sep 22, 2026
@mergify

mergify Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-22 09:56 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-22 10:12 UTC · at 128a8d0e3cb487f6379fcbebf7685dc0f30ed04d

This pull request spent 16 minutes 32 seconds in the queue, with no time running CI.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Reason

Pull request #29192 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit 1634996 into matrixorigin:main Sep 22, 2026
26 of 27 checks passed
@mergify mergify Bot added dequeued and removed queued labels Sep 22, 2026

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/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]: Proxy CN draining resets LAST_INSERT_ID on the migrated JDBC session

5 participants