Skip to content

fix(lock): a node that loses to a lower slot leaves a waiting mark so holders give it a turn - #143

Merged
mattmattox merged 1 commit into
mainfrom
claude/lock-waiting-mark
Nov 14, 2026
Merged

mattmattox merged 1 commit into
mainfrom
claude/lock-waiting-mark

Conversation

@mattmattox

Copy link
Copy Markdown
Contributor

Fixes the starvation found in the #135 review: a higher slot waiting while a lower slot re-claims right after each cache expiry. The waiting-mark idea comes from the extent-trees author, with one change. A holder does not yield on every release once it sees a mark. Instead its turn runs 250 ms from the first sighting, across fresh claims, and then ends with the usual 50 ms yield. This keeps batching under contention and bounds the wait to about 300 ms per holder ahead.

Marks conflict with nothing, so the safety and no-cycle arguments are unchanged. A mark counts only while its writer is alive in the registry and is still its occupant (without a registry, until it is stale). A dead waiter's mark is ignored, and adoption clears it.

Evidence (.68):

  • The lock-level repro fails with the old clear-on-lose behavior (higher slot times out) and passes in about 100 ms per wait. All four mutations fail.
  • 1–4 node probe, 2 runs each against main b5d1825: same totals and wait shares.
  • The perf(alloc): free uncounted blocks under the bitmap lock alone, once per operation #135 cross-node stress does not reproduce on .68 even without the fix.
  • TestMultiNodeRestartKeepsPeerJournal fails 1 of 5 runs on main as well. The test reads files right after the replay starts. Not fixed here.
  • The 2-node VM suite is running.

🤖 Generated with Claude Code

… holders give it a turn

A node in a higher slot that lost a claim cleared its slot and only polled.
A lower slot that released a lock and claimed it again right after its
cached hold expired never saw the waiter, and its turn restarted with every
claim, so the higher slot could wait until the 30 s timeout.

The loser now writes a waiting mark, which conflicts with no claim. A
holder that wins a claim and sees a live node's mark ends its turn 250 ms
after it first saw one, even across fresh claims, then yields for YieldGap.
Marks count only while their node is alive in the registry (or, without a
registry, until they are stale), and the waiter clears its mark when its
Acquire ends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mattmattox
mattmattox merged commit 20ee91e into main Nov 14, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant