Skip to content

feat(gc): let the age guard decide index retention, with a ceiling of 10 as backup - #2168

Merged
bplatz merged 8 commits into
mainfrom
fix/gc-default-version-ceiling
Oct 30, 2026
Merged

bplatz merged 8 commits into
mainfrom
fix/gc-default-version-ceiling

Conversation

@bplatz

@bplatz bplatz commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2164.

A superseded index version is kept so that a query which started on it can finish. That query might be running on the server, on a peer, or in an application embedding the library. New queries read the newest version, so the 15-minute age guard is the retention that matters. What was missing was a bound for a ledger that publishes faster than the guard: it kept every version from the last 15 minutes, which is how #2164 saw 79 versions against a target of 5.

This PR makes the age guard decide retention, with the ceiling from #1601 as the default backup:

  • Age guard (gc_min_time_mins, 15): a version is kept until it has been superseded for 15 minutes.
  • Ceiling (gc_hard_max_old_indexes, now 10, was unset): past ten old versions, a version is collected whatever its age.
  • Floor (gc_max_old_indexes, now 0, was 5): optional. The newest this many old versions are kept whatever their age. A ceiling at or below the floor is raised to it.

A ledger that publishes slowly now keeps no old version once its last one has been superseded for 15 minutes. Before, it kept five indefinitely, which protected no query.

The trade-off is the one #1601 documented. Past the ceiling, a query still reading a version can lose its artifacts: at one publish every 6 s, that happens to a query started a minute earlier. Operators raise the ceiling for ledgers that publish fast and serve long queries. An embedding application can remove it with IndexerConfig::with_gc_hard_max_old_indexes(None).

The default of 10 is a deliberate choice. The age guard is what protects long-running queries on servers, peers and embedded applications, but a ledger that publishes fast still needs a bound on disk.

Also user-visible: fluree branch list, the server's branch route and the Python binding now return an error when a branch's nameservice record cannot be read, and the error names the record. Before, they returned a list that silently left that branch out. See Branch listing below.

Changes

  • Defaults. IndexerConfig and its presets default the ceiling to DEFAULT_HARD_MAX_OLD_INDEXES (10). An unset --gc-hard-max-old-indexes / FLUREE_GC_HARD_MAX_OLD_INDEXES now means 10. A bare CleanGarbageConfig still sets no ceiling, so direct clean_garbage callers choose their own. DEFAULT_MAX_OLD_INDEXES drops to 0.

  • A ceiling at or below the floor. The collector already raised such a ceiling to the floor: the floor's versions are kept, and every version past them goes whatever its age. The docs said it had no effect, and now say what it does. With the ceiling on by default, a floor an operator raised above 10 becomes the ceiling. The worker warns at start-up when the floor is above the ceiling, and stays quiet when they are equal, since that is how a fixed retention count is set.

  • Override count. age_guard_overridden counts a version only when its garbage record was still inside the age guard. Before, every version past the ceiling counted, including ones the guard had already let go.

  • BM25 snapshots. BM25's manifest retention borrowed DEFAULT_MAX_OLD_INDEXES + 1. It counts snapshots with no age guard, so it now has its own constant and keeps 6 snapshots as before.

  • Reindex. The reindex path's GC pass now passes the configured ceiling, as the worker's pass does. Before, it passed the floor and the guard but no ceiling.

  • Sibling listing. A pass lists its ledger's sibling branches inside the release window, which holds every build of that ledger until it closes. That listing was all_records(), which is O(ledgers): on the storage-backed nameservice, one LIST plus about three sequential GETs per branch on the server; on DynamoDB, a query per ledger. A cache kept it off most passes, but with a default ceiling every pass on a fast ledger took it fresh, so the ledger's next build waited on a listing of the whole nameservice. The nameservice now has NameServiceLookup::branch_records(ledger_name), which lists one ledger's branches:

    • File storage walks the ledger's directory. Storage-backed: one LIST under the ledger's prefix, with up to 8 record reads in flight. DynamoDB: one GSI1 query narrowed by begins_with(pk, "name:"), then a query per branch.
    • It includes retracted branches, since a soft-dropped branch is restorable.
    • It fails on a record it cannot read, since GC reads a missing branch as one with nothing to protect.

    Every pass lists fresh, so the cached listing (BranchDirectory, SIBLING_LISTING_MAX_AGE) and the timing argument behind it are gone, as is GarbagePlan::overrides_age_guard. Branches the worker has built still count as siblings, because DynamoDB's index is eventually consistent. Branch drop and the reindex pass use the same listing.

  • Branch listing. NameServiceLookup::list_branches is removed, leaving branch_records as the trait's only per-ledger listing. list_branches skipped records it could not read, and fluree materialize relied on it before a run whose failed parity gate hard-drops every branch of the target name: a branch whose record read failed passed the check that should have refused the run. Fluree::list_branches keeps its contract, the non-retracted branches, by filtering branch_records. The file and storage-backed nameservices now name the record in a parse error, for example Cannot parse nameservice record fluree:file://ns@v2/mydb/dev.json: ….

  • JSON-LD connection config. defaults.indexing.gcHardMaxOldIndexes now sets the ceiling. Before this, the connection config could set the floor and the guard but not the ceiling, so an embedding application configured this way couldn't change the new default.

  • Config template. The fluree init template lists the three settings under [server.indexing].

  • Docs. background-indexing.md has a single account of retention:

    • why superseded versions are kept (time travel doesn't need them);
    • every place each setting is set;
    • how the settings combine, with retention at three publish rates;
    • sizing from the longest query;
    • the log fields;
    • troubleshooting for index storage that keeps growing.

    The configuration reference, the reindex guide, the JSON-LD reference, the query-peers page, the Rust guide and the time-travel page link to it. None of them says the two thresholds are ANDed any more. The Rust guide's background-indexing example called a BackgroundIndexerWorker::new signature that no longer exists; it now uses the builder. The nameservice concepts page and the crate map name branch_records.

Tests

  • Default ceiling, end to end. a_pass_lists_its_ledgers_branches_afresh runs a worker pass with IndexerConfig::default() over twelve versions whose garbage is fresh. The eleventh old version is collected inside the guard. The pass lists the ledger's branches once and never calls all_records, and it finds a fork whose dictionary blob therefore survives.
  • Branches built here. a_branch_no_listing_shows_yet_is_a_sibling_once_built_here hides a branch from every listing, as DynamoDB's index can for a branch created a moment ago. A branch this process built still protects the blob it reads.
  • Override count. test_hard_ceiling_collects_despite_recent_garbage runs with a 5-minute and a 60-minute garbage record. Both are collected past the ceiling, and only the first counts as an override.
  • Listing, per backend. Memory, file, storage-backed, and DynamoDB under LocalStack: retracted branches are kept, and nested and other ledgers are left out. File and storage-backed: an unreadable branch fails the call and the error names its record, and an unreadable record of another ledger is never read. drop_branch_with_children_deferred checks that Fluree::list_branches hides a soft-dropped branch that branch_records still lists.
  • Config. The config tests pin the default of 10 in every preset, show that None removes the ceiling, and check that an unset server flag leaves the indexer's default.
  • Default floor. by_default_the_age_guard_alone_decides runs a two-version chain under default settings. The old version is collected once it has been superseded for 60 minutes and kept at 5 minutes. With the old floor of 5 it fails.
  • Connection config. connection_config_gc_retention_reaches_the_indexer parses a JSON-LD connection config with all three keys and checks they reach the indexer config. A config without the ceiling keeps the default.
  • Template. The template test checks the three settings appear, and the wasm stub drift test now covers the two new constants.
  • Renamed. The collector test that pins "no ceiling keeps everything inside the guard" is now ..._without_a_ceiling, since no ceiling is no longer the indexer's default.
  • Existing test. it_fwd_pack_compaction::incremental_cycles_compact_the_forward_pack_tail reads every root from twelve index cycles, and the default ceiling collected the oldest. Its indexer now runs without the ceiling. The test is about dictionary compaction, not GC.

A superseded index version is kept so that a query which started on it can
finish, and the 15-minute age guard decides how long that is. Until now
nothing bounded it: a ledger publishing every few seconds kept every
version from the last 15 minutes. `gc_hard_max_old_indexes` now defaults
to 10, so past ten old versions a version is collected whatever its age.
`max_old_indexes` stays a floor, and `None` still removes the ceiling.

- `IndexerConfig` presets default the ceiling to
  `DEFAULT_HARD_MAX_OLD_INDEXES`. A bare `CleanGarbageConfig` still sets
  none.
- The reindex path's GC pass now passes the configured ceiling, as the
  worker's pass does.
- Only a pass that collects a version past the ceiling takes the
  sibling-branch listing fresh. Before, any configured ceiling took it fresh
  on every pass, and with a default ceiling that would have meant an
  O(ledgers) listing per GC pass.
- The docs describe retention as a floor, an age guard and a ceiling.
@bplatz bplatz added enhancement New feature or request area:storage Storage backends, nameservice, ledger lifecycle, index storage, caches labels Oct 23, 2026
…ling

The retention docs were spread across four pages, each describing the old
model, in which the age guard and the count were ANDed. This adds one
account in background-indexing.md and points the other pages at it:

- Why superseded versions are kept: queries already running on a server, a
  peer or an embedding application. Time travel does not need them.
- The three settings, and every place each one is set: flag, environment,
  config file, JSON-LD connection config and Rust.
- How the settings combine, with retention at three publish rates.
- Sizing the age guard and the ceiling from the longest query.
- The INFO log fields, and troubleshooting for index storage that keeps
  growing.
- Peers, the Rust guide, the JSON-LD reference and time travel link to it.

The JSON-LD connection config could set the floor and the age guard but not
the ceiling, so an embedding application could not raise the new default.
It now reads `defaults.indexing.gcHardMaxOldIndexes`. The `fluree init`
config template lists the three settings under `[server.indexing]`.

The Rust guide's background-indexing example called a
`BackgroundIndexerWorker::new` signature that no longer exists. It now
shows the builder, whose persistent backends index by default.
`gc_max_old_indexes` defaulted to 5, a floor kept whatever its age, so a
ledger that published slowly held five old index versions indefinitely
although no query was reading them. Retention is now the age guard, with
the ceiling as its backup. The floor defaults to 0 and stays available.

- BM25 manifests used the same constant for snapshot retention, which
  counts snapshots with no age guard. They now keep 6 snapshots under
  their own constant, as before.
- it_fwd_pack_compaction reads every cycle's root after twelve builds, so
  its indexer now runs without the ceiling the previous commit made the
  default.
- The `fluree init` template test reads the defaults from the constants.
- The docs lead with the age guard, then the ceiling, then the optional
  floor.
@bplatz bplatz changed the title feat(gc): default the index version ceiling to 10 feat(gc): let the age guard decide index retention, with a ceiling of 10 as backup Oct 23, 2026
@bplatz
bplatz requested a review from a team October 23, 2026 12:03
Base automatically changed from fix/gc-retained-count to main October 24, 2026 19:33

@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 the retention model reads much more clearly this way (the age guard decides, a ceiling backs it up, an optional floor), and pulling four pages' worth of the old ANDed description into one account in background-indexing.md is a real improvement. I'm on board with the model. My reservation is about the default, and I think that part is a call above this PR. Two headline notes:

(1) #2164 framed this as "Decision needed", and its own text says a default ceiling "would give that protection up on exactly the fast-publishing ledgers it would help", with reader tracking (option 2) as the option that removes the trade-off. This PR takes a path the issue didn't list: a default ceiling of 10 plus a floor of 0. So every server and embedded deployment that never set these gets different retention at upgrade. On a ledger publishing faster than about every 90 s, a reader holding one version (a long query, a peer, an embedding app's long-running job, a 15-minute serverless invocation) now keeps it for about ten publishes rather than 15 minutes. And a slow ledger keeps no old version 15 minutes after its last publish, where it used to keep five indefinitely. Is defaulting the ceiling on the trade we want for every deployment, or should it stay opt-in (#2164's option 1) until something tracks readers? That feels like a product call more than a code one, and worth making explicitly rather than having the merge settle it.

(2) More of an observation for after this PR: every one of these knobs is standing in for something we don't track, namely which roots a reader still holds. The age guard, #1601's ceiling, this default, and the sweep's single-process caveat (MaintenanceGuard) are all proxies for reader liveness, and each new one moves the trade rather than removing it. #2164's option 2 (a registry of in-use roots, with something like #1635's lease for other processes) is the structural fix. Definitely not for this PR.

Full review below:


✅ Approving to unblock you — with 1 thing that needs to be addressed before this merges.

Must address before merge:

  1. A ceiling at or below the floor turns the age guard off past the floor, and the new docs say it has no effect (fluree-db-indexer/src/gc/mod.rs:124, docs/indexing-and-search/background-indexing.md:297). The loop in plan_garbage starts at the floor and treats every position at or past 1 + ceiling as past the ceiling. So when the ceiling is at or below the floor, every version beyond the floor is collected whatever its age, and the existing test_hard_ceiling_never_collects_inside_retention_target pins exactly that. Now that the ceiling defaults to 10, an operator who explicitly set the floor to 10 or more upgrades from "the floor plus everything inside the age guard" to "the floor is a hard cap", with no signal and docs saying nothing changed. I reproduced it with a throwaway test (details inline). The fix is either the docs saying what the code does, plus a warning when the floor reaches the ceiling, or the code ignoring a ceiling at or below the floor. Your call which.

Should address:

  • fluree-db-indexer/src/orchestrator.rs:831: for the ledgers the default ceiling exists for, every pass now takes the O(ledgers) sibling listing fresh, on a default deployment that never did before. There's a narrower condition that I think is still safe. Details inline.

Beyond those, this is carefully built. The sibling-listing change is the right instinct (before it, any configured ceiling forced a fresh listing on every pass, so a deployment that already sets one gets strictly cheaper here). The reindex path picking up the configured ceiling closes a real gap. The JSON-LD connection config finally reaching the ceiling matters, since without it an embedding app configured that way couldn't move the new default at all. And the BM25 snapshot count is kept at 6 rather than silently following the floor to 1.

On the reader-safety questions behind the headline, here's what I checked:

  • Time travel doesn't need superseded versions. Nothing on the read path walks prev_index (only the indexer's build, drop and import code does), so the time-travel.md change holds.
  • Clock skew doesn't come into it. Age is the writer's created_at_ms against the collecting process's clock, which is the same process in the worker, and the ceiling is a pure count.
  • A query that does lose its version gets a storage miss rather than a short result, as far as I traced: local-path and disk-cache misses in binary_index_store.rs fall through to the remote read, and that read errors.
  • Every old knob is still honored. The one asymmetry is that the flag, env, TOML and JSON-LD surfaces can raise the ceiling but not remove it; only IndexerConfig::with_gc_hard_max_old_indexes(None) can. The docs say so plainly.

Adherence to repo commitments:

  • Patterns/abstractions: ✔ extends the existing IndexerConfig, CleanGarbageConfig and connection-config surfaces; no parallel mechanism; GarbagePlan::overrides_age_guard sits where the decision is made.
  • Performance (speed first, memory second): ⚠️ no query or index-build path is touched. The per-pass fresh listing on fast ledgers is new O(ledgers) nameservice I/O per build on a default deployment (inline). No query-path regression risk.
  • Deployment targets: ⚠️ the new defaults reach every host that builds an IndexerConfig from defaults, including the JSON-LD connection-config path an embedding app uses, and the evidence is unit tests plus an in-process worker test. The fence that matters is the one the docs already name: a reader holding one snapshot across many publishes. That's the trade in headline note (1) rather than a defect.
  • Testing: ✔ default-floor, default-ceiling, config, connection-config and template tests, each pinning a new default. CI's test, clippy, fmt and wasm32 jobs ran green once it was retargeted onto main (at 7de14a549), on top of the local runs below.
  • Conventions: ✔ thorough multi-line commit bodies; cargo fmt --check clean; docs updated across configuration, reindex, the JSON-LD reference, query peers, the Rust guide and time travel. The Rust guide's stale BackgroundIndexerWorker::new example being fixed is a nice catch.

Verified locally at 44cd3fb2a: cargo test -p fluree-db-indexer --lib -- gc:: orchestrator::tests::a_ config::tests → 67 passed, including by_default_the_age_guard_alone_decides, a_pass_past_the_default_ceiling_lists_siblings_afresh, a_fork_the_listing_predates_is_a_sibling_once_built_here and test_gc_config_builders; cargo test -p fluree-db-api --lib for connection_config_gc_retention_reaches_the_indexer, test_with_gc_settings_reaches_indexer_config_in_either_order, template_contains_default_values and the wasm stub drift test → 4 passed; cargo clippy -p fluree-db-indexer -p fluree-db-connection --all-targets -- -D warnings and cargo fmt --check clean. I set the default floor back to 5 and by_default_the_age_guard_alone_decides went red; I dropped overrides_age_guard from the listing's max-age and a_pass_past_the_default_ceiling_lists_siblings_afresh went red; restored, green. I didn't run the fluree-db-server flag test or grp_index's it_fwd_pack_compaction.

Approving now so you can merge without waiting on another pass from me. Just be sure the floor/ceiling interaction is resolved before you do, and, if you agree, the listing cost bounded too.

Comment thread fluree-db-indexer/src/gc/mod.rs Outdated
//! version's artifacts released underneath it; past the ceiling they go anyway.
//! At the default of 10, a ledger publishing every 6 s can collect a version a
//! query started on a minute earlier. Raise it for a ledger that publishes fast
//! and serves long queries. A ceiling below `max_old_indexes` has no effect:

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.

🔴 Must address before merge: a ceiling at or below the floor doesn't have "no effect". It switches the age guard off past the floor, and with a default ceiling of 10 that now reaches anyone who set the floor to 10 or more.

In plan_garbage (fluree-db-indexer/src/gc/collector.rs:489 at this head), the eligible loop starts at keep_count = 1 + max_old_indexes, and past_ceiling is i >= 1 + hard_max_old_indexes. When the ceiling is at or below the floor, every position the loop visits is past the ceiling, so every version beyond the floor is collected with the age floor set to 0. test_hard_ceiling_never_collects_inside_retention_target pins exactly this (ceiling 0, floor 1, five-minute-old garbage: both eligible versions are collected). So the code is deliberate; it's this sentence, and docs/indexing-and-search/background-indexing.md:297 ("a ceiling below the floor has no effect"), that disagree with it.

Before this PR, that combination only arose if someone set both knobs. Now the ceiling defaults to 10, so an operator who explicitly set --gc-max-old-indexes / FLUREE_GC_MAX_OLD_INDEXES / gc_max_old_indexes / maxOldIndexes to 10 or more (to keep more history) upgrades from "the floor plus everything inside the age guard" to "exactly the floor, with the age guard off past it". Nothing tells them, and these docs say the ceiling doesn't apply. I ran it with a throwaway test: floor 12, a 15-version chain with five-minute-old garbage, a 15-minute guard. With no ceiling the pass collects 0; with the default ceiling of 10 it collects 2 (age_guard_overridden = 2, retained = 13).

Either direction seems defensible to me, so it's your call which:

  • (a) Keep the code and make the docs say it: "a ceiling at or below the floor makes the floor a hard cap; past it, versions go whatever their age". That means this sentence, background-indexing.md:297, and the past_target bound at :319 (ceiling − floor goes negative). Add a warn! when the worker starts with gc_max_old_indexes >= gc_hard_max_old_indexes, so an operator whose floor now meets the new default finds out.
  • (b) Ignore a ceiling at or below the floor (e.g. hard_keep.filter(|&hk| hk > keep_count) in plan_garbage). That makes this sentence true and keeps an explicit floor's age guard intact. It means rewriting the second half of test_hard_ceiling_never_collects_inside_retention_target, which asserts the hard-cap reading.

(b) is the one that changes nothing for an operator who only ever set the floor, which feels closer to the spirit of a default, though it would also drop the cap for someone who deliberately set both knobs to the same number. I may also be missing why the hard-cap reading was wanted when #1601 dropped its clamp.

Comment thread fluree-db-indexer/src/orchestrator.rs Outdated
let max_age = if self.config.gc_hard_max_old_indexes.is_some()
|| guard_secs < 2 * SIBLING_LISTING_MAX_AGE.as_secs()
{
let max_age = if overrides_age_guard || guard_secs < 2 * SIBLING_LISTING_MAX_AGE.as_secs() {

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.

🟠 Should address: for the ledgers the default ceiling exists for, every pass now takes the O(ledgers) listing fresh.

The body says the fresh listing is only needed when a pass releases a version inside the age guard, and that other passes use the cached listing. That's right, but in steady state a ledger publishing more than ten versions per 15 minutes releases exactly one version past the ceiling on every pass (the chain reaches 12 and position 11 goes). So plan.overrides_age_guard() is true every time and max_age is ZERO every time. Per SIBLING_LISTING_MAX_AGE's own doc, that's a directory walk, a LIST plus a GET per record, or a DynamoDB query per ledger, on every index build of every fast ledger. A default deployment never listed fresh before (no ceiling meant the 300 s cache). a_pass_past_the_default_ceiling_lists_siblings_afresh pins the correctness half; nothing bounds the cost half.

If I'm following the safety argument in the SIBLING_LISTING_MAX_AGE doc correctly, an unlisted fork copied the source's head at some point after the listing was taken. So the only version a pass can release out from under it is one that was still the head after that point, i.e. one superseded more recently than the listing. That suggests a narrower condition: list fresh only when the youngest version the pass releases past the ceiling was superseded after the cached listing was taken. Its successor's garbage record (created_at_ms) is already read during planning, so the plan could carry the youngest such time; the listing keeps an Instant, so it would need a wall-clock stamp beside it. At one publish every 6 s with a ceiling of 10, the released version was superseded about a minute earlier, so the listing would be refreshed about once a minute instead of on every 6 s pass.

This is more of a question than a demand. You know the fork paths far better than I do, and if there's a reason the listing's age vs. the released version's isn't the right test, a sentence in the body saying the per-pass cost is accepted would be fine too. It's not a query path, but it is O(ledgers) per build by default, so if you agree I'd rather see it bounded in this PR than discovered on a deployment with many ledgers.

Comment thread fluree-db-indexer/src/orchestrator.rs Outdated
/// listing to show every fork (see [`SIBLING_LISTING_MAX_AGE`]), so it
/// lists afresh and finds the one that still reads the blob.
#[tokio::test]
async fn a_pass_past_the_default_ceiling_lists_siblings_afresh() {

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.

👍 Nice test. It's the one that proves the narrowed listing condition is still safe: a fork the cached listing predates still reads a blob from the version past the ceiling, and only the fresh listing saves it. I dropped overrides_age_guard from the listing's max-age locally and this went red (the fork's blob was no longer deferred: shared_deferred 0 instead of 1), so it really is guarding the narrowed condition.

…errides

A ceiling at or below `gc_max_old_indexes` never had "no effect", as the
docs said. The collector's loop starts at the floor, so every version
past the floor was past the ceiling and went whatever its age: the
ceiling is raised to the floor. That reading is kept. It is the only one
that keeps a bound for an operator who raised the floor, and it honours a
floor and ceiling set to the same count. The docs and the config field
now say so, and `past_target`'s documented bound is 0 once the floor
reaches the ceiling.

With the ceiling now on by default, a floor raised above 10 before this
change becomes the ceiling. The worker warns at start-up when the floor
is above the ceiling. It stays quiet when they are equal, which is how a
fixed retention count is set.

A version past the ceiling was counted as overriding the age guard
whatever its age, so `age_guard_overridden` and
`GarbagePlan::overrides_age_guard` also counted versions the guard had
already let go, and those passes listed siblings afresh for nothing. The
override is now read from the garbage record: it counts only when the
record is still inside the guard. `test_hard_ceiling_collects_despite_recent_garbage`
covers both a 5-minute and a 60-minute record.
…se window

A collector pass finds its ledger's sibling branches inside the release
window, which holds every build of that ledger until it closes. With the
ceiling on by default, a ledger publishing faster than the age guard
releases a version inside the guard on every pass, and each such pass
listed `all_records()` afresh. On the storage-backed nameservice that is
one LIST plus about three GETs per branch on the server, one at a time;
on DynamoDB, a query per ledger. With many ledgers on S3, the listing was
long enough to hold up the ledger's next build.

`NameServiceLookup::branch_records(ledger_name)` lists one ledger's
branches:

- A record it cannot read fails the call, as in `all_records`: GC reads a
  missing branch as one with nothing to protect. `list_branches` skips
  such a record and leaves out retracted branches, so it could not serve.
- Retracted branches are included, since a soft-dropped branch is
  restorable.
- File: walks the ledger's directory. Storage-backed: one LIST under the
  ledger's prefix, with up to 8 record reads in flight. DynamoDB: one GSI1
  query narrowed by `begins_with(pk, "name:")`, then a query per branch.
  Other backends filter `all_records()` by default, and the Arc,
  notifying, composite and API wrappers forward the call.

Every pass now lists its ledger's branches fresh, so the cached listing
(`BranchDirectory`, `SIBLING_LISTING_MAX_AGE`) and the timing argument
behind it are gone, as is `GarbagePlan::overrides_age_guard`. Branches
this process has built still join the siblings, because DynamoDB's index
is eventually consistent. Branch drop and the reindex pass, which also
list while holding the ledger, use the narrower listing too.

Tests:
- Every backend (the memory default, file, storage-backed, and DynamoDB
  under LocalStack): retracted branches are kept, and nested and other
  ledgers are left out.
- File and storage-backed: an unreadable branch fails the call, and an
  unreadable record of another ledger is never read.
- In the indexer, a test nameservice counts listings and can hide a
  branch. `a_pass_lists_its_ledgers_branches_afresh` checks for one branch
  listing, no `all_records`, and the fork found.
  `a_branch_no_listing_shows_yet_is_a_sibling_once_built_here` covers
  branches built here.
…t cannot read

The nameservice had two ways to list a ledger's branches.
`list_branches` skipped a record it could not read and left out retracted
branches. `branch_records` fails on an unreadable record and includes
retracted branches. Two near-identical methods invited the wrong pick,
and the lenient one was already relied on where a missing branch is
unsafe: `fluree materialize` checks that a target ledger name has no
other live branch before a run whose failed parity gate hard-drops every
branch of that name. A branch whose record read failed, such as on a
throttled S3 GET, passed that check and could then be purged.

`NameServiceLookup::list_branches` is removed, so `branch_records` is
the only listing on the trait, alongside `all_records`:

- `Fluree::list_branches` keeps its contract, the non-retracted branches,
  by filtering `branch_records`. `fluree branch list`, the server's
  branch route and the Python binding go through it. They now fail on an
  unreadable branch record rather than return a list missing that branch.
- `fluree materialize`'s check reads `branch_records`. Its own filter
  already skips retracted branches.
- The storage proxy's dictionary-blob routing reads `branch_records`. Any
  branch of the ledger serves, and an unreadable record now fails the
  read rather than being skipped.
- The duplicate lenient loops in the file and storage-backed nameservices
  are gone. Storage-backed and DynamoDB listings take their narrower
  per-ledger path for these callers too, where `list_branches` on
  DynamoDB listed every ledger.

The backend tests that pinned `list_branches` now run against
`branch_records`, including the file nameservice's path-traversal check.
The ones that pinned the exclusion of retracted branches move up a layer:
`drop_branch_with_children_deferred` checks that `Fluree::list_branches`
hides a soft-dropped branch while `branch_records` still lists it.
Branch listings now fail on a record they cannot read, but a parse error
reached the user as `Serialization error: EOF while parsing a string at
line 1 column 11`, with no hint of which record it was. A read failure
already named its key; a parse failure did not.

The file and storage-backed nameservices now parse every ns record
through `ns_format::parse_record`, which names the address it read:
`Cannot parse nameservice record fluree:file://ns@v2/mydb/dev.json: ...`.
That covers main records, index sidecars, head reads, and the record
reads on the write paths. The error is now a storage error rather than a
serialization error. Both map to the same HTTP status, and nothing
matched on the variant.

The two `branch_records` strictness tests now check that the error names
`mydb/dev.json`, and fail when it does not.
@bplatz

bplatz commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

@aaj3f thanks, both addressed:

  • Ceiling at or below the floor: kept the code, since it keeps a bound for anyone who raised the floor and lets floor = ceiling mean a fixed count. Fixed the docs, and the worker now warns at start-up when the floor is above the ceiling.
  • Listing cost: rather than narrowing when to list, the listing is now per ledger. The new NameServiceLookup::branch_records is O(branches) on every backend and is taken fresh on every pass. The cache is gone.

Following that thread, list_branches turned out to skip unreadable records, and fluree materialize relied on it before a hard drop, so it's removed from the trait. On the default: 10 is a deliberate call. Agreed that tracking readers is the real fix, separately.

Enough has changed since your approval that a re-look would help. The body is updated.

@bplatz
bplatz merged commit 8f342c8 into main Oct 30, 2026
19 checks passed
@bplatz
bplatz deleted the fix/gc-default-version-ceiling branch October 30, 2026 11:12
bplatz added a commit that referenced this pull request Oct 31, 2026
Brings #2217 (SPARQL reads list members as values; CONSTRUCT writes lists),
#2218 (schema writes judged by modify policy), #2208, #2169, #2168, #2153,
#2149 and #2148 into next.

Resolutions:
- Nameservice: branch_records is the one branch listing (strict, retracted
  branches kept for GC) on every backend, resolved through next's bindings;
  Fluree::list_branches filters retracted ones. The lifecycle conformance
  suite reads live branches through a helper. DynamoDB's narrow listing is
  wired into its trait impl.
- JSON-LD adapter: main's graph scoping (Walk, Scope, node_graph, selectors)
  with next's triple terms, @annotation, @reifies, blank-label and number
  datatype handling. to_graph_events writes a JSON-LD named graph under its
  @id and refuses a graph selector. main's f:reifiesGraph anchor is dropped:
  next writes an annotation as an rdf:reifies link in its graph.
  emit_quad_list_item takes (graph, index).
- Bulk import: an annotation's link is written to the graph its slots name,
  and a triple-term statement in a named graph is spooled under that graph
  (both landed in the default graph); emit_quad_reified_triple is
  implemented. resolve_object_value keeps main's vector refusals and next's
  term-table path.
- Ledger manager: a store that fails to load fails the load or keeps the
  reloaded ledger's state (main), over next's load_decoding_root and
  activation swap rule.
- Novelty keeps main's KeptEffects without the retired arena's reifies
  capture. The pool's resolve_events_at and compaction's split_lifecycles
  follow fluree_db_core::same_t.
- Retired annotation arena files stay deleted.
- Tests from main adapted to next: one Fluree per storage directory, async
  genesis_ledger, storage-namespace content stores, u32 graph ids, a store
  broken by hiding a dictionary branch (next has no disk cache), a refused
  import leaving no ledger. next's tests that pinned bulk import refusing
  @graph and SPARQL's RDF list view now check what main changed them to.
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 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Under frequent index builds the GC age guard, not max_old_indexes, decides retention

2 participants