Skip to content

fix(proxy): migrate sessions from obsolete CN routes - #33568

Merged
XuPeng-SH merged 10 commits into
matrixorigin:mainfrom
jiangxinmeng1:codex/fix-33556-proxy-rebalance-main
Dec 3, 2026
Merged

XuPeng-SH merged 10 commits into
matrixorigin:mainfrom
jiangxinmeng1:codex/fix-33556-proxy-rebalance-main

Conversation

@jiangxinmeng1

@jiangxinmeng1 jiangxinmeng1 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG

Which issue(s) this PR fixes:

Related to #33556.

What this PR does / why we need it:

The proxy rebalancer could leave an existing session on a CN that the current route no longer selects. With one eligible target, the load threshold can prevent migration from the obsolete source. This is consistent with the placement error in #33556, although the incident's exact connection path could not be recovered.

Each rebalance pass fixes its registration boundary before reading CN discovery. It applies the shared routing policy for removed, draining, and relabeled sources, including the existing sys root/dump fallback and a live plugin destination for sessions that originally used Bypass. Backend registrations carry their own route origin during migration and rollback. Built-in pool balancing excludes retained plugin sessions outside that pool. A pass attempts at most one synchronous discovery refresh, reuses compiled label patterns, and defers busy tunnels. Plugin probes use the configured RPC timeout.

Validation

  • The previous implementation reproduced the stale-view and sys fallback failures on the same main base. Both regressions pass with the fix.
  • The full race suites for proxy, cluster service, and route passed on 16b9b15643. The Proxy suite included the embedded-cluster session migration test and ran with the local HAKeeper listener isolated. Seven focused race tests passed 100 repetitions each, including the two-CN migration followed by a SQL request. The two-CN balance test passed 63 repetitions. Vet and incremental SCA passed.
  • After rebasing onto 914470d753, the Proxy race regressions passed again. The intervening base commit updates IVFFlat and the Proxy, cluster-service, route, and native build source files are byte-identical to the tested version.
  • In a local steady-state benchmark with 64 tenants, 128 CNs and 4,096 registrations, median pass time fell from 7.59 ms to 5.08 ms, and bytes allocated per pass fell from 2.92 MB to 0.70 MB.

Review follow-up (2026-12-02)

  • A queued rebalance request now retains the selected backend registration and checks it again before transfer, so a completed migration invalidates stale work. It also checks the current tenant route before evacuating a source or balancing away from the only remaining tenant CN.
  • A busy tunnel on a draining CN retains scaling transfer intent even if that CN disappears from discovery before the next scan. Tunnel close clears the intent.
  • Added regressions for route relabeling, stale backend registration, shrinking balance pools, and busy scaling delivery after CN removal. Focused proxy tests and the same focused race tests passed; go vet ./pkg/proxy passed. Merged upstream main at f9d52a3a39.

Verify the plugin's current selection against the registered endpoint

An existing TCP connection may record 127.0.0.1:port as its peer while the CN advertises localhost:port. When a plugin switches from Bypass to Select, the proxy now checks a serving recommendation against the registered CN ID and advertised address before retaining the session. A changed advertised address still permits evacuation. Review

  • Rebased onto main edd86400a89a. The hostname regression reaches the tunnel's real destination selection with a TCP socket and a mock CN registration. On the reviewed code it attempted a replacement dial. On the corrected code it retains the source when the plugin still selects it. Controls exercise changed recommendations, a changed advertised endpoint, a draining source and load balancing.
  • Full race runs passed for pkg/proxy (37.042s), pkg/clusterservice (3.465s) and pkg/vm/engine/disttae/route (3.380s). They include automatic two-CN migration followed by a MySQL request and real session migration with privilege checks. The hostname regression passed 100/100 repeats under race.
  • The incremental SCA selector covered 18 packages for this review fix. Molint and golangci-lint passed. Previous full PR CI

Rebased validation for 89068bb76c96 on main faafdf4fef03

The tested checkout 7be7ae2c341b matches the published Git tree 9c13314c471196025052449bca3514f8804bad10. The run used Go 1.27.1 on Darwin ARM64 and the checked native library profile. The package-wide race run completed with exit 0.

