Repository navigation
feat(store): store compact rewrites a closed store without dead terms - #825
MathiasVDA wants to merge 5 commits into
Conversation
…#759) Following DR 0013 §1 and §4. Store::compact opens the closed store and counts the live ordinals: those that some quad uses. It renumbers each live ordinal by its rank, through a bitset with a count every 512 ordinals, so no map of every term is built. It then writes checkpoint n+1 with: - the live keys, copied in order as one dictionary piece, with its index; - the saved geometries, read by their old ordinals; - every permutation sorted again by the bulk load's sorter, under the memory limit. The old checkpoint stays current until CURRENT names the new one, so a crash leaves the store as it was. The log is folded in, as by any checkpoint. `tripletrail store compact --location --dataset [--memory-limit]` runs it.
…s; churn example compacts (#759)
|
The red Generated by Claude Code |
|
Changes requested at bfcdbb5. The core is right: rank renumbering, the checkpoint path, the crash rule and the three deviations from DR 0013 are fine with me (the DR text should follow, I note it on enterprise#131). I also ran a harder variant of your release test, because its dead term is the newest one and so no id moves: on every release fixture I served the dataset (so the routing network and spatial index are saved), deleted Two must-fix items. 1. Compacting a dataset whose files are of an older version upgrades it with no way back. 2. The whole live dictionary is copied onto the heap, whatever Small: the doc comment of
Generated by Claude Code |
Review of #825: - store compact refuses a dataset whose files are of an older version instead of upgrading it with no restore point: run store upgrade first. - Dictionary::keep writes the kept keys to a mapped spill file as it reads them, and the old ordinal of a new one comes from Ranks::select, so the heap holds a bit per term besides the sort. - The release test serves each fixture first, leaves about 400 early terms dead and compares the fixture queries and a full dump; a new test checks the refusal and compaction after store upgrade. - Doc comments of store_upgrade and from_pieces back on their functions. Refs #759
|
Approved at 6c1841f. Both must-fix items are done: For #760: the automatic run needs the same rule for an older dataset, as noted on the decision record (tripletrail-enterprise#131). Generated by Claude Code |
Requested by Mathias · project thread
Closes #759
Phase 2 of #757, following decision record 0013 §1 and §4 (tripletrail-enterprise PR #131). Running inside the server is #760.
What
Store::compact(dir)andtripletrail store compact --location DIR [--dataset ds] [--memory-limit SIZE]rewrite a closed store with only the terms its quads still use.Ranksincompact.rs). A live ordinal's new number is the count of live ordinals up to and including it. Au32count every 512 ordinals keeps this cheap; no map of every term is built. The map is monotone, so key order is kept.Disk::checkpoint(…, rewrite = true), the same pathstore upgradetakes:Dictionary::keepcopies the live keys in order as one piece, as stored, with the same namespaces, and the piece's index is rebuilt;encode_geometry) and copied;stats.bin) is sorted again by the bulk load'sSorter, with spill under the memory limit.CURRENTnames checkpointn+1only once it is complete. Until then the old checkpoint is untouched, and an unfinished one is removed at the next open, as a stale checkpoint is. The old log is retired at its full length, as at any checkpoint. Once compacted, the store's writer is dropped, so nothing more is written from the old data held in memory.A store without dead terms is left as it is. The output is the current format; there is no new magic.
Differences from DR 0013, for the reviewer
compact-<n>/scratch name. The checkpoint is written straight ascheckpoint-(n+1), the way every checkpoint andstore upgradewrite theirs. The crash rule is the same (CURRENTflips last, and a checkpointCURRENTdoesn't name is removed at open). For feat(server): compact the dictionary by itself in the background, and from POST /$/compact #760's online catch-up, a scratch name may still pay off.namespaces.binis kept, not rebuilt. Compact IRI keys refer to namespaces by number, so rebuilding them would mean rewriting those keys. The table is small.Measured
examples/dict_churn.rs(1M triples, 10 rounds each replacing a tenth, release build) now compacts at the end and also loads the same quads fresh:dict*.binandgeoms*.binmatch a fresh load exactly, which meets the acceptance criterion. The segments are 18 % larger than a fresh load's, because ordinal order differs (DR 0013 §1: equal "up to ordinal order").Tests
crates/tripletrail-store/tests/compact.rs:dict*.bin+geoms*.binwithin 3 % of a fresh load;Ranksunit test.crates/tripletrail-server/tests/upgrade_in_place.rs,every_release_is_compacted_with_the_same_answers: each release fixture gets a dead term, runsstore compact, then is served. It gives the release's answers (spatial and routing queries included), is up to date, and takes a write.tests/offline.rs,store_compact_drops_dead_terms: the CLI output, the same dump, a second run that has nothing to do, and an unknown dataset refused.11 of 108 terms dropped).Local results:
cargo test -p tripletrail-store: all pass--test offline,--test upgrade_in_place(the compaction test), andGUIDE_CHAPTER=11 --test guide: pass-D warnings(store, server): cleanapi_surfacelisting is updated for the new subcommandDocs
tdb2.tdbcompactrow and a section with the example.There is no
docs/cli.md; CLI commands are documented in docs/server.md.Generated by Claude Code