Repository navigation
fix(gc): log the index versions a pass leaves, not the retention target - #2167
Conversation
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`.
aaj3f
left a comment
There was a problem hiding this comment.
@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
GarbagePlanandCleanGarbageResultrather than adding a parallel report;WalkStopreplaces anOptionthat 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.retainedand the loggedretainedagainst 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 --checkclean;tracing-subscriberis a dev-dependency only; and thetime-travel.mdcorrection checks out (TxnOpts::store_raw_txnis 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, |
There was a problem hiding this comment.
👍 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.
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.
Fixes #2163.
The GC completion line logged
retained_count = keep_count. That value is1 + 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 atINFO, so a ledger held entirely by the age guard didn't show up at all.Changes
Plan.
plan_garbagereturns aGarbagePlaninstead of anOption. An empty plan releases nothing but still knows the chain length, so every path reports the versions it left (GarbagePlan::unreleased). As before, callers checkis_empty()before they open a release window.Stop reason. The chain walk records why it stopped:
age_guardorunreadable_manifest.Completion line.
Garbage collection completenow 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_countis gone.Held passes. A pass that releases nothing while versions are past the target logs
Garbage collection released nothingatINFO. It carries the same fields, plusmin_time_garbage_mins.Result.
CleanGarbageResult.retainedcarries the count.Docs.
background-indexing.mddescribes the new fields.time-travel.mdsaidtxn: truestores a transaction's raw payload. No such option exists; the opt-in isTxnOpts::store_raw_txn.retainedcounts the chain the pass planned from. It doesn't include versions published while the pass ran.Tests
CleanGarbageResult.retainedand the loggedretainedboth 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.INFOline;