Skip to content

fix: free large-value segment pages on full-partition Truncate - #486

Open
thweetkomputer wants to merge 1 commit into
mainfrom
fix/truncate-segment-leak
Open

fix: free large-value segment pages on full-partition Truncate#486
thweetkomputer wants to merge 1 commit into
mainfrom
fix/truncate-segment-leak

Conversation

@thweetkomputer

Copy link
Copy Markdown
Collaborator

Problem

Truncate's full-partition fast path (empty position) iterated only the data mapper and FreePage'd its pages — it never touched the segment mapper. For a partition holding large values the segment mapping stayed fully populated, so the empty snapshot flushed by UpdateMeta serialized it verbatim:

  • GC's manifest replay kept every segment file alive forever (only DropTable would reclaim them);
  • segment compaction counted them as live, so amplification never triggered;
  • the stale segment mapping was copied into every later archive/branch snapshot.

Reads correctly saw an empty partition, so this is a silent space leak (disk and cloud) + snapshot pollution, not a correctness bug. The partial-truncate path already frees these via DelLargeValue.

Fix

Free the segment pages too, mirroring the data-mapper loop, so the flushed segment mapping is empty and GC reclaims the files. The empty-snapshot flush serializes the current segment mapping (not deltas), so no delta recording is needed.

Test

large_value_gc: full-truncating a partition of pinned large values leaves no segment files after GC. Verified it fails without the fix (the files are retained).

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@thweetkomputer, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 23 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1f61a53b-9b50-43cd-bde6-d69cf98dc4c0

📥 Commits

Reviewing files that changed from the base of the PR and between e8cd94e and b44e74f.

📒 Files selected for processing (2)
  • src/tasks/batch_write_task.cpp
  • tests/large_value_gc.cpp
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/truncate-segment-leak

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Truncate's full-partition fast path (empty position) iterated only the
data mapper and FreePage'd its pages, never touching the segment mapper.
For a partition holding large values the segment mapping stayed fully
populated, so the empty snapshot flushed by UpdateMeta serialized it
verbatim: GC's manifest replay kept every segment file alive forever
(only DropTable would reclaim them), and the stale mapping was copied
into every later archive/branch snapshot. The partial-truncate path frees
these via DelLargeValue.

Free the segment pages too, mirroring the data-mapper loop, so the
flushed segment mapping is empty and GC reclaims the files.

Regression test in large_value_gc: full-truncating a partition of pinned
large values leaves no segment files after GC (retained without the fix).
@thweetkomputer
thweetkomputer force-pushed the fix/truncate-segment-leak branch from 8170e9a to b44e74f Compare July 10, 2026 04:57
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