Skip to content

fix(gc): log the index versions a pass leaves, not the retention target - #2167

Merged
bplatz merged 2 commits into
mainfrom
fix/gc-retained-count
Oct 24, 2026
Merged

bplatz merged 2 commits into
mainfrom
fix/gc-retained-count

Conversation

@bplatz

@bplatz bplatz commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2163.

The GC completion line logged retained_count = keep_count. That value is 1 + max_old_indexes, so with the defaults it read 6 on every pass, even when the age guard left dozens of versions in storage. A pass that released nothing logged nothing at INFO, so a ledger held entirely by the age guard didn't show up at all.

Changes

  • Plan. plan_garbage returns a GarbagePlan instead of an Option. An empty plan releases nothing but still knows the chain length, so every path reports the versions it left (GarbagePlan::unreleased). As before, callers check is_empty() before they open a release window.

  • Stop reason. The chain walk records why it stopped: age_guard or unreadable_manifest.

  • Completion line. Garbage collection complete now logs:

    • retained: the chain length less the versions cleaned;
    • retention_target: 1 + max_old_indexes;
    • past_target;
    • stopped_by, when the walk stopped early.

    retained_count is gone.

  • Held passes. A pass that releases nothing while versions are past the target logs Garbage collection released nothing at INFO. It carries the same fields, plus min_time_garbage_mins.

  • Result. CleanGarbageResult.retained carries the count.

  • Docs.

    • background-indexing.md describes the new fields.
    • time-travel.md said txn: true stores a transaction's raw payload. No such option exists; the opt-in is TxnOpts::store_raw_txn.

retained counts the chain the pass planned from. It doesn't include versions published while the pass ran.

Tests

  • Harness. After every pass, the publish-then-GC harness checks that CleanGarbageResult.retained and the logged retained both equal the number of root objects in the store. It runs under three regimes: no age guard, a live guard that holds every version, and a live guard with a ceiling.
  • Log lines. Two existing tests now assert the new log fields:
    • the time-threshold test, for the held pass's INFO line;
    • the semantics test, for the completion line.

The completion line logged `retained_count = keep_count`, which is
`1 + max_old_indexes` on every pass. When the age guard stops the walk,
storage can hold dozens of versions while the line reads 6. A pass that
released nothing logged nothing at INFO, so a ledger held entirely by the
age guard did not show up at all.

- `plan_garbage` always returns a plan. An empty one releases nothing and
  carries the chain length, so every path can report the versions it left
  (`GarbagePlan::unreleased`).
- The walk records why it stopped: the age guard or an unreadable manifest.
- `Garbage collection complete` logs `retained` (the chain length less the
  versions cleaned), `retention_target`, `past_target` and `stopped_by`.
- A pass that releases nothing while versions are past the target logs
  `Garbage collection released nothing` at INFO with the same fields.
- `CleanGarbageResult.retained` carries the count.

Also corrects the time-travel docs, which said `txn: true` stores the raw
transaction. That flag does not exist; the opt-in is `TxnOpts::store_raw_txn`.
@bplatz bplatz added bug Something isn't working as expected area:storage Storage backends, nameservice, ledger lifecycle, index storage, caches labels Oct 23, 2026
@bplatz
bplatz requested a review from a team October 23, 2026 12:03

@aaj3f aaj3f 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.

@bplatz this is a clean, well-scoped fix, and at a design level no pushback from me. Reporting what a pass actually left, and saying so at INFO when the age guard held everything, is exactly what was missing when #2163 was reported.

One headline note, and it's a suggestion rather than a request: as far as I can tell neither this nor #2168 depends on the Delta work it's stacked on. This PR's commit applies cleanly onto main (git merge-tree with no conflicts), #2168 applies cleanly on top of that, and the only file the Delta stack under #2166 shares with either GC PR is docs/operations/configuration.md, in an unrelated section. So it may be worth rebasing both onto main, so they aren't waiting on the #2165/#2166 review, and so CI actually runs on them: the only check that ran on this head was the release plan job (no fmt, clippy or nextest). Your call, of course.

Claude-assisted review below:


✅ Approve.

Nice one. retained_count = keep_count is the kind of log line that makes an operator distrust a collector that's working fine, and this reports the real number on every path. Having plan_garbage always return a GarbagePlan that knows its chain length is the right shape for it: every early return (clean_garbage, the worker's GcPassContext::run including the no-release-window path, the reindex pass in admin.rs, and release_garbage_plan when the ledger has no index head) now reports retained instead of a zeroed CleanGarbageResult::default().

Since turning a None into an empty value is exactly where an empty guard can start releasing things, I checked that specifically. An empty plan has nothing in named (the walk only extends it alongside planned), so even a caller that skipped is_empty() and called release would release nothing; it fails closed. Dropping the index_chain.len() <= keep_count early return costs nothing either, since the chain walk had already happened before it, and the chain_len - keep_count in the "released nothing" line is only reachable once the loop has run, so it can't underflow.

On log volume, the new Garbage collection released nothing line is at most one INFO line per pass, the same cadence as the existing Successfully indexed ledger line per build plus the periodic tick, so I don't think that's a concern.

Adherence to repo commitments:

  • Patterns/abstractions: ✔ extends GarbagePlan and CleanGarbageResult rather than adding a parallel report; WalkStop replaces an Option that was carrying two meanings.
  • Performance (speed first, memory second): ✔ background GC only; no query or index-build path touched, and the removed early return came after the chain walk, so no extra I/O. No performance-degradation risk.
  • Deployment targets: ✔ host-neutral: a result field and log lines in the collector every host runs; nothing a serverless or wasm32 fence forbids.
  • Testing: ✔ the publish-then-GC harness now checks CleanGarbageResult.retained and the logged retained against the roots actually on disk under all three regimes, and the time-threshold and semantics tests assert the new fields. ⚠️ No CI test job ran on this head, so the local run below is the only evidence until it's retargeted.
  • Conventions: ✔ multi-line commit body; cargo fmt --check clean; tracing-subscriber is a dev-dependency only; and the time-travel.md correction checks out (TxnOpts::store_raw_txn is the real opt-in).

Verified locally at c39369d66: cargo test -p fluree-db-indexer --lib -- gc:: … → 55 passed, including the semantics, time-threshold and three repeated_publish_* tests. I set retained_versions back to keep_count and repeated_publish_then_gc_bounded_with_a_live_age_guard went red (3 reported against 9 roots on disk); I suppressed the "released nothing" event and test_clean_garbage_respects_time_threshold went red; restored, green.

Approving so you can merge when ready.

"generation {gen}: no roots observed under {prefix}"
);
assert_eq!(
result.retained, roots,

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.

👍 This is the assertion that makes the fix stick: it compares retained against the roots actually on disk rather than against a number computed the same way as the code under test. I set retained_versions back to keep_count locally and the live-guard-with-ceiling run went red (3 reported, 9 roots on disk). Worth knowing: the other two regimes and test_clean_garbage_semantics stayed green under that mutation, because each ends its pass with exactly retention_target versions left (or takes the empty-plan path), so this one regime is carrying the regression-proofing for the original bug on its own.

Base automatically changed from feat/delta-incremental-materialize to main October 24, 2026 19:11
@bplatz
bplatz merged commit 9420db4 into main Oct 24, 2026
19 checks passed
@bplatz
bplatz deleted the fix/gc-retained-count branch October 24, 2026 19:33
bplatz added a commit that referenced this pull request Oct 24, 2026
Brings #2142, #2144, #2154, #2155, #2156, #2158, #2159, #2165, #2166 and
#2167 into next.

Where main's RDF lists (#2159) meet next's RDF 1.2 links:
- The list view walks an EdgeAnnotation's body; next has no
  AnnotationTarget.
- Export marks annotated edges skipping list rows, and writes an
  rdf:reifies row as next's @reifies block through main's JsonLdNode,
  untranslated rows included.
- The JSON-LD and import readers keep next's graph argument and
  triple-term spool records beside main's gap-free list positions and
  list chunking.
- One collection writer: main's shared module, which both JSON-LD and
  Turtle use, replaces next's Turtle-only one, and now also keeps the
  labels of blank nodes inside triple terms, of reifiers, and of blank
  graph names. A reified cell keeps its triples while the well-formed
  tail after it folds, as JSON-LD's list conversion does; next's writer
  test now says so.
- Hiding list members also turns off next's wildcard lane, which reads
  leaflets directly, and next's independent-scan count builds its right
  scan with the same hiding.

Elsewhere:
- List-predicate discovery opens a leaf ranged unless the store cannot
  read ranges, which next fetches whole.
- GC reports main's walk stop reason without next's removed artifact
  cache directory.
- Tests from main await next's async genesis_ledger, reload with
  without_storage_lock, and build stores without a cache directory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:storage Storage backends, nameservice, ledger lifecycle, index storage, caches bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GC's completion log reports retained_count as the retention target, not the versions left

2 participants