ok  github.com/matrixorigin/matrixone/pkg/proxy  24.612s
ok  github.com/matrixorigin/matrixone/pkg/clusterservice  1.674s
ok  github.com/matrixorigin/matrixone/pkg/vm/engine/disttae/route  1.308s

The suite includes TestRebalanceFallbackToNewlyLabeledCN, which checks one automatic transfer and a successful MySQL command afterward, and TestRenameUserProxyMigrationPrincipal, which opens a real client session through Proxy on a two-CN cluster and verifies identity and privileges after transfer. The focused runs separately stress the deferred evacuation and observed drain paths.

Exact test under race Passed
TestDeferredEvacuationKeepsRecoveredSource 100/100
TestScalingRetainsUnqueuedDrain 100/100
TestRebalanceRejectsSupersededRegistration 100/100
TestTransferRouteKeepsPreferredTier 100/100
TestRebalanceFallbackToNewlyLabeledCN 100/100
TestRenameUserProxyMigrationPrincipal 3/3

Incremental molint and golangci-lint passed on those three packages. The local package-race JSON receipt has SHA-256 1ce1ecdde9172ce921b0c038085dc5b2ba492c998408a0e7393fe00747b710d9. The base contains #33691, which updates the ODKU CHECK expectations that failed the previous Compose BVT job. The original connection path in #33556 remains unknown.

@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 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@XuPeng-SH

XuPeng-SH commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 52b6582343a7f0dd9757d867b5d2cdb30b6d58a3

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 52b6582343a7f0dd9757d867b5d2cdb30b6d58a3

Assessment: request_changes

The per-registration origin tracking reuses the existing transfer machinery, but retaining plugin-selected sessions can now prevent balancing within the built-in pool. The new removed-source handling also leaves a pre-existing gap when the only replacement is available through the plugin.

Model: gpt-6.1-terra / max

Session: 01a22aff-bb68-7e31-ae71-ee4ab48ad9d0 · slot 0 · generation 45

  • P2 pkg/proxy/rebalancer.go:255: A tenant has ten built-in sessions on CN A, none on newly eligible CN B, and ten plugin-selected sessions retained on a live shared CN outside the built-in route.
    Impact: The retained plugin sessions inflate the total used for the two-CN built-in pool, raising the default-tolerance limit to 13. Neither A nor the shared CN exceeds it, so no transfer is scheduled and A remains overloaded while B remains idle.
    Evidence: The in-process routing probe confirms B is an eligible transfer target: without plugin sessions it collects three tunnels; with them it collects none. The base rebalancer selected the shared sessions, but restoring that eviction would defeat the intended plugin protection. Calculate the built-in balance independently of retained out-of-route plugin sessions while preserving their placement.

  • P2 pkg/proxy/rebalancer.go:212: A plugin-selected source disappears from cluster discovery, and the plugin recommends a live replacement with same-tenant custom labels that do not match the built-in selector.
    Impact: The built-in and shared candidate sets are empty, so the early return prevents the removed source from being collected even though plugin transfer routing admits the replacement. A surviving connection remains on the obsolete source until some other event removes it.
    Evidence: The routing probe admits the replacement through RouteForTransfer but collects zero tunnels; its control with a built-in target collects the source. This blind spot also exists in the base rebalancer, so it is an incomplete part of the new plugin removed-source handling. Account for plugin-provided targets before concluding that migration has no destination.

Validation:

  • Private-runtime preflight and the audit of 195 native inputs passed.

  • The selected committed proxy routing and registration tests passed: checks/1796107608684265036-3.json.

  • The focused routing overlay reproduced both findings with passing adjacent controls: review-routing-v3.log and checks/1796107694189122585-3.json.

  • A base-rebalancer overlay confirmed the balancing comparison: base-routing-v3.log and checks/1796107722976405919-3.json. Earlier base probes confirmed the plugin-only gap predates this change.

  • Initial toolchain and dependency downloads timed out before test execution; validation resumed successfully after recovering the toolchain and disabling Go HTTP/2.

Limitations:

  • The probes exercise the router and rebalancer with in-process cluster fixtures; they do not reproduce the linked production incident or a complete client migration.

  • The author-reported full-package race run was not independently repeated.

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

mo-bot review · mo-bot-local · review

Commit: 28f1a58408e137c845a80f10ee9f52981d865995

Assessment: request_changes

The change appropriately reuses the existing routing and transfer machinery and tracks backend identity across overlapping registrations. Two lifecycle gaps remain in the previously raised stale-route and busy-scaling concerns: deferred transfers can use an obsolete routing decision, and a busy scaling delivery can remain unscheduled after its CN disappears from discovery.

Model: gpt-6.1-terra / max

Session: 01a23504-137d-7f93-9b91-fd29f7f60fa2 · slot 1 · generation 42

  • P2 pkg/proxy/tunnel.go:1162: Under the default active policy, an obsolete-source candidate is validated while its session is in a transaction. Before the transaction finishes, the source becomes eligible again and its former tenant target leaves the route.
    Impact: The response-boundary transfer can move the session from its now-eligible tenant CN to a shared fallback, where locality-constrained queries can fail.
    Evidence: An unsafe asynchronous attempt calls finishTransferAttempt, clearing rebalanceCandidate, then sets transferIntent at tunnel.go:1219. The later synchronous transfer at tunnel.go:1270 does not call shouldTransferCandidate; client_conn.go:1129 excludes the current address before applying the current route. Preserve and revalidate the selection when deferred work actually chooses its destination, including route changes between validation and selection.

  • P2 pkg/proxy/tunnel_deliver.go:65: A scaling scan observes a plugin-selected draining CN while its tunnel mutex is busy. The CN then disappears from discovery, the client becomes idle, and a later authoritative refresh fails while a cached plugin destination remains usable.
    Impact: The observed drain can remain unattempted: scaling no longer rediscovers the CN, and the ordinary rebalancer conservatively skips the missing plugin source after the failed refresh. The session can be disconnected when the old CN shuts down.
    Evidence: The busy branch records only transferIntent and returns without queuing. That flag is consumed at a subsequent server response boundary in tunnel.go:1584; scaling.go:72 scans only currently discovered draining CNs, and rebalancer.go:352 skips unconfirmed missing plugin sources. Retain or retry the observed scaling work independently of later discovery and client traffic, until it transfers or closes.

Validation:

  • Reviewed the complete frozen diff, linked issue, indexed discussion, applicable repository policy, and affected routing, registration, transfer and scaling owners.

  • Private /tmp and loopback preflight passed: checks/1796221734338417314-3.json and preflight.log.

  • git diff --check passed for the assigned base and head: checks/1796221683275554485-3.json and diff-check.log.

  • Both findings are supported by source traces; receipt and log reconciliation is retained in validation-reconciliation.json.

Limitations:

  • No local Go tests ran. The installed Go 1.26.6 is below the checkout's Go 1.27.1 requirement, and two bounded toolchain download attempts timed out, including one with HTTP/2 disabled.

  • The author reports earlier race and multi-CN validation and focused follow-up checks, but the supplied evidence does not include matching local receipts for those claims. The original incident's connection path remains unconfirmed.

@XuPeng-SH

XuPeng-SH commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: cb1b0259864e811d36bb2cfbd8dec790bef89473

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: cb1b0259864e811d36bb2cfbd8dec790bef89473

Assessment: request_changes

The current source addresses the previously reported stale-registration and lost-drain scenarios and reuses the existing routing and transfer owners. The required execution evidence for the revised transfer lifecycle is not available for this head.

Model: gpt-6.1-terra / max

Session: 01a23642-a5da-74a3-9479-4bd000540084 · slot 0 · generation 54

  • P2 pkg/proxy/tunnel.go:1264: A deferred migration competes with routing changes, scaling delivery, or tunnel lifecycle events.
    Impact: Validation gap: the revised synchronization and client migration path lack matching race and two-CN execution evidence. This is not a demonstrated production failure.
    Evidence: The pinned testing and race policies require focused lifecycle validation and an owning-package race run. The PR reports earlier results, but the final head materially changes the transfer, router, and scaling paths, and local_validation contains no matching result. The local Go test attempts stopped before compilation because the Go 1.27.1 download timed out. Provide traceable matching CI or author evidence, or run the existing deferred-evacuation and retained-drain tests under race and the proxy race package, including its two-CN migration test.

