ISSUE DESCRIPTION Range-lock conflicts can strand waiters in stale queues A waiter that…
- User
ISSUE DESCRIPTION
Range-lock conflicts can strand waiters in stale queues
A waiter that moves to a new range conflict must no longer remain in stale queues. Cleanup must preserve unrelated lock state, wake the next eligible waiter when necessary, and continue to work when the previous key disappeared or was recreated.
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /matrixone, current file: none) bash-$
- Assistant
I’ll first map the repository and locate the range-lock implementation and its tests, then reproduce the stale-waiter behavior before making a focused cleanup change.
- Assistant
rgis unavailable, so I’ll usefind/grepto identify lock-service files and references to range conflicts and waiter queues. - Assistant
The relevant logic appears in
lock_table_local.go, with lock-level queue operations inlock.go. I’ll inspect the acquisition retry path and the tests around the documented multi-conflict sequence. - Assistant
There is already a complex regression scenario for moving between conflicts, which suggests the bug is near retry bookkeeping. I’ll inspect
doAcquireLock, conflict detection, and the remainder of that test to understand current intended queue ownership and synchronization hooks. - Assistant
The current range cleanup stores only the previous key and reloads whatever lock now occupies it. That can (a) miss cleanup when the key vanished, (b) remove from a recreated unrelated lock, and (c) use
closeWaiter, which does not actually remove a non-head waiter and can delete lock state. I’ll inspect queue APIs and range merge behavior to design identity-safe removal that also performs proper wake-up. - Assistant
I need the exact reference-count and notification behavior of queue removal before adding an API or reusing one. I’ll read the complete queue implementation and the lock context lifecycle, including the recently added direct missing-key test.
- Assistant
The queue has no pointer-specific removal method;
removeByTxnIDalso notifies, which is wrong when the same waiter has already moved and is about to block elsewhere. I’ll inspect context construction/reset and queue reset internals, then implement a pointer-specific detach operation that closes exactly one queue reference and conditionally wakes the next waiter. - Assistant
The central fix should track the actual prior queue, not just its key. Because both range endpoints may share queues and keys can be deleted/recreated, queue identity is the stable ownership token. I’ll verify unlock/release ordering and all
waiterQueueimplementations before editing, especially whether a deleted range lock’s queue may already have been reset and pooled. - Assistant
I’ll implement three coordinated changes: pointer-specific queue detachment (without notifying the moved waiter), lock-level wake-up of the next eligible waiter only when the detached waiter was head and no holder exists, and context tracking of the prior queue identity so a missing/recreated key is never mistaken for the old lock. I’ll also avoid duplicate insertion when retrying the same queue and clear tracking after successful acquisition.
- Assistant
Now I’ll wire identity-aware cleanup into the conflict handler. Cleanup will only mutate a stored lock when its queue is exactly the recorded old queue; empty row locks are released, while paired range entries are removed together. A retry against the same queue retains its original position instead of appending a duplicate.
- Assistant
The implementation is in place. I’ll run the focused lock-service tests (including the existing multi-conflict hang reproduction, queue tests, and direct missing-key case) under a generous timeout to catch deadlocks and reference-count errors.
- Assistant
The test command is blocked by environment configuration (
GOPATH/GOMODCACHEare unset), not by code. I’ll inspect available Go caches and configure a local writable cache without fetching external solutions. - Assistant
A populated
/root/go/pkgcache exists, so I’ll rerun usingGOPATH=/root/goand disable network module lookups to ensure validation relies only on repository/cached dependencies. - Assistant
Go also requires an explicit build cache in this stripped environment; I’ll supply
/tmp/go-buildand rerun the same focused suite. - Assistant
The focused test passes, but reviewing the “previous key disappeared” edge case reveals that range merging can move the old queue to another key. Key-plus-identity lookup alone would then miss it. I’ll strengthen cleanup by tracking the prior lock state and scanning stored queue identities for the exact waiter (excluding the new conflict queue), with a direct fallback for an orphaned/deleted prior lock. This remains pointer-specific and cannot alter a recreated lock that does not contain the waiter.
- Assistant
The strengthened implementation passes the focused regression suite. I’ll now run the full
pkg/lockservicetest package to cover remote tables, merges, cancellation, deadlock checks, and queue reference accounting. - Assistant
All lock-service tests pass. I’ll review the final diff for unintended changes, stale comments/imports, and ensure the implementation is narrowly scoped before running formatting/status checks.
- Assistant
The diff is clean and limited to waiter bookkeeping. As a final concurrency check, I’ll run the key multi-conflict regression under Go’s race detector; this specifically exercises notification, retry, queue movement, and wake-up interleavings.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →