Skip to content

fix: evict idle lock routes after CN scale-down - #30269

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
aptend:fix/29447-idle-lock-routes
Oct 16, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
aptend:fix/29447-idle-lock-routes

Conversation

@aptend

@aptend aptend commented Oct 15, 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 #29447

What this PR does / why we need it:

After a controlled CN scale-down, idle remote lock-table routes could remain cached indefinitely because remote-lock heartbeats only cover bindings referenced by active transactions. The first DROP DATABASE could then contact a retired owner and fail with 20702 even after TN had completed retirement.

The existing remote keeper now reconciles idle routes with the local raw CN inventory and evicts exact bindings only after their transaction references reach zero. Membership removal triggers a cache scan; eviction is limited to 64 attempts per keeper round. Membership remains a routing hint, while TN remains authoritative for binding validity and active transactions retain their existing recovery behavior.

Cold publication confirms owners missing from the keeper snapshot against current discovery, using the existing on-demand refresh only on an address miss. Confirmation runs outside service locks and is checked against the same immutable snapshot before publication. A coalesced scan request also covers owners that join and leave between keeper rounds. Cached Lock/Unlock adds no RPC or discovery lookup.

Accepted TN binding changes retire the exact old generation independently of replacement-owner discovery. If the replacement cannot be published, cleanup still completes and the missing route remains cold for the normal GetBind path. A concurrently published replacement and its transaction consumers are preserved. This prevents Unlock from retrying an owner TN has already superseded.

Validation:

  • LockService package: normal tests with -vet=all, and the full package under -race, both with -short.
  • Ten directly affected cleanup, publication, keeper and allocator-epoch tests, each repeated 100 times under -race. The new cleanup regression covers an unreachable old owner and absent/failed replacement discovery through both ordinary and context-bounded Unlock, plus exact-generation fencing and preservation of concurrently published routes.
  • Real embedded 3-CN to 1-CN test: after membership convergence and TN retirement, the first SQL DROP DATABASE succeeds without a client retry.
  • Incremental golangci-lint for both changed packages: 0 issues; cache-hit GetBind call-count control and stable-keeper microbenchmark passed.
  • The idle-route regression fails at the original baseline; the stale-snapshot publication regression fails before its fix. All four retired-owner cleanup cases also fail before the cleanup correction and pass afterward.

Membership changes can still trigger one full route-cache scan.

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

@matrix-meow matrix-meow added the size/XL Denotes a PR that changes [1000, 1999] lines label Oct 15, 2026
@mergify mergify Bot added the kind/bug Something isn't working label Oct 15, 2026
@aptend
aptend force-pushed the fix/29447-idle-lock-routes branch from 631780c to 79239a8 Compare October 15, 2026 10:50
@XuPeng-SH

XuPeng-SH commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 6368e84d6f90875b639527c71fbd6444f70ebc4e

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: 6368e84d6f90875b639527c71fbd6444f70ebc4e

Assessment: approve

Reviewed the complete 13-file delta and affected callers. The design appropriately reuses the keeper, exact binding references and existing synchronization. Idle eviction preserves admitted transactions and replacement generations. The prior cleanup defect is resolved: TN-confirmed retirement no longer depends on replacement-owner discovery. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

Validation:

  • Full lockservice race suite passed: 664 root tests, no failures or skips.

  • Fifteen affected concurrency tests each passed 100 repetitions under race, including both Unlock APIs, discovery failures, delayed publication and replacement preservation.

  • The real three-CN-to-one-CN regression passed: after membership convergence and TN retirement, the first DROP DATABASE succeeded without client retry; fixture cleanup completed.

  • Stable keeper benchmarks across 0, 10,000 and 100,000 cached routes measured 224.6–300.3 ns/round, 272 bytes and four allocations. Cached Lock/Unlock tests confirmed unchanged GetBind counts.

  • Verified native provenance, clean frozen source, commands, exit receipts and retained logs. Evidence is recorded in /home/xupeng/.local/state/mo-bot/jobs/55fed108a890a67baec030ff/attempt-1/validation-audit.json; the final audit also passed.

Limitations:

  • Membership changes still require a full route scan and proportional candidate storage; only eviction attempts are capped at 64 per round. The benchmark measures stable keeper work with mock inventory, not SQL throughput or membership-change latency.

  • Integration covers controlled scale-down, not every network-partition scenario. The standalone linked-issue body and raw author validation logs were not supplied; author claims were not counted as verified execution.

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

Reviewed head 6368e84d6f90875b639527c71fbd6444f70ebc4e against supplied main base e8b3ed7f21c2b1966d74814adaa2bcd96d8c129f, including all 13 changed files, transaction admission/reference accounting, remote Unlock, allocator-state fencing, route publication, proxy cleanup, and keeper paths. No current actionable findings; APPROVE.

The previous blocking cleanup finding is resolved. handleBindChangedFromAllocator no longer performs replacement-owner discovery. After accepting changed TN binding evidence, an unpublishable replacement causes exact old-binding fencing and detachment, returns successful cleanup, and closes the retired table after releasing service locks. An already-published or newer concurrent route is preserved. The added regression exercises ordinary and context-bounded Unlock with an unreachable old owner and absent/failed replacement discovery; it also checks other old consumers, retained-reference release, and replacement-consumer preservation.

Reviewed the idle-eviction and publication tests, including reference preservation during in-flight Lock, bounded eviction, generation checks, stale discovery confirmations, brief join/leave, and the embedded scale-down SQL case. Membership absence only governs idle routing hints; accepted TN evidence remains the authority for retiring active generations.

Validation: git diff --check passed; the local full patch matches the supplied GitHub patch apart from index-hash abbreviation. A temporary extracted-source harness exercised the actual current idle-route functions and allocator-change handler with dependency stubs: cleanup, rejection/cancellation, batching/generation preservation, and confirmation/snapshot behavior passed 100 repetitions under -race. Substituting the previous-head handler made both missing-owner and discovery-error cleanup controls fail as expected. This is control-flow validation, not a native lockservice package or live-cluster run; the added native tests and SQL regression were inspected but not rerun. Source files remain unchanged and the sparse checkout was not expanded.

The supplied exact-head CI snapshot has 28 completed checks: 12 successful, 14 skipped, and 2 neutral, with no failures. GitHub reports mergeable, with the branch behind main. Prior reviews, review-thread comments, and PR conversation were inspected; no explicit author reply is present in the supplied history. Approval follows resolution of the previous blocking finding and absence of current findings.

@mergify mergify Bot added the queued label Oct 16, 2026
@mergify

mergify Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-16 05:03 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-16 08:01 UTC · at 11750c64b4f46f5a4fec126b247780868b46b31b

This pull request spent 2 hours 58 minutes 3 seconds in the queue, with no time running CI.

Reason

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

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

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

  • Requeue this pull request

This branch was previously deployed

1 inactive deployment
ci — 11750c64 Deployed Oct 16, 2026 by mergify[bot]
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/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: DROP DATABASE fails with lock table bind changed after controlled 3 CN to 1 CN scale-down

4 participants