Repository navigation
Fix #297: OLC B+Tree concurrent insert/remove key loss - #304
Merged
Merged
Conversation
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.
Summary
Fixes #297 — OLC B+Tree concurrent inserts/removes silently losing keys under heavy parallel CPU pressure.
Engine fixes (
src/Typhon.Engine/Data/Index/)BTree.Remove.cs— Option D stale-separator detection inRemoveIterative: after Phase 1.5A version validation, ifnode.Nextis valid and key ≥HighKey, abort the write lock and restart. Stale-head/tail OLC checks in begin/end fast paths and pessimistic begin-fast-path. Snapshot-once on_reverseLinkListupdates.BTree.Insert.cs— CAS-init lock around the initialPushLast(prevents unsynchronized writes when concurrent threads observe a just-published_rootChunkId); root-split lock aroundnewRootwrites (prevents descent through a partially-constructed new root); defensive_reverseLinkListnull guard in tail-cache update.BTree.cs— B-link follow uses the actual leaf last key instead of staleHighKey.BTree.NodeWrapper.cs—SpillLeftSortInvariantHolds/SpillRightSortInvariantHoldsfor spill-path correctness asserts.String64BTree.cs— explicitHighKey[64]field +GetHighKey/SetHighKeyto maintainnode.HighKey == nextNode.firstKeyforString64keys (parity withIndex64Chunk/ L16/L32/L64).OlcDescentTrace.cs(new) — minimal diagnostic hooks (RecordStep,OnInvalidChunkId,OnRemoveNotFound). JIT short-circuits when null; near-zero production cost.Test infrastructure
OlcBTreeRaceStressTests.cs— new stress fixture, 5 scenarios under heavy parallel CPU pressure. HANG-safe iter cleanup, file-based progress logging, descent-ring dump onOnInvalidChunkId,OnRemoveNotFoundcapture.Results
Remove_Disjointsilent key lossKnown residual
Add_*scenarios show a ~0.08–0.40% silent-loss rate, suspected origin inHandlePromotedInsertspill paths for internal nodes. Out of scope for this PR — recommend follow-up issue once a deterministic repro lands.Test plan
Remove_*and AV regressions🤖 Generated with Claude Code