Repository navigation
memdb: compact the values left in mostly dead blocks - #53
Merged
Merged
Conversation
A block's logs stay in the WAL while it holds a value, and so do the logs of every block that deletes from it, and of those that delete from them: a delete must outlive the put it deletes. A value kept for long, a session's row, a message waiting on a subscriber away, then keeps the logs of most blocks written after it, in a store that rewrites and deletes its keys. A server's message store on v0.7.0 kept every log since it started, about 12 a minute idle; another, 1,379 logs for 1,644 keys, each block held by one value or chained to one. Compact moves the values left in blocks whose values take up at most half their data to the current block, so that those blocks hold none and go, with the logs that waited on them. A value moves under its key's index lock, as a put does: a put or delete of the key waits, other writes go on, and a key put again or deleted since it was listed doesn't move. The engine's own memdb doesn't compact: it finds an entry by its block. The server's message store compacts at open and every minute. A test store that kept 152 logs for one value keeps 1 after compacting, moving 2. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The test failed now and then (1 in 30 runs, and in CI): "Compact moved 1; want none". A write goes to the block of the log's last rotation, every log interval, not to the block of the time it is made; a round of writes made as a block began could put its first writes in the block before. Split between two blocks, a round left one mostly dead, which Compact rightly moved. Each round now starts a few log intervals into a new block, with blocks of 50 ms, far longer than a round. 200 runs pass. Co-Authored-By: Claude Opus 5.5 (1M context) <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.
Adds
memdb.DB.Compact, which frees the WAL logs that long-kept values hold, and runs it in the server's message store.The problem
CompactPutdoes. A put or delete of that key waits; other writes carry on. A key put again or deleted since it was listed doesn't move.Varzreports compactions and values moved.The server's message store compacts at open and every minute.
Tests
Compactmoved 2 values and left 1 log; all values read correctly after a reopen.Compactis now one of its operations.-race -tags lockcheckpass; so do the engine, the server under-race, and e2e.🤖 Generated with Claude Code