Skip to content

feat(compaction): reclaim crash orphans + RFC0009.4 crash-recovery test - #206

Merged
jensholdgaard merged 4 commits into
mainfrom
feat/compaction-rfc0009-4-crash-orphan-gc
Jun 14, 2026
Merged

feat(compaction): reclaim crash orphans + RFC0009.4 crash-recovery test#206
jensholdgaard merged 4 commits into
mainfrom
feat/compaction-rfc0009-4-crash-orphan-gc

Conversation

@jensholdgaard

@jensholdgaard jensholdgaard commented Jun 14, 2026

Copy link
Copy Markdown
Owner

What

Closes the RFC0009.4 (crash safety) §5 evidence gap for background compaction (epic #94) — the one criterion with implementation but no acceptance test.

Why

Compaction's only commit point is the atomic manifest.json generation swap, so a crash always freezes a partition at a clean generation (the no-torn-read half is atomic_publish_is_never_torn_across_the_swap, RFC0009.3). The missing half: the dead files a crash leaves — superseded inputs the post-commit GC never reached, a pre-commit consolidated file, or an interrupted *.parquet.tmp publish — must be reclaimable (the Manifest doc itself says manifest-excluded files "are orphans awaiting GC").

Changes

  • ourios-parquet gc_orphans(partition_dir) -> OrphanGc — manifest-authoritative reclamation: a *.parquet not named by the manifest is provably dead; with no manifest the glob is the live set so only stray *.parquet.tmp are orphans. Idempotent; never unlinks a live file.
  • RFC0009.4 test — builds the exact on-disk state a SIGKILL would leave at each commit point (pre-swap, post-swap-pre-GC, stray .tmp/no-manifest) and asserts orphans are reclaimable, reads stay at a clean pre-/post-generation, and live files are untouched. Faithful because the commit is a single rename.
  • Sweep wiringrun_sweep reclaims a candidate partition's prior-crash orphans (SweepReport.orphans_reclaimed).

Invariants (CLAUDE.md §3)

§3.6 (object storage source of truth) / RFC0009.2-.3 unaffected: gc_orphans only removes manifest-excluded files (provably dead), never a live row. Row conservation (RFC0009.2) and atomicity (RFC0009.3) tests stay green.

Verification

cargo fmt --check, cargo clippy -p ourios-parquet -p ourios-ingester --all-targets --all-features -D warnings, and both crates' full test suites pass locally.

Part of driving RFC 0009 specified → green; next: RFC0009.1 (post-compaction file-size histogram) + RFC0009.6 (union-schema merge).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added orphan file garbage collection during compaction sweeps to reclaim unused storage space.
    • Implemented crash-safe cleanup logic that handles partial compaction scenarios and temporary file removal.
  • Improvements

    • Enhanced reporting to track the number of orphan files reclaimed per sweep operation.

Closes the RFC0009.4 (crash safety) §5 evidence gap. The commit point is
the atomic manifest swap, so a crash always freezes a partition at a clean
generation (RFC0009.3); the missing half was that the dead files a crash
leaves — superseded inputs the post-commit GC never reached, a pre-commit
consolidated file, an interrupted `*.parquet.tmp` publish — are
*reclaimable*.

- `gc_orphans(partition_dir)` in ourios-parquet: manifest-authoritative
  reclamation (a `*.parquet` not named by the manifest is provably dead;
  no manifest ⇒ glob ⇒ only stray `*.parquet.tmp` are orphans). Idempotent;
  never unlinks a live file. Returns `OrphanGc { reclaimed, failures }`.
- RFC0009.4 test: builds the on-disk state a SIGKILL at each commit point
  would leave (pre-swap, post-swap-pre-GC, stray `.tmp` / no manifest) and
  asserts orphans are reclaimable while reads stay at a clean generation
  and live files are untouched. Faithful because the only commit is one
  `rename`.
- Wired into the ingester sweep (`SweepReport.orphans_reclaimed`) so a
  prior crash's orphans are reclaimed on the next sweep.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jensholdgaard
jensholdgaard requested a review from Copilot June 14, 2026 22:03
@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@jensholdgaard, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 42 minutes. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

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.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3c8bf86c-661f-4a1d-9670-46d76d089f07

📥 Commits

Reviewing files that changed from the base of the PR and between 6061861 and 4fecaad.

📒 Files selected for processing (2)
  • crates/ourios-ingester/src/compactor.rs
  • crates/ourios-parquet/src/compaction.rs
📝 Walkthrough

Walkthrough

Adds orphan file garbage collection to the sealed-partition compaction path. OrphanGc and gc_orphans are introduced in ourios-parquet, using an optional manifest.json to determine the live set and unconditionally treating *.parquet.tmp as dead. The ingester compactor's run_sweep now calls gc_orphans per candidate partition, accumulating results in a new orphans_reclaimed field on SweepReport.

Changes

Orphan GC for sealed-partition compaction

Layer / File(s) Summary
OrphanGc struct, gc_orphans implementation, re-exports, and crash-safety tests
crates/ourios-parquet/src/compaction.rs, crates/ourios-parquet/src/lib.rs
Defines OrphanGc { reclaimed, failures }, implements gc_orphans which scans a partition directory and uses manifest.json (when present) as the authoritative live set while always treating *.parquet.tmp as dead, adds RFC0009.4 crash-safety tests for three scenarios (post-commit, pre-manifest-swap, no-manifest stray tmp), and re-exports both items from the crate root.
Compactor sweep wiring and metrics test fixture
crates/ourios-ingester/src/compactor.rs, crates/ourios-ingester/src/metrics.rs
Imports gc_orphans, adds pub orphans_reclaimed: u64 to SweepReport, calls gc_orphans before each partition compaction in run_sweep accumulating reclaimed counts and soft-appending errors without aborting, and updates the test SweepReport fixture with orphans_reclaimed: 0.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

  • jensholdgaard/ourios#101: Introduced the compactor/sweep runner scaffold in crates/ourios-ingester/src/compactor.rs that this PR extends to call gc_orphans.
  • jensholdgaard/ourios#96: Added the ourios-parquet::manifest module/API that gc_orphans relies on to determine the live parquet file set.
  • jensholdgaard/ourios#110: Also extends SweepReport and modifies the run_sweep per-partition outcome handling in the same compactor file.

Poem

🐇 Hop, hop through the partition lane,
Old .parquet.tmp files, gone in vain!
The manifest says who's live today,
Orphaned shards are swept away.
gc_orphans cleans the nest—
This bunny's compactor does its best! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the main changes: adding orphan reclamation for crash safety and the RFC0009.4 crash-recovery test, which are the core objectives of this PR.
Description check ✅ Passed The description is comprehensive and well-structured, covering the What, Why, Changes, and Invariants sections with clear explanations. However, the provided template requires a Checklist section with verification items.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/compaction-rfc0009-4-crash-orphan-gc

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 and usage tips.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds crash-orphan reclamation to the compaction subsystem and introduces an RFC0009.4 acceptance test to close the crash-safety evidence gap around post-crash cleanup behavior.

Changes:

  • Introduces gc_orphans(partition_dir) -> OrphanGc to reclaim manifest-excluded *.parquet and stray *.parquet.tmp files safely.
  • Adds an RFC0009.4 test that constructs crash-point on-disk states (pre-swap, post-swap/pre-GC, and no-manifest stray .tmp) and validates reclaim + read correctness.
  • Wires orphan GC into ourios-ingester sweep execution and extends metrics tests for the expanded SweepReport.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
crates/ourios-parquet/src/lib.rs Re-exports gc_orphans / OrphanGc from the compaction module.
crates/ourios-parquet/src/compaction.rs Implements orphan GC + adds RFC0009.4 crash-recovery test coverage.
crates/ourios-ingester/src/metrics.rs Updates SweepReport test fixture to include the new field.
crates/ourios-ingester/src/compactor.rs Runs gc_orphans for each candidate partition and tracks reclaimed count in SweepReport.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/ourios-parquet/src/compaction.rs
Comment thread crates/ourios-parquet/src/compaction.rs Outdated
Comment thread crates/ourios-ingester/src/compactor.rs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/ourios-ingester/src/compactor.rs`:
- Around line 82-86: The orphans_reclaimed field accumulated in run_sweep is not
being published to telemetry by CompactionMetrics::record_sweep, making the
crash recovery path invisible operationally. Update the record_sweep method to
emit orphan-file telemetry for the orphans_reclaimed field alongside the
existing gc_failures metric—either by folding it into an existing instrument or
creating a dedicated one. Then add an assertion in the metrics test to verify
that this metric is being recorded when orphans are reclaimed during a sweep.
- Around line 173-179: The gc_orphans function is only being called on
partitions after they pass the plan_candidates filter, which excludes partitions
with fewer than two live files. However, the crash states this code is meant to
recover from result in partitions with exactly one live file (either a
consolidated file after manifest swap, or one parquet file with a stray tmp
file), which are filtered out before reaching the gc_orphans call. Move the
gc_orphans execution to run across all sealed partitions before the
plan_candidates filtering step, or execute it via a separate sealed-partition
scan that is independent of candidate filtering. Additionally, add a sweep-level
regression test that validates these one-live-file partition cases are properly
handled, building on the existing
rfc0009_4_orphans_reclaimable_and_live_files_untouched test patterns.

In `@crates/ourios-parquet/src/compaction.rs`:
- Around line 311-316: Update the `# Errors` documentation section for the
`gc_orphans` function to include `CompactionError::Manifest` as a documented
error case. Currently, the documentation only mentions `CompactionError::Io` for
directory scan failures, but the function can also fail when reading or parsing
the manifest before the directory scan begins. Add a statement documenting that
manifest read/parse failures will result in `CompactionError::Manifest` being
returned, ensuring the documented error contract matches the actual
implementation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5472e694-05cc-4b55-9719-1298cb1673ad

📥 Commits

Reviewing files that changed from the base of the PR and between bd05edf and 6061861.

📒 Files selected for processing (4)
  • crates/ourios-ingester/src/compactor.rs
  • crates/ourios-ingester/src/metrics.rs
  • crates/ourios-parquet/src/compaction.rs
  • crates/ourios-parquet/src/lib.rs

Comment thread crates/ourios-ingester/src/compactor.rs
Comment thread crates/ourios-ingester/src/compactor.rs
Comment thread crates/ourios-parquet/src/compaction.rs Outdated
jensholdgaard and others added 2 commits June 15, 2026 00:11
… too_many_lines)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- mark OrphanGc #[non_exhaustive] (forward-compat for the new pub struct)
- gc_orphans # Errors doc: also documents CompactionError::Manifest
- sweep gc-orphans error now names the partition, not just the tenant

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@jensholdgaard
jensholdgaard merged commit 9c418b6 into main Jun 14, 2026
12 checks passed
@jensholdgaard
jensholdgaard deleted the feat/compaction-rfc0009-4-crash-orphan-gc branch June 14, 2026 22:25
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.

2 participants