Repository navigation
Invalidating keys removes them from the disk order by key, not by walking it - #454
Merged
matrixarkai merged 3 commits intoNov 14, 2026
Merged
Conversation
…king it `invalidate_keys_locked` took the named keys out of the SSD order with `retain`, which visits every entry in the order. One invalidation therefore cost as much as the number of entries on disk, however few keys it named, and a write into a cache with a large disk tier paid it per key. Every other site that drops a disk entry already removes it by key, in constant time. Each named key now leaves the order by its own handle. What survives, and in what order, is the same: the new test keeps the walk as the oracle and compares at batch sizes either side of the eight the old code switched to a set at, with keys the cache never held. The set switch is gone with the walk it served. A source guard pins that the batched path does not walk the order again. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ves-the-disk-order-by-key
matrixarkai
added a commit
that referenced
this pull request
Nov 14, 2026
…, not by walking it (#456) Staging a batch for the SSD tier removed the batch's keys from the disk order with `retain`, which visits every entry in the order, and then pushed them back at the end. One batch therefore cost as much as the number of entries on disk, however few keys it staged. This is the same walk that `invalidate_keys_locked` used to do before #454, on the write path. Each staged key now leaves the order by its own handle and is pushed back as before, so the keys that were not in the batch keep their places and the batch follows them in the order it was staged. The batch's keys are unique (`staged_ssd_positions` collapses repeats), so this removes exactly what the walk removed. The set switch at eight keys is gone with the walk it served. Tests: the order after a batch is compared with the order the walk would have left, at batch sizes either side of eight, for rewritten keys, and for a mix of rewritten and new keys; the test passes on the old code as well as the new, which is what makes it an oracle. A source guard pins that the batch path does not walk the order again. Co-authored-by: Claude <noreply@anthropic.com>
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.
invalidate_keys_lockedtook the named keys out of the SSD order withretain, which visits every entry in the order. One invalidation therefore cost as much as the number of entries on disk, however few keys it named. Every other site that drops a disk entry already removes it by key, in constant time; this one now does too. What survives, and in what order, is unchanged.Measured (one
invalidateof a key, SSD-only cache, median of the best of 3 passes of 300; a debug build, so read the shape, not the microseconds):The walk grows with the disk tier (about 12x for 16x the entries); the per-key removal is flat. At 1,000 entries the new code measures slightly slower, which is within the noise of a debug build; I did not chase it. In a TemporalStore shared-store harness profile this call was 75.9M instructions over 6,400 invalidations, but that corpus is small, so the table above is the evidence for the scaling.
Tests (
src/tests/invalidate_disk_order.rs): the survivors and their order equal what a walk keeping every unnamed key would leave, at batch sizes 1, 2, 7, 8, 9 and 40 plus a key the cache never held, and the order and the index hold the same keys; a source guard pins that the batched path does not walk the order again (a behavioural test cannot see a walk that finds the right answer). Two planted defects are caught: the walk restored (caught by the guard) and only the first key removed (caught by the equivalence test).Checks:
cargo test --lib: 861 pass, 0 fail on this branch; 859 pass on main (the two extra are these tests).🤖 Generated with Claude Code