Skip to content

Measure segment liveness in bytes - #21

Merged
venkat1701 merged 4 commits into
mainfrom
fix/compaction-live-bytes
Oct 4, 2026
Merged

venkat1701 merged 4 commits into
mainfrom
fix/compaction-live-bytes

Conversation

@venkat1701

Copy link
Copy Markdown
Collaborator

Closes #7

Compaction used to count live node images, but images range from 64 bytes to a whole page, so a segment full of dead big leaves could look half alive. Stored references now carry the image size in 64-byte units (one varint, at most 3 bytes per reference). The liveness walk sums real bytes from the references alone, without reading any page, and compaction_live_ratio now compares live bytes with allocated bytes.

With an honest measure more segments qualify, and relocating several at once held the commit lock long enough to visibly slow ingest. So the background pass now relocates only the emptiest qualifying segment per pass. COMPACT still does all of them.

This changes the on-disk format (every reference gained a field), so FORMAT goes to 3 and older directories are refused with the usual message. Nothing is released yet, so I didn't write a migration.

Numbers, scale 4 async with only HStore running:

  • Disk after shutdown: 2,362 MiB on main. With this branch it was 1,741 MiB on the first run and 1,948 MiB with the one-segment-per-pass limit.
  • Throughput: I couldn't compare it fairly. Other containers kept the machine at a load average around 26 during these runs, and even ingest.nodes, which never compacts, came out at half its usual rate. Worth rerunning on a quiet box before reading anything into ingest speed.

The compaction test now also checks that liveness comes back in bytes, as whole 64-byte units and never more than the segment's allocation. Full ./mvnw install passes locally.

Stored references now carry the image size, so the liveness walk sums
real bytes without reading pages, and compaction_live_ratio compares live
bytes with allocated bytes instead of counting node images. Background
passes relocate only the emptiest qualifying segment so a single pass
can't hold the commit lock for too long. The storage format moves to 3
because every reference gained the size field.
@venkat1701
venkat1701 force-pushed the fix/compaction-live-bytes branch from dda6661 to 04c15d7 Compare October 4, 2026 08:13
@venkat1701
venkat1701 merged commit 86fc2d8 into main Oct 4, 2026
@venkat1701
venkat1701 deleted the fix/compaction-live-bytes branch October 6, 2026 00:54
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.

Compaction counts live images, not bytes

1 participant