Skip to content

feat(storage): expose compaction via StorageEngine::compact()#4

Open
emanzx wants to merge 1 commit into
NodeDB-Lab:litefrom
emanzx:feat/expose-compaction
Open

feat(storage): expose compaction via StorageEngine::compact()#4
emanzx wants to merge 1 commit into
NodeDB-Lab:litefrom
emanzx:feat/expose-compaction

Conversation

@emanzx

@emanzx emanzx commented Jun 14, 2026

Copy link
Copy Markdown

What

Adds a compact() method to the StorageEngine trait so consumers can trigger storage compaction. The pagedb-backed engine overrides it to call pagedb::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 zero CompactionOutcome.
  • PagedbStorage::compact() — calls compact_now(), maps pagedb::CompactStats into a lite-owned CompactionOutcome (reclaimed_pages / segments_repacked / file_bytes_freed).
  • NodeDbLite::compact() — public forwarder.

CompactionOutcome is 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 through StorageEngine, 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 be Send-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).

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).
@emanzx emanzx force-pushed the feat/expose-compaction branch from 64eb6e1 to 4d6e588 Compare June 15, 2026 06:18
@emanzx emanzx marked this pull request as ready for review June 15, 2026 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant