Repository navigation
#740 Fix the lower-bound guard's surviving twin in RemoveIterative, and widen IXW-03 to cover it - #766
Merged
Conversation
…nd widen IXW-03 to cover it PR #745 replaced `key < leaf.firstKey` with a comparison against the previous leaf's HighKey on the insert side, and left the identical predicate standing in RemoveIterative. Both were written by the same change (#737), one was found wrong, one was fixed. BTree.Remove.cs:610 carried `count > 0 && key < firstKey && previous.IsValid` verbatim until this commit, and KeyBelowLeafLowerBound had five uses in BTree.Insert.cs against zero in Remove.cs and zero in Move.cs. The predicate fails for the same reason it failed on the insert side: a leaf's first key equals the separator routing to it only until something is removed from the front, after which the band prevHighKey <= key < firstKey is one the leaf IS authoritative for. Answering "not authoritative" there releases the latch and re-descends to the same leaf. It is NOT single-threaded reachable, and the difference from #740 is worth stating because it was asserted the other way before it was tested. TryRemoveOlc answers NotFound from the optimistic descent before its count check, so an absent key never arrives at the pessimistic guard at all. Reaching it needs the descent to FIND the key, the leaf underfull enough to defer to the pessimistic path, and a concurrent writer to raise the leaf's first key above it in between — concurrency-gated, and the #738 class rather than #740's. That is also why this ships without a red-to-green regression test. RemoveAbsentKeyBelowLeafFirstKey_ReportsNotFound is included because the coverage is real and was missing — double-remove across every leaf boundary of a 2,000-key tree, with a consistency check either side — but it passed before this change as well as after, and its remarks say so. Presenting it as proof of the fix would be the same "green means verified" error the assessment condemns. The justification here is the invariant, not the test. Verified against the race harness instead: four runs, 41,934 iterations, no hangs, no crashes, failure counts unchanged from baseline. Full suite 5,116 passed with five failures, all in the known flake band and none in indexing. IXW-03 scoped itself to BTree.Insert.cs alone — the rule written to stop this exact drift did not cover its own twin, and shipped that way for a day. Its scope now names Remove.cs and Move.cs, and it carries an explicit gap note: Move.cs performs leaf inserts with no lower-bound guard at all, which is not a drifted copy but a missing one. Collapsing the five hand-maintained leaf-insert copies onto one authority is the only fix that scales, and it is #765 step S2.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR #745 replaced
key < leaf.firstKeywith a comparison against the previous leaf'sHighKeyon the insert side — and left the identical predicate standing inRemoveIterative. Both were written by the same change (#737); one was found wrong, one was fixed.Why it is wrong
A leaf's first key equals the separator routing to it only until something is removed from the front. After that, the band
prevHighKey <= key < firstKeyis one the leaf is authoritative for; answering "not authoritative" releases the latch and re-descends to the same leaf.Why it ships without a red-to-green test — read this part
It is not single-threaded reachable, and I asserted it was before testing it.
TryRemoveOlcanswersNotFoundfrom the optimistic descent before its count check, so an absent key never arrives at the pessimistic guard. Reaching it needs the descent to find the key, the leaf underfull enough to defer, and a concurrent writer to raise the leaf's first key in between. Concurrency-gated — the #738 class, not #740's.RemoveAbsentKeyBelowLeafFirstKey_ReportsNotFoundis included because the coverage is real and was missing (double-remove across every leaf boundary of a 2,000-key tree, consistency-checked either side) — but it passed before this change as well as after, and its remarks say so in the source. Presenting it as proof would be the same "green means verified" error the assessment condemns. The justification is the invariant, not the test.Verified against the race harness instead: 4 runs, 41,934 iterations, 0 hangs, 0 crashes, failure counts unchanged from baseline. Full suite 5,116 passed / 5 failed, all known flake band, none in indexing.
IXW-03 did not cover its own twin
The rule written to stop this drift scoped itself to
BTree.Insert.csalone, and shipped that way for a day. Scope now namesRemove.csandMove.cs, plus an explicit gap note:Move.csperforms leaf inserts with no lower-bound guard at all — not a drifted copy but a missing one. Collapsing the five hand-maintained leaf-insert copies onto one authority is #765 step S2.Assessment: #765.