Repository navigation
fix(lockservice): recover from stale empty locks - #27296
Conversation
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? |
aptend
left a comment
There was a problem hiding this comment.
[P1] Do not attach an orphan endpoint to an adjacent live range
In deleteEmptyLockLocked, findPairedRangeLock only finds the nearest endpoint of the opposite kind; it does not prove that endpoint belonged to the stale lock. With an orphan empty range-start at key 1 and an otherwise valid live range [3,5], this branch treats key 5 as the pair, copies its holders/waiters into key 1, and leaves both starts (1 and 3) pointing at the same end. When the live owner later unlocks [3,5], that shared state is returned to the pools while key 1 still references it, so a subsequent allocation can mutate a lock that remains in this table. I reproduced the bad three-entry state directly at this head. Only rebuild an endpoint when its counterpart can be identified unambiguously; otherwise remove the orphan without splicing it into a neighboring range. Please add a regression with an orphan endpoint adjacent to a complete live range.
[P2] Restart the merge transaction before retrying an empty conflict
The errEmptyLock branch at lock_table_local.go:989-998 continues the outer range scan without rolling back/reinitializing mc. Any locks owned by the requester that were visited before the stale entry have already had their waiters copied into mc.to; the retry visits them again and copies the same waiter a second time. A concrete reproduction is: txn 1 owns [1,2], txn 2 is waiting on it, insert an empty row entry at key 5, then let txn 1 extend its range to [1,10]. The call succeeds, but the final range queue contains txn 2 twice. Discard/reinitialize the in-progress merge state before rescanning (including mergedWaiters/mergedLocks, not only the queue change marker), and cover this retry-after-partial-merge case.
aunjgr
left a comment
There was a problem hiding this comment.
Reviewed current head 06fca7d. The structural pair identity checks, merge-context restart, orphan cleanup, and half-live endpoint repair close the prior stale-range invariants. The lockservice regressions cover adjacent live ranges, retry-after-partial-merge, and both half-live endpoint directions. No additional blocking findings.
aptend
left a comment
There was a problem hiding this comment.
Deep re-review of exact head 06fca7d. I read the complete review/thread history, checked the b5ddcfd increment against the prior reviewed head and re-audited the full diff. The half-live endpoint repair now preserves the structural pair without attaching an orphan to an adjacent complete range; abandoned pooled state is only released after store-reference checks; and merge restart rolls back speculative waiter refs and bookkeeping before rescanning. I also reviewed row/range acquisition, waiter detach/notification, merge commit/rollback, unlock bookkeeping, and the LockOp shared-target path. Both affected packages pass under the repository CGO environment. No blocking findings remain.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review of exact head 06fca7dfdc26782c26d738c3eeb8d541145a3e4d: no blocking findings.
I re-audited the complete stale-lock recovery, not only the latest patch. Structural endpoint pairing now stops before an adjacent complete range; a unique half-live counterpart is repaired without changing its holder/waiter generation; abandoned pooled states are released only after checking remaining store references; and a retry after a partially accumulated range merge rolls back both waiter-queue changes and merged-key bookkeeping before rescanning. Row/range waiter detach, unlock notification, endpoint removal, and the LockOp shared-target/default-checker paths preserve ownership and wait-for invariants.
Verification on this exact worktree:
git diff --checkpassed.- Seven stale endpoint/partial-merge/empty-lock regressions passed with
-race -count=20. - Both LockOp regressions passed with
-race -count=20. - Full
./pkg/lockservicepassed with-race -count=1(99.176s).
|
Queued — the merge queue status continues in this comment ↓. |
Merge Queue Status
This pull request spent 1 hour 31 minutes 12 seconds in the queue, including 50 minutes 14 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #27291
#27293
What this PR does / why we need it:
当前主干已包含 nil-pointer 问题的 LockOp 修复(9661f93b0、f3039c909),本分支补齐了后续 try hold on empty lock 问题。