feat(storage): expose compaction via StorageEngine::compact()#4
Open
emanzx wants to merge 1 commit into
Open
Conversation
Add compact() to the StorageEngine trait (default no-op), overridden by the pagedb-backed engine to call pagedb::Db::compact_now() and map CompactStats to a lite-owned CompactionOutcome. Add a NodeDbLite::compact() forwarder. In-memory engine keeps the no-op default. Lets consumers reclaim deferred-free space / bound on-disk growth between writes. Requires pagedb compact_now() to be Send-callable (NodeDB-Lab/pagedb#4). Addresses NodeDB-Lab/pagedb#2 (compaction not exposed to consumers).
64eb6e1 to
4d6e588
Compare
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.
What
Adds a
compact()method to theStorageEnginetrait so consumers can trigger storage compaction. The pagedb-backed engine overrides it to callpagedb::Db::compact_now(), draining the deferred-free list and truncating the file to bound on-disk growth. In-memory/test engines inherit a default no-op.StorageEngine::compact()— new trait method, default no-op returning a zeroCompactionOutcome.PagedbStorage::compact()— callscompact_now(), mapspagedb::CompactStatsinto a lite-ownedCompactionOutcome(reclaimed_pages/segments_repacked/file_bytes_freed).NodeDbLite::compact()— public forwarder.CompactionOutcomeis lite-owned (not a pagedb type) so the trait doesn't force pagedb types onto non-pagedb engines.Why
Previously
compact_now()lived inside pagedb with no path to it throughStorageEngine, so consumers writing one-commit-per-entry had no way to reclaim space and watched the file grow unbounded. This is the consumer-facing half of the reclamation work — the pagedb side landed in NodeDB-Lab/pagedb#4 and #5.Requires pagedb
compact_now()to beSend-callable (NodeDB-Lab/pagedb#4). Addresses the "compaction not exposed to consumers" half of NodeDB-Lab/pagedb#2.Testing
compact_mem_is_ok_noop— in-memory engine: compact is a successful no-op, data intact afterward.compact_default_disk_is_ok— disk engine: churn (200 writes + 150 deletes) -> compact -> surviving key still readable; outcome fields well-formed.Both green against current pagedb
main(dad7f26).