Repository navigation
fix(lockservice): recover from departed lock owners - #28115
Conversation
Fence transactions when the remote-lock keeper finds a definitively unavailable owner so stale bind references drain through transaction cleanup. Retry view-metadata catalog fencing across connection availability changes during bounded CN startup admission.
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.
Blocking: a departed owner is still retried forever when the exact route has already been detached or replaced.
invalidateRemoteBind delegates to removeLockTablesWithFence, and that helper fences transactions only while iterating removedTables. If the exact old route is no longer in tableGroups, the slice is empty and no transaction is fenced. That state is valid by design: remoteBindRefs is transaction-owned and intentionally outlives route-cache membership, while production paths such as ForceRefreshLockTableBinds and CloseRemoteLockTable can remove the route independently.
A concrete interleaving is:
- A transaction records old bind B and acquires its
remoteBindRef. - A refresh/query command removes B from the route cache while the transaction remains active.
- The keeper sends B, gets the missing-owner
ErrBackendCannotConnect, and callsinvalidateRemoteBind(B). - No route is detached in that call, so the transaction is not marked
bindChanged; its ref remains and subsequent keeper rounds keep contacting the departed owner.
I reproduced this on exact head 0744fa5f617dbc497037bb6cc6737f3d2c2e1095 by changing the new regression test along only this state axis: remove the exact route after acquireRemoteBindRef(oldBind), while retaining the active transaction and ref. TestKeepRemoteLockMissingOwnerFencesActiveTxn then fails at the txn.bindChanged assertion.
Please make fencing of exact dependent transactions independent of route detachment/cache state. The fence must be scoped to the exact old bind so an already-published/newer generation and its transactions are not disturbed. Add deterministic coverage for both an absent route and an already-replaced route, including an unaffected new-generation transaction; keep ref release transaction-cleanup-owned.
Unhappy-path closure:
- Q1 cleanup ownership: route and ref have independent owners; the missing route currently suppresses the only new txn-fence action.
- Q2 termination: the keeper round itself remains bounded, but this stale transaction/ref state has no keeper-driven terminal transition.
- Q3 growth: queues and per-round work remain bounded, but every later round repeats work for the persistent stale ref.
Make missing-owner fencing depend on the transaction's exact remote bind instead of route-cache removal. Preserve replacement generations and keep remote bind reference release owned by transaction cleanup.
|
Addressed the blocking review in
The focused regression passes under |
…nt (#28343) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue #27707 ## What this PR does / why we need it: PR #28115 stopped a missing LockService owner from crashing a replacement CN and fenced transactions that depended on the departed exact bind. However, transaction-owned `remoteBindRefs` intentionally remain until transaction cleanup, and the keeper still treated those retained references as heartbeat-eligible. A fenced transaction could therefore keep the departed generation in every keeper round, matching the latest stability report of continuous `failed to keep remote locks` after all replacement CNs were Ready. This follow-up separates reference lifetime from keeper eligibility: - invalidates an unusable exact remote-bind generation while retaining its ref-counted tombstone until normal transaction cleanup, preserving the cleanup ownership and ABA protection introduced by #28115; - excludes invalidated generations from future keeper rounds without affecting a replacement generation for the same table; - rejects new transaction admission to an invalidated exact tombstone before the remote Lock RPC, while allowing the same bind to be admitted again after the old owners finish cleanup; - treats owner-side `ErrLockTableBindChanged`, `ErrLockTableNotFound`, and `NewBind` as authoritative rejection of the exact generation, even when the allocator temporarily returns the same stale bind; - rejects a request routed to a replacement CN with a different UUID using `ErrLockTableBindChanged` instead of terminating the replacement CN; - covers missing/changed owners, stale allocator responses, already-published replacement generations, invalidated-tombstone admission, delayed cleanup, transient owner-side allocator failure, and same-endpoint replacement routing. There is no wire-format or public API change. Validation on the current head: - focused keeper, replacement-CN, invalidated-admission, and transient-NotFound regressions passed; - the two review counterexamples passed with `-race -count=100`; - full `pkg/lockservice` passed with `-short` in normal mode (87.132s) and race mode (90.880s); - `make dev-build` passed; - `make static-check-analysis GOLANGCI_LINT_CONCURRENCY=4` passed with 0 issues; - `git diff --check` passed. The original convergence path was also validated with a real local two-CN reproduction using the built image: an active transaction on CN1 held a lock whose owner was CN2, then CN2 was replaced at the same endpoint with a new UUID. There was no fatal log or restart. Transient keeper/rejection counters stopped changing during an additional 20-second steady-state window; the replacement CN remained running, the uncommitted value was not exposed, and rollback preserved the original committed value. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: XuPeng-SH <[email protected]>
…#28474) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue #27707 Keep the issue open until the complete fixed image passes the field acceptance gate below; merging this PR alone is not the closure criterion. ## What this PR does / why we need it: This follow-up closes two recovery gaps left after #28115 and #28343, without weakening their transaction fences: - **DN departed-owner recovery:** check the local raw CN inventory before GetActiveTxn. If no endpoint exists, retain admission/cannot-commit fences but skip futile RPCs, backend resets and repeated missing-owner errors. Recheck membership every normal sweep, including pending-admission CNs. - **Safe eventual expiry:** preserve the first disconnect timestamp rather than extending the 24-hour retention on each failure. Cleanup validates ctl identity, recovery epoch, transaction watermark and inactive timestamp against Resume, fresh state and replacement ctl. In-flight Commit and persistent unknown-Commit fences keep their independent lifetime protection. - **CN route recovery:** a stale allocator reply can republish an invalidated exact bind after keeper detachment. New requests then reject before reaching the RPC refresh path, while the keeper correctly skips the invalidated ref. Rejection now detaches only that exact cached route, allowing subsequent discovery to fetch the converged bind. Lock, ForwardLock and RemoteLock-on-Shared-proxy use the same helper. - **Preserved ownership:** old transactions remain fenced; invalidated refs remain until their consumers release them. The helper pins ref lifetime through constant-time route detachment, preserves newer/metadata-distinct routes and same-key valid reacquisition, and closes outside mutation locks. No wire/API/storage-format change, new retry layer/background worker, pressure-policy change or configuration-default change. Validation: - Deterministic expiry/Resume/Commit/ctl-replacement and missing-membership counterexamples; negative controls fail on unfixed behavior. - Actual Lock and forwarded/proxied handler rejection; cancellation, new route/allocator/routing metadata, ref release/reacquisition, and close ownership controls. - Individual adaptive race stress, including 100 repetitions for the route and membership recovery tests. - Delivery integrates main `f0c31cd4b8` at `56fe252fd7`; CI checks out the PR head, so the current dependency graph is tested explicitly. PR head `07a73ab3e7` differs from the tested revision only in the evidence document. - Integrated owning package: `-short -count=1` passed (86.463s); `-short -race -count=1` passed (91.534s). All ten exact route/membership/expiry race tests were remeasured and repeated individually (nine at 100 repetitions, persistent-disconnect expiry at 47); all passed. - `make build`, `make err-check`, and repository-configured owning-package golangci passed (0 lint issues). - Full-repository `make static-check-analysis GOLANGCI_LINT_CONCURRENCY=2` passed (exit 0): err-check, all-package molint and all-package golangci; golangci reported 0 issues under unchanged repository rules/exclusions (11m21s). - Additional repository license-header check passed (exit 0): 5,264 files checked, 0 invalid, 0 modified. - Integrated real LogService + DN + two CN processes (`dn-expiry-compare-vrbvaws6`, exit 0), two sequential CN replacements: both 65-second windows completed 33 SQL commits. Departed-owner DN error counters stayed `[6] -> [6]` and `[6,6] -> [6,6]`; the second transition had one transient 20702, then progress. Old uncommitted values stayed invisible, both DN fences remained, and the original locked row could be rewritten/committed and read from the other CN. All test-owned processes exited, with no CN fatal/panic. Binary SHA-256: `0d65214a27aafbfd5cc0d574b71ecdbde0ba7f9539ec82bae92986b9f256f4c8`. Limits are explicit: the real test keeps default 24-hour DN retention and 20-second cleaner cadence but uses a 10-second CN remote-lock lease. It is not a default-10-minute-lease test, a 24-hour soak or a field 15-minute acceptance run. The non-short `TestIssue3288` deadline also fails at the clean investigation baseline; no assertion was weakened. Owning-package molint diagnostics match the clean baseline. Full evidence and the closure checklist are in `docs/design/evidence/27707_dn_inactive_expiry.md`. Field acceptance before issue closure: use an immutable image containing the complete fix, replace both CNs with active remote-lock transactions, verify completed rollout/SQL and original-row recovery/data safety, and keep each departed owner's error counters flat for at least 15 minutes after membership convergence. This PR intentionally does not auto-close the issue. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue #27291 issue #27293 ## What this PR does / why we need it: This is a focused backport of the merged upstream #27296 fix to `4.2-dev`. A stale empty row/range lock can reach `tryHold`. The old `4.2-dev` path panics (`BUG: try hold on empty lock`) and can leave the following admission blocked. This backport: - returns `errEmptyLock` instead of panicking; - removes or repairs stale row/range endpoints before retry; - preserves structural range pairing and merge/restart behavior; - adds direct lockservice regression coverage. It also closes the empty-endpoint lifecycle hole in the batch cleanup path. `closeRangeWaiterLocked` can snapshot multiple empty endpoints before deleting them; `deleteEmptyLockLocked` re-reads the current store entry and verifies the value, creation timestamp, and backing holders/waiter identity before dereferencing or releasing state. The current formal P1 repair closes the remaining Start-first orphan sequence. For a live `[1,10]` plus orphan `End(5)` and `Start(7)`, structural cleanup now crosses an unmatched orphan end and rejects a candidate `End` that already has an earlier matching `Start`. This prevents either cleanup order from copying the live pooled state into an orphan key. The regression uses real `service.Lock([1,10])`, both Start-first and End-first cleanup orders, real owner `Unlock`, returned-state traps, and an empty-store assertion. The companion remote-bind lifecycle fixes #28115 and #28343 are intentionally not included. They address departed-owner/CN-replacement fencing, require an adapted ordered backport, and were not established as the cause of this incident. They should be reviewed separately. QA required: yes. This changes distributed LockService/CN failure and cleanup behavior; after merge it requires dev two-CN validation of the original panic path and post-cleanup admission. ## Validation - Exact tested base: `matrixorigin/matrixone:4.2-dev` at `b122da6dc20985cbfcb2fcc642ae6729d70d8516`. - Current backport head: `babbdc7bdf0bedec18822a3f774fc48f21644e94`. - Exact committed base-to-head diff SHA-256: `4196ac635372fa22eec6a7bab304d1cc43b239a569e82f4e869b12981e79df6a`. - Schema-v7 semantic preflight: PASS; exact-content hash `a58df1faf1c94c16a9151454c6cf2caa8174bd19b3f16c6af184ab2fb032de82`. - Red/green P1 proof: the new Start-first regression failed on the prior exact head `551700dfad0ecf97d9f6acd2e4f66d6e5f74eb29` because the orphan endpoint remained; the repaired head passes. - Focused LockService structural/cleanup set, including both cleanup orders, enclosing/multiple/mixed orphan endpoints, mismatched repair, stale batch snapshots, merge restart, waiter-reference clearing, and interleaved range locks: PASS. - New regression after exact-base rebase: normal PASS; focused `-race -count=100` PASS with 100 pass records and no race report. - Full `./pkg/lockservice` normal: PASS (`111.826s`). Full `./pkg/lockservice` `-race`: PASS (`115.861s`). - `go list -mod=readonly ./pkg/lockservice ./pkg/sql/colexec/lockop`: PASS. - `gofmt` and `git diff --check`: PASS. - `mo-cgo-test` clean-worktree wrapper: `BLOCKED_ENVIRONMENT` because this candidate worktree lacks `thirdparties/install`. Controlled direct CGo execution with explicit native paths passed the lockservice normal/race tests. `go build`/`go vet` for lockservice+lockop remain environment-blocked in `pkg/common/docfilter` by unavailable `C.mo_cbitmap_*`/`C.mo_croaring_*` bindings; no build/vet PASS is claimed. - BVT: N/A for this internal LockService/CN lifecycle fix; there is no SQL result contract reachable through BVT. The equivalent package regression is provided, and the required post-merge two-CN SQL/admission QA is called out above. - New-head required GitHub checks are running after this update; prior green checks belonged to an older head and are not reused as current evidence. The PR does not modify GitOps/Kubernetes or deploy to dev. Full dev rollout and SQL validation remain post-merge QA gates. --------- Co-authored-by: davis zhen <[email protected]>
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#27707 ## What this PR does / why we need it: A rolling CN replacement can leave an exact remote lock-table bind pointing at a LockService UUID that is no longer present in cluster inventory. The remote-lock keeper previously detached the local route after `ErrBackendCannotConnect`, but left transactions that depended on that bind usable. Their transaction-owned remote-bind references therefore kept the departed owner in the keeper set until transaction cleanup, matching the repeated `failed to keep remote locks` reports from the stability cluster. This change: - makes definitive missing-owner keeper failures detach the exact stale route, when present, and fence every transaction that depends on that exact remote bind; - makes transaction fencing independent of route-cache membership, covering routes already removed by `ForceRefreshLockTableBinds` / `CloseRemoteLockTable` or replaced before the keeper result arrives; - compares the complete `remoteBindKey` when removing and fencing, preserving replacement routes and transactions even when `LockTable.Changed` treats their routing metadata as compatible; - preserves transaction ownership of `remoteBindRefs`, so normal transaction cleanup remains the only release owner; - treats MORPC connection-availability errors from startup view-metadata catalog fencing as retryable within the existing bounded discovery/upgrade context, instead of terminating the replacement CN during membership convergence; - keeps joined catalog/rollback errors fail-closed by requiring every error leaf to be retryable. Regression coverage includes a cached old route, an absent route, an already-replaced route with an unaffected new-generation transaction, a `Changed`-compatible but non-exact replacement route, and an in-flight bind intent whose lock operation must be canceled. Validation: - Before the review fix, the absent-route and replaced-route cases failed because the old transaction was not fenced. - During self-review, the `Changed`-compatible/non-exact replacement case failed because the replacement route was incorrectly detached; exact-key matching fixes it. - The final missing-owner regression passed in normal mode and under `-race -count=100`. - Full `pkg/lockservice` tests passed in normal mode (99.867s) and race mode (105.223s) using the repository CGo test wrapper. - Full `pkg/cnservice` tests passed in normal mode (8.563s) and race mode (9.756s) using the repository CGo test wrapper. - Focused CN catalog classifier, startup retry, and mixed-error rejection tests passed. - `go vet` passed for both owning packages with the repository CGo environment. - `git diff --check` passed. No BVT is added because the changed contract is internal LockService/CN lifecycle behavior rather than a SQL result contract. The remaining acceptance check is the reported two-CN rolling-update stability topology. A stale remote-bind reference is deliberately retained until its fenced transaction completes cleanup; invalidation does not take over that ownership. --------- Co-authored-by: XuPeng-SH <[email protected]>
…nt (matrixorigin#28343) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#27707 ## What this PR does / why we need it: PR matrixorigin#28115 stopped a missing LockService owner from crashing a replacement CN and fenced transactions that depended on the departed exact bind. However, transaction-owned `remoteBindRefs` intentionally remain until transaction cleanup, and the keeper still treated those retained references as heartbeat-eligible. A fenced transaction could therefore keep the departed generation in every keeper round, matching the latest stability report of continuous `failed to keep remote locks` after all replacement CNs were Ready. This follow-up separates reference lifetime from keeper eligibility: - invalidates an unusable exact remote-bind generation while retaining its ref-counted tombstone until normal transaction cleanup, preserving the cleanup ownership and ABA protection introduced by matrixorigin#28115; - excludes invalidated generations from future keeper rounds without affecting a replacement generation for the same table; - rejects new transaction admission to an invalidated exact tombstone before the remote Lock RPC, while allowing the same bind to be admitted again after the old owners finish cleanup; - treats owner-side `ErrLockTableBindChanged`, `ErrLockTableNotFound`, and `NewBind` as authoritative rejection of the exact generation, even when the allocator temporarily returns the same stale bind; - rejects a request routed to a replacement CN with a different UUID using `ErrLockTableBindChanged` instead of terminating the replacement CN; - covers missing/changed owners, stale allocator responses, already-published replacement generations, invalidated-tombstone admission, delayed cleanup, transient owner-side allocator failure, and same-endpoint replacement routing. There is no wire-format or public API change. Validation on the current head: - focused keeper, replacement-CN, invalidated-admission, and transient-NotFound regressions passed; - the two review counterexamples passed with `-race -count=100`; - full `pkg/lockservice` passed with `-short` in normal mode (87.132s) and race mode (90.880s); - `make dev-build` passed; - `make static-check-analysis GOLANGCI_LINT_CONCURRENCY=4` passed with 0 issues; - `git diff --check` passed. The original convergence path was also validated with a real local two-CN reproduction using the built image: an active transaction on CN1 held a lock whose owner was CN2, then CN2 was replaced at the same endpoint with a new UUID. There was no fatal log or restart. Transient keeper/rejection counters stopped changing during an additional 20-second steady-state window; the replacement CN remained running, the uncommitted value was not exposed, and rollback preserved the original committed value. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: XuPeng-SH <[email protected]>
…matrixorigin#28474) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#27707 Keep the issue open until the complete fixed image passes the field acceptance gate below; merging this PR alone is not the closure criterion. ## What this PR does / why we need it: This follow-up closes two recovery gaps left after matrixorigin#28115 and matrixorigin#28343, without weakening their transaction fences: - **DN departed-owner recovery:** check the local raw CN inventory before GetActiveTxn. If no endpoint exists, retain admission/cannot-commit fences but skip futile RPCs, backend resets and repeated missing-owner errors. Recheck membership every normal sweep, including pending-admission CNs. - **Safe eventual expiry:** preserve the first disconnect timestamp rather than extending the 24-hour retention on each failure. Cleanup validates ctl identity, recovery epoch, transaction watermark and inactive timestamp against Resume, fresh state and replacement ctl. In-flight Commit and persistent unknown-Commit fences keep their independent lifetime protection. - **CN route recovery:** a stale allocator reply can republish an invalidated exact bind after keeper detachment. New requests then reject before reaching the RPC refresh path, while the keeper correctly skips the invalidated ref. Rejection now detaches only that exact cached route, allowing subsequent discovery to fetch the converged bind. Lock, ForwardLock and RemoteLock-on-Shared-proxy use the same helper. - **Preserved ownership:** old transactions remain fenced; invalidated refs remain until their consumers release them. The helper pins ref lifetime through constant-time route detachment, preserves newer/metadata-distinct routes and same-key valid reacquisition, and closes outside mutation locks. No wire/API/storage-format change, new retry layer/background worker, pressure-policy change or configuration-default change. Validation: - Deterministic expiry/Resume/Commit/ctl-replacement and missing-membership counterexamples; negative controls fail on unfixed behavior. - Actual Lock and forwarded/proxied handler rejection; cancellation, new route/allocator/routing metadata, ref release/reacquisition, and close ownership controls. - Individual adaptive race stress, including 100 repetitions for the route and membership recovery tests. - Delivery integrates main `f0c31cd4b8` at `56fe252fd7`; CI checks out the PR head, so the current dependency graph is tested explicitly. PR head `07a73ab3e7` differs from the tested revision only in the evidence document. - Integrated owning package: `-short -count=1` passed (86.463s); `-short -race -count=1` passed (91.534s). All ten exact route/membership/expiry race tests were remeasured and repeated individually (nine at 100 repetitions, persistent-disconnect expiry at 47); all passed. - `make build`, `make err-check`, and repository-configured owning-package golangci passed (0 lint issues). - Full-repository `make static-check-analysis GOLANGCI_LINT_CONCURRENCY=2` passed (exit 0): err-check, all-package molint and all-package golangci; golangci reported 0 issues under unchanged repository rules/exclusions (11m21s). - Additional repository license-header check passed (exit 0): 5,264 files checked, 0 invalid, 0 modified. - Integrated real LogService + DN + two CN processes (`dn-expiry-compare-vrbvaws6`, exit 0), two sequential CN replacements: both 65-second windows completed 33 SQL commits. Departed-owner DN error counters stayed `[6] -> [6]` and `[6,6] -> [6,6]`; the second transition had one transient 20702, then progress. Old uncommitted values stayed invisible, both DN fences remained, and the original locked row could be rewritten/committed and read from the other CN. All test-owned processes exited, with no CN fatal/panic. Binary SHA-256: `0d65214a27aafbfd5cc0d574b71ecdbde0ba7f9539ec82bae92986b9f256f4c8`. Limits are explicit: the real test keeps default 24-hour DN retention and 20-second cleaner cadence but uses a 10-second CN remote-lock lease. It is not a default-10-minute-lease test, a 24-hour soak or a field 15-minute acceptance run. The non-short `TestIssue3288` deadline also fails at the clean investigation baseline; no assertion was weakened. Owning-package molint diagnostics match the clean baseline. Full evidence and the closure checklist are in `docs/design/evidence/27707_dn_inactive_expiry.md`. Field acceptance before issue closure: use an immutable image containing the complete fix, replace both CNs with active remote-lock transactions, verify completed rollout/SQL and original-row recovery/data safety, and keep each departed owner's error counters flat for at least 15 minutes after membership convergence. This PR intentionally does not auto-close the issue. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#27707 ## What this PR does / why we need it: A rolling CN replacement can leave an exact remote lock-table bind pointing at a LockService UUID that is no longer present in cluster inventory. The remote-lock keeper previously detached the local route after `ErrBackendCannotConnect`, but left transactions that depended on that bind usable. Their transaction-owned remote-bind references therefore kept the departed owner in the keeper set until transaction cleanup, matching the repeated `failed to keep remote locks` reports from the stability cluster. This change: - makes definitive missing-owner keeper failures detach the exact stale route, when present, and fence every transaction that depends on that exact remote bind; - makes transaction fencing independent of route-cache membership, covering routes already removed by `ForceRefreshLockTableBinds` / `CloseRemoteLockTable` or replaced before the keeper result arrives; - compares the complete `remoteBindKey` when removing and fencing, preserving replacement routes and transactions even when `LockTable.Changed` treats their routing metadata as compatible; - preserves transaction ownership of `remoteBindRefs`, so normal transaction cleanup remains the only release owner; - treats MORPC connection-availability errors from startup view-metadata catalog fencing as retryable within the existing bounded discovery/upgrade context, instead of terminating the replacement CN during membership convergence; - keeps joined catalog/rollback errors fail-closed by requiring every error leaf to be retryable. Regression coverage includes a cached old route, an absent route, an already-replaced route with an unaffected new-generation transaction, a `Changed`-compatible but non-exact replacement route, and an in-flight bind intent whose lock operation must be canceled. Validation: - Before the review fix, the absent-route and replaced-route cases failed because the old transaction was not fenced. - During self-review, the `Changed`-compatible/non-exact replacement case failed because the replacement route was incorrectly detached; exact-key matching fixes it. - The final missing-owner regression passed in normal mode and under `-race -count=100`. - Full `pkg/lockservice` tests passed in normal mode (99.867s) and race mode (105.223s) using the repository CGo test wrapper. - Full `pkg/cnservice` tests passed in normal mode (8.563s) and race mode (9.756s) using the repository CGo test wrapper. - Focused CN catalog classifier, startup retry, and mixed-error rejection tests passed. - `go vet` passed for both owning packages with the repository CGo environment. - `git diff --check` passed. No BVT is added because the changed contract is internal LockService/CN lifecycle behavior rather than a SQL result contract. The remaining acceptance check is the reported two-CN rolling-update stability topology. A stale remote-bind reference is deliberately retained until its fenced transaction completes cleanup; invalidation does not take over that ownership. --------- Co-authored-by: XuPeng-SH <[email protected]>
…nt (matrixorigin#28343) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#27707 ## What this PR does / why we need it: PR matrixorigin#28115 stopped a missing LockService owner from crashing a replacement CN and fenced transactions that depended on the departed exact bind. However, transaction-owned `remoteBindRefs` intentionally remain until transaction cleanup, and the keeper still treated those retained references as heartbeat-eligible. A fenced transaction could therefore keep the departed generation in every keeper round, matching the latest stability report of continuous `failed to keep remote locks` after all replacement CNs were Ready. This follow-up separates reference lifetime from keeper eligibility: - invalidates an unusable exact remote-bind generation while retaining its ref-counted tombstone until normal transaction cleanup, preserving the cleanup ownership and ABA protection introduced by matrixorigin#28115; - excludes invalidated generations from future keeper rounds without affecting a replacement generation for the same table; - rejects new transaction admission to an invalidated exact tombstone before the remote Lock RPC, while allowing the same bind to be admitted again after the old owners finish cleanup; - treats owner-side `ErrLockTableBindChanged`, `ErrLockTableNotFound`, and `NewBind` as authoritative rejection of the exact generation, even when the allocator temporarily returns the same stale bind; - rejects a request routed to a replacement CN with a different UUID using `ErrLockTableBindChanged` instead of terminating the replacement CN; - covers missing/changed owners, stale allocator responses, already-published replacement generations, invalidated-tombstone admission, delayed cleanup, transient owner-side allocator failure, and same-endpoint replacement routing. There is no wire-format or public API change. Validation on the current head: - focused keeper, replacement-CN, invalidated-admission, and transient-NotFound regressions passed; - the two review counterexamples passed with `-race -count=100`; - full `pkg/lockservice` passed with `-short` in normal mode (87.132s) and race mode (90.880s); - `make dev-build` passed; - `make static-check-analysis GOLANGCI_LINT_CONCURRENCY=4` passed with 0 issues; - `git diff --check` passed. The original convergence path was also validated with a real local two-CN reproduction using the built image: an active transaction on CN1 held a lock whose owner was CN2, then CN2 was replaced at the same endpoint with a new UUID. There was no fatal log or restart. Transient keeper/rejection counters stopped changing during an additional 20-second steady-state window; the replacement CN remained running, the uncommitted value was not exposed, and rollback preserved the original committed value. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: XuPeng-SH <[email protected]>
…matrixorigin#28474) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#27707 Keep the issue open until the complete fixed image passes the field acceptance gate below; merging this PR alone is not the closure criterion. ## What this PR does / why we need it: This follow-up closes two recovery gaps left after matrixorigin#28115 and matrixorigin#28343, without weakening their transaction fences: - **DN departed-owner recovery:** check the local raw CN inventory before GetActiveTxn. If no endpoint exists, retain admission/cannot-commit fences but skip futile RPCs, backend resets and repeated missing-owner errors. Recheck membership every normal sweep, including pending-admission CNs. - **Safe eventual expiry:** preserve the first disconnect timestamp rather than extending the 24-hour retention on each failure. Cleanup validates ctl identity, recovery epoch, transaction watermark and inactive timestamp against Resume, fresh state and replacement ctl. In-flight Commit and persistent unknown-Commit fences keep their independent lifetime protection. - **CN route recovery:** a stale allocator reply can republish an invalidated exact bind after keeper detachment. New requests then reject before reaching the RPC refresh path, while the keeper correctly skips the invalidated ref. Rejection now detaches only that exact cached route, allowing subsequent discovery to fetch the converged bind. Lock, ForwardLock and RemoteLock-on-Shared-proxy use the same helper. - **Preserved ownership:** old transactions remain fenced; invalidated refs remain until their consumers release them. The helper pins ref lifetime through constant-time route detachment, preserves newer/metadata-distinct routes and same-key valid reacquisition, and closes outside mutation locks. No wire/API/storage-format change, new retry layer/background worker, pressure-policy change or configuration-default change. Validation: - Deterministic expiry/Resume/Commit/ctl-replacement and missing-membership counterexamples; negative controls fail on unfixed behavior. - Actual Lock and forwarded/proxied handler rejection; cancellation, new route/allocator/routing metadata, ref release/reacquisition, and close ownership controls. - Individual adaptive race stress, including 100 repetitions for the route and membership recovery tests. - Delivery integrates main `f0c31cd4b8` at `56fe252fd7`; CI checks out the PR head, so the current dependency graph is tested explicitly. PR head `07a73ab3e7` differs from the tested revision only in the evidence document. - Integrated owning package: `-short -count=1` passed (86.463s); `-short -race -count=1` passed (91.534s). All ten exact route/membership/expiry race tests were remeasured and repeated individually (nine at 100 repetitions, persistent-disconnect expiry at 47); all passed. - `make build`, `make err-check`, and repository-configured owning-package golangci passed (0 lint issues). - Full-repository `make static-check-analysis GOLANGCI_LINT_CONCURRENCY=2` passed (exit 0): err-check, all-package molint and all-package golangci; golangci reported 0 issues under unchanged repository rules/exclusions (11m21s). - Additional repository license-header check passed (exit 0): 5,264 files checked, 0 invalid, 0 modified. - Integrated real LogService + DN + two CN processes (`dn-expiry-compare-vrbvaws6`, exit 0), two sequential CN replacements: both 65-second windows completed 33 SQL commits. Departed-owner DN error counters stayed `[6] -> [6]` and `[6,6] -> [6,6]`; the second transition had one transient 20702, then progress. Old uncommitted values stayed invisible, both DN fences remained, and the original locked row could be rewritten/committed and read from the other CN. All test-owned processes exited, with no CN fatal/panic. Binary SHA-256: `0d65214a27aafbfd5cc0d574b71ecdbde0ba7f9539ec82bae92986b9f256f4c8`. Limits are explicit: the real test keeps default 24-hour DN retention and 20-second cleaner cadence but uses a 10-second CN remote-lock lease. It is not a default-10-minute-lease test, a 24-hour soak or a field 15-minute acceptance run. The non-short `TestIssue3288` deadline also fails at the clean investigation baseline; no assertion was weakened. Owning-package molint diagnostics match the clean baseline. Full evidence and the closure checklist are in `docs/design/evidence/27707_dn_inactive_expiry.md`. Field acceptance before issue closure: use an immutable image containing the complete fix, replace both CNs with active remote-lock transactions, verify completed rollout/SQL and original-row recovery/data safety, and keep each departed owner's error counters flat for at least 15 minutes after membership convergence. This PR intentionally does not auto-close the issue. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#27707 ## What this PR does / why we need it: A rolling CN replacement can leave an exact remote lock-table bind pointing at a LockService UUID that is no longer present in cluster inventory. The remote-lock keeper previously detached the local route after `ErrBackendCannotConnect`, but left transactions that depended on that bind usable. Their transaction-owned remote-bind references therefore kept the departed owner in the keeper set until transaction cleanup, matching the repeated `failed to keep remote locks` reports from the stability cluster. This change: - makes definitive missing-owner keeper failures detach the exact stale route, when present, and fence every transaction that depends on that exact remote bind; - makes transaction fencing independent of route-cache membership, covering routes already removed by `ForceRefreshLockTableBinds` / `CloseRemoteLockTable` or replaced before the keeper result arrives; - compares the complete `remoteBindKey` when removing and fencing, preserving replacement routes and transactions even when `LockTable.Changed` treats their routing metadata as compatible; - preserves transaction ownership of `remoteBindRefs`, so normal transaction cleanup remains the only release owner; - treats MORPC connection-availability errors from startup view-metadata catalog fencing as retryable within the existing bounded discovery/upgrade context, instead of terminating the replacement CN during membership convergence; - keeps joined catalog/rollback errors fail-closed by requiring every error leaf to be retryable. Regression coverage includes a cached old route, an absent route, an already-replaced route with an unaffected new-generation transaction, a `Changed`-compatible but non-exact replacement route, and an in-flight bind intent whose lock operation must be canceled. Validation: - Before the review fix, the absent-route and replaced-route cases failed because the old transaction was not fenced. - During self-review, the `Changed`-compatible/non-exact replacement case failed because the replacement route was incorrectly detached; exact-key matching fixes it. - The final missing-owner regression passed in normal mode and under `-race -count=100`. - Full `pkg/lockservice` tests passed in normal mode (99.867s) and race mode (105.223s) using the repository CGo test wrapper. - Full `pkg/cnservice` tests passed in normal mode (8.563s) and race mode (9.756s) using the repository CGo test wrapper. - Focused CN catalog classifier, startup retry, and mixed-error rejection tests passed. - `go vet` passed for both owning packages with the repository CGo environment. - `git diff --check` passed. No BVT is added because the changed contract is internal LockService/CN lifecycle behavior rather than a SQL result contract. The remaining acceptance check is the reported two-CN rolling-update stability topology. A stale remote-bind reference is deliberately retained until its fenced transaction completes cleanup; invalidation does not take over that ownership. --------- Co-authored-by: XuPeng-SH <[email protected]>
…nt (matrixorigin#28343) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#27707 ## What this PR does / why we need it: PR matrixorigin#28115 stopped a missing LockService owner from crashing a replacement CN and fenced transactions that depended on the departed exact bind. However, transaction-owned `remoteBindRefs` intentionally remain until transaction cleanup, and the keeper still treated those retained references as heartbeat-eligible. A fenced transaction could therefore keep the departed generation in every keeper round, matching the latest stability report of continuous `failed to keep remote locks` after all replacement CNs were Ready. This follow-up separates reference lifetime from keeper eligibility: - invalidates an unusable exact remote-bind generation while retaining its ref-counted tombstone until normal transaction cleanup, preserving the cleanup ownership and ABA protection introduced by matrixorigin#28115; - excludes invalidated generations from future keeper rounds without affecting a replacement generation for the same table; - rejects new transaction admission to an invalidated exact tombstone before the remote Lock RPC, while allowing the same bind to be admitted again after the old owners finish cleanup; - treats owner-side `ErrLockTableBindChanged`, `ErrLockTableNotFound`, and `NewBind` as authoritative rejection of the exact generation, even when the allocator temporarily returns the same stale bind; - rejects a request routed to a replacement CN with a different UUID using `ErrLockTableBindChanged` instead of terminating the replacement CN; - covers missing/changed owners, stale allocator responses, already-published replacement generations, invalidated-tombstone admission, delayed cleanup, transient owner-side allocator failure, and same-endpoint replacement routing. There is no wire-format or public API change. Validation on the current head: - focused keeper, replacement-CN, invalidated-admission, and transient-NotFound regressions passed; - the two review counterexamples passed with `-race -count=100`; - full `pkg/lockservice` passed with `-short` in normal mode (87.132s) and race mode (90.880s); - `make dev-build` passed; - `make static-check-analysis GOLANGCI_LINT_CONCURRENCY=4` passed with 0 issues; - `git diff --check` passed. The original convergence path was also validated with a real local two-CN reproduction using the built image: an active transaction on CN1 held a lock whose owner was CN2, then CN2 was replaced at the same endpoint with a new UUID. There was no fatal log or restart. Transient keeper/rejection counters stopped changing during an additional 20-second steady-state window; the replacement CN remained running, the uncommitted value was not exposed, and rollback preserved the original committed value. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: XuPeng-SH <[email protected]>
…matrixorigin#28474) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#27707 Keep the issue open until the complete fixed image passes the field acceptance gate below; merging this PR alone is not the closure criterion. ## What this PR does / why we need it: This follow-up closes two recovery gaps left after matrixorigin#28115 and matrixorigin#28343, without weakening their transaction fences: - **DN departed-owner recovery:** check the local raw CN inventory before GetActiveTxn. If no endpoint exists, retain admission/cannot-commit fences but skip futile RPCs, backend resets and repeated missing-owner errors. Recheck membership every normal sweep, including pending-admission CNs. - **Safe eventual expiry:** preserve the first disconnect timestamp rather than extending the 24-hour retention on each failure. Cleanup validates ctl identity, recovery epoch, transaction watermark and inactive timestamp against Resume, fresh state and replacement ctl. In-flight Commit and persistent unknown-Commit fences keep their independent lifetime protection. - **CN route recovery:** a stale allocator reply can republish an invalidated exact bind after keeper detachment. New requests then reject before reaching the RPC refresh path, while the keeper correctly skips the invalidated ref. Rejection now detaches only that exact cached route, allowing subsequent discovery to fetch the converged bind. Lock, ForwardLock and RemoteLock-on-Shared-proxy use the same helper. - **Preserved ownership:** old transactions remain fenced; invalidated refs remain until their consumers release them. The helper pins ref lifetime through constant-time route detachment, preserves newer/metadata-distinct routes and same-key valid reacquisition, and closes outside mutation locks. No wire/API/storage-format change, new retry layer/background worker, pressure-policy change or configuration-default change. Validation: - Deterministic expiry/Resume/Commit/ctl-replacement and missing-membership counterexamples; negative controls fail on unfixed behavior. - Actual Lock and forwarded/proxied handler rejection; cancellation, new route/allocator/routing metadata, ref release/reacquisition, and close ownership controls. - Individual adaptive race stress, including 100 repetitions for the route and membership recovery tests. - Delivery integrates main `f0c31cd4b8` at `56fe252fd7`; CI checks out the PR head, so the current dependency graph is tested explicitly. PR head `07a73ab3e7` differs from the tested revision only in the evidence document. - Integrated owning package: `-short -count=1` passed (86.463s); `-short -race -count=1` passed (91.534s). All ten exact route/membership/expiry race tests were remeasured and repeated individually (nine at 100 repetitions, persistent-disconnect expiry at 47); all passed. - `make build`, `make err-check`, and repository-configured owning-package golangci passed (0 lint issues). - Full-repository `make static-check-analysis GOLANGCI_LINT_CONCURRENCY=2` passed (exit 0): err-check, all-package molint and all-package golangci; golangci reported 0 issues under unchanged repository rules/exclusions (11m21s). - Additional repository license-header check passed (exit 0): 5,264 files checked, 0 invalid, 0 modified. - Integrated real LogService + DN + two CN processes (`dn-expiry-compare-vrbvaws6`, exit 0), two sequential CN replacements: both 65-second windows completed 33 SQL commits. Departed-owner DN error counters stayed `[6] -> [6]` and `[6,6] -> [6,6]`; the second transition had one transient 20702, then progress. Old uncommitted values stayed invisible, both DN fences remained, and the original locked row could be rewritten/committed and read from the other CN. All test-owned processes exited, with no CN fatal/panic. Binary SHA-256: `0d65214a27aafbfd5cc0d574b71ecdbde0ba7f9539ec82bae92986b9f256f4c8`. Limits are explicit: the real test keeps default 24-hour DN retention and 20-second cleaner cadence but uses a 10-second CN remote-lock lease. It is not a default-10-minute-lease test, a 24-hour soak or a field 15-minute acceptance run. The non-short `TestIssue3288` deadline also fails at the clean investigation baseline; no assertion was weakened. Owning-package molint diagnostics match the clean baseline. Full evidence and the closure checklist are in `docs/design/evidence/27707_dn_inactive_expiry.md`. Field acceptance before issue closure: use an immutable image containing the complete fix, replace both CNs with active remote-lock transactions, verify completed rollout/SQL and original-row recovery/data safety, and keep each departed owner's error counters flat for at least 15 minutes after membership convergence. This PR intentionally does not auto-close the issue. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
What type of PR is this?
Which issue(s) this PR fixes:
issue #27707
What this PR does / why we need it:
A rolling CN replacement can leave an exact remote lock-table bind pointing at a LockService UUID that is no longer present in cluster inventory. The remote-lock keeper previously detached the local route after
ErrBackendCannotConnect, but left transactions that depended on that bind usable. Their transaction-owned remote-bind references therefore kept the departed owner in the keeper set until transaction cleanup, matching the repeatedfailed to keep remote locksreports from the stability cluster.This change:
ForceRefreshLockTableBinds/CloseRemoteLockTableor replaced before the keeper result arrives;remoteBindKeywhen removing and fencing, preserving replacement routes and transactions even whenLockTable.Changedtreats their routing metadata as compatible;remoteBindRefs, so normal transaction cleanup remains the only release owner;Regression coverage includes a cached old route, an absent route, an already-replaced route with an unaffected new-generation transaction, a
Changed-compatible but non-exact replacement route, and an in-flight bind intent whose lock operation must be canceled.Validation:
Changed-compatible/non-exact replacement case failed because the replacement route was incorrectly detached; exact-key matching fixes it.-race -count=100.pkg/lockservicetests passed in normal mode (99.867s) and race mode (105.223s) using the repository CGo test wrapper.pkg/cnservicetests passed in normal mode (8.563s) and race mode (9.756s) using the repository CGo test wrapper.go vetpassed for both owning packages with the repository CGo environment.git diff --checkpassed.No BVT is added because the changed contract is internal LockService/CN lifecycle behavior rather than a SQL result contract. The remaining acceptance check is the reported two-CN rolling-update stability topology. A stale remote-bind reference is deliberately retained until its fenced transaction completes cleanup; invalidation does not take over that ownership.