Validation:

  • Reviewed the complete frozen diff, linked issue, indexed discussion, and affected routing, registration, transfer, and scaling paths.

  • Private /tmp and loopback preflight passed; receipt checks/1796229354164920569-3.json.

  • git diff --check passed for the assigned base and head; receipt checks/1796230154259060200-3.json.

  • No Go tests completed locally. Both toolchain download attempts failed before compilation; receipts and logs are recorded in validation-reconciliation.json.

Limitations:

  • Earlier author-reported race and multi-CN results do not establish execution of the final transfer-state changes.

  • The exact connection path behind linked issue #33556 remains unconfirmed.

@XuPeng-SH

XuPeng-SH commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 89068bb76c96b7dec1bc1af9fe534a36cbd382b7

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 89068bb76c96b7dec1bc1af9fe534a36cbd382b7

Assessment: request_changes

The stale-registration and retained-drain fixes are supported by current tests, but evacuation can still override a plugin’s current selection for a session originally routed through Bypass. The design otherwise reuses the existing routing and transfer owners.

Model: gpt-6.1-terra / max

Session: 01a23642-a5da-74a3-9479-4bd000540084 · slot 0 · generation 54

  • P2 pkg/proxy/router.go:420: A session initially reaches CN A through plugin Bypass. After labels change, the built-in route selects CN B, while the plugin changes to Select and explicitly selects the still-serving CN A.
    Impact: The rebalancer evacuates the session to B even though a new session with the same client information is routed by the plugin to A. This overrides the plugin’s current placement decision.
    Evidence: The registration retains its original builtin origin, so rebalancer.go:324 queues evacuation. RouteForTransfer receives the plugin’s current recommendation for A, but excludes A before recognizing it as a valid source; this guard only protects sources originally marked pluginSelected. A diagnostic routing probe reproduced the move, with passing controls for an originally plugin-selected source and for a plugin-selected new target. A live mock-CN tunnel probe observed the migration to B and a successful subsequent MySQL command. The frozen-base overlay did not evacuate this single session. For evacuation, validate a current admitted plugin Select of the source against the same discovery snapshot before excluding it, while retaining drain and balancing behavior.

Validation:

  • Seven focused proxy tests passed with the isolated executor, including deferred evacuation, retained drain, stale registration, preferred-tier routing, and a migration followed by a MySQL command; receipt checks/1796240771690242543-3.json.

  • The diagnostic routing and live-tunnel probes reproduced the finding with passing adjacent controls; receipts checks/1796240895452998795-3.json and checks/1796241065267361932-3.json. The base overlay control passed; receipt checks/1796241196027680329-3.json.

  • Private-runtime preflight and git diff --check passed. The native build used 198 inputs verified against the frozen source; reconciliation.log maps commands, source identities, exits, and logs.

  • The assigned head’s tree matches the tree identified in the author’s package-race report. The frozen CI snapshot also records successful Ubuntu unit tests and proxy multi-CN BVT. All 15 discussion keys are assessed.

Limitations:

  • The finding’s live probe uses a test client and mock CN servers, not an authenticated production cluster. The original connection path in issue #33556 remains unconfirmed.

  • The author-reported full-package race and authenticated two-CN runs were not independently repeated.

@XuPeng-SH

XuPeng-SH commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 65802001bed80efaa253f8e9c70183f5c860f0b2

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 65802001bed80efaa253f8e9c70183f5c860f0b2

Assessment: request_changes

The change reuses the existing routing and transfer owners, and most previously raised cases are addressed. The prior Bypass-to-Select finding remains open for hostname-advertised CNs: the new source-preservation guard compares different forms of the backend address.

Model: gpt-6.1-terra / max

Session: 01a23642-a5da-74a3-9479-4bd000540084 · slot 0 · generation 54

  • P2 pkg/proxy/router.go:416: A session initially reaches CN A through plugin Bypass using an advertised hostname such as cn-0:6001. A is later relabeled outside the built-in route, while the plugin selects the still-serving A and the built-in route selects CN B.
    Impact: The guard compares A's advertised hostname with the socket's numeric peer address, so it fails to preserve A. The transfer then excludes A and can migrate the session to B despite the plugin's current selection.
    Evidence: getNewServerConn supplies RemoteAddr().String() as source.addr, while source.cn.addr retains the advertised address. Hostname SQL addresses are used in etc/launch-tae-compose/config/cn-0.toml. The existing regression test supplies the advertised address as the peer, masking the difference. A source-derived guard probe using a loopback socket failed for localhost versus 127.0.0.1, while equal-address and changed-endpoint controls passed. Compare the registered advertised endpoint and ID with discovery when available, preserve the changed-endpoint behavior, and add a hostname-backed transfer regression.

Validation:

  • Reviewed the complete frozen diff, pinned repository policy, linked issue, and all 17 discussion entries. The review plan, discussion assessment, and receipt reconciliation are saved in the diagnostic directory.

  • Private runtime preflight and git diff --check passed: checks/1796270593260538037-3.json and checks/1796270959254590025-3.json.

  • The isolated, source-derived guard probe failed the hostname case and passed its two controls: guard-probe-fingerprinted.stdout and checks/1796271177860490113-3.json.

  • The supplied current-head CI snapshot reports successful Ubuntu UT, arm64 SCA, and proxy multi-CN BVT aggregate jobs.

Limitations:

  • The local pkg/proxy test did not compile or run because the Go 1.27.1 toolchain download timed out: checks/1796270660240265953-3.json. The guard probe is not a full proxy migration test.

  • The supplied CI snapshot does not include named test logs, and the linked incident's exact connection path remains unknown.

jiangxinmeng1 and others added 9 commits December 3, 2026 13:30
Port the reviewed 4.2-dev repair from e64e1f7 while retaining main’s transfer and round-robin behavior.
Preserve the transfer reason through a transaction and evaluate it against the same discovery snapshot used for destination selection. Reject stale registration work at queue admission and keep observed drains retryable while their source still owns sessions.

Share the existing route priority logic with migration, remove the separate worker-side eligibility scan, and reuse the request buffers within each rebalance pass.
@XuPeng-SH

XuPeng-SH commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 7dbe5ce920cb309351abba118f547347819cdb34

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 7dbe5ce920cb309351abba118f547347819cdb34

Assessment: approve

The proxy changes reuse the existing routing and transfer machinery while tracking backend registrations and retaining observed drains. The prior routing, lifecycle, validation, and hostname findings are addressed at this head. No actionable findings remain.

Model: gpt-6.1-terra / max

Session: 01a23642-a5da-74a3-9479-4bd000540084 · slot 0 · generation 54

Validation:

  • The isolated-runtime preflight passed, and native prerequisites were built from 196 inputs verified against the frozen source.

  • Full race runs passed for pkg/proxy, pkg/clusterservice, and pkg/vm/engine/disttae/route. They included an authenticated two-CN session migration and an automatic mock-CN migration followed by a MySQL command: package-race.log and checks/1796282582484218548-3.json.

  • The focused routing and lifecycle race selection passed: focused-race.log and checks/1796282509365875773-3.json.

  • The hostname preservation, deferred evacuation, retained drain, stale registration, and preferred-tier tests each passed 100 race repetitions. Individual logs and receipts are retained under attempt-1; the receipts are 1796282622457864321-3.json, 1796282628660173559-146.json, 1796282634767739955-293.json, 1796282640910127785-438.json, and 1796282647059669163-586.json.

  • git diff --check passed: diff-check.log and checks/1796282735808122350-3.json. The supplied CI snapshot also reports successful Ubuntu unit and multi-CN proxy BVT aggregate jobs.

  • The review plan and assessment of all 19 discussion keys are retained in the diagnostic directory.

Limitations:

  • The exact connection path behind linked issue #33556 remains unconfirmed, so the tests do not establish that this change eliminates that particular incident.

  • The author-reported steady-state benchmark was not independently reproduced.

@mergify

mergify Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request dequeued

13 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Thu 3 Dec, 07:29 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 07:42 · f06acf3

Reason

Pull request #33568 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.

To get back in the queue

  • Push a change if one is needed: the pull request is queued again once its queue conditions match.
  • If no change is needed, tick the box below to queue it again as it is.

Merge conditions not met when it left the queue

  • any of · required by GitHub branch protection:
    • check-neutral = CI Required
    • check-skipped = CI Required
    • check-success = CI Required

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

  • Requeue this pull request
2 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection

Times in UTC · dashboard · how the merge queue works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued kind/bug Something isn't working size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants