Repository navigation
Conversation
tefkah
marked this pull request as ready for review
October 21, 2026 20:09
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.
Stacked on #69 (leveled packs), which is stacked on #71. Merge them in order, pointing each at
mainonce the one below is in.The index split ("c3x" in the daily-updates simulation: Layout F Daily Updates). In a leveled collection, the index (the layered runs) now serves only level 0. Each pack in a level or in the history carries its own index. Level merges write no index layer. The history is leveled like the current versions. The design note in meta is
planning/kf/underlay/leveled-packs-design.md.Leveled reads stay flat however many versions pile up; index runs no longer hold an entry for every copy of every record. The simulation puts it at 19 GETs per leaf at the median after three years, against #69's 28.
Measured locally (real code, about 1/64 scale)
200,000 records of about 500 B (102 MB), loaded in key order as the bottom level, then 365 days of 2,000 random changes each (1%). It counts a cold read of 1,000 consecutive current records, 20 leaves per checkpoint. Packs were 2 MB, so a leaf is smaller than a pack, as in production. Script:
bench-split.mts, in the session folder; #69 ran the same withbench-leveled.mts.How it works
layers/<pack>i) is written beside the pack, after it (PackInfo.indexed). Merges and the upload writer write one. Commits' packs don't, since they only ever sit in level 0.#findLeveled):stats.indexStalecounts them: a pack merged down adds its records, and so does a sorted load adopted as the bottom level. The count only ever overestimates.levelConfig.staleEntries(50k), every run merges at once. The merge drops entries whose pack is in a level, in the history, retired or gone. An unlisted pack's entries stay, because an upload's packs are adopted only after its commit's runs are in. The merge is the index's size, which is level 0 plus the stale entries. It settles the count.Manifest.historyis the history's level 0; levelsh1–h6are listed in shards like the current ones. A history merge keeps every copy, one of each key, so an old version's lookup reads a pack per level, not one per month. This replaces Layout F: leveled packs, with replaced versions in history packs #69's history packs in the registry (and the monthly compaction it left for later).reclaimRewrite(ids, mark). The server's rewrite job runsmarkRangeover the retained versions.push_packs.lo_key/hi_keyare stored as JSON. SQLite text ends at a key's first NUL, so a sorted load's bottom level got the range"Doc"–"Doc". Layout F: leveled packs, with replaced versions in history packs #69 hid it because the index served every lookup.Not in this PR
testing/,scale-testing), checked against the simulator, is still the next measurement.Tests
test/repo/leveled.test.ts:UNDERLAY_TEST_LEVELED=1.Deploy
Migration
0029_push_pack_indexed(push_packs.indexed, nullable) goes with or before the deploy, after #69's0028.LEVELED_PACKS=1, as in Layout F: leveled packs, with replaced versions in history packs #69.indexStalereturns to 0 after each merge down; its index stays around level 0's size;levelRewritesrises with reclaims.