Repository navigation
Description
plan_sweep builds its live set by walking every branch's index chain and expanding each root's reachable CAS set. Both halves of that re-read data they already have:
collect_root_cas_ids_expandedruns once per root and issues astore.getper named-graph branch manifest and per annotation branch. Consecutive roots in an incremental chain share nearly all of those manifests, so the same blobs are fetched and decoded once per root rather than once per distinct manifest.live_addressescalls the uncachedwalk_prev_index_chain_cs(fluree-db-indexer/src/gc/sweep.rs:195), even thoughwalk_prev_index_chain_cs_cachedexists andclean_garbagealready feeds itconfig.artifact_cache_dir(collector.rs:245). Every root is re-read from remote storage with a warm artifact cache sitting unused.
Both costs land on the operation's critical path, and the sweep holds every branch of the ledger out of indexing for its whole duration.
Why it matters here specifically
The sweep exists for ledgers whose index chains grew unbounded — that is the population it targets, and it is the worst case for this shape. On a reported deployment the chain is ~3,000 roots. Multiplied by a handful of graph orders, expansion alone is tens of thousands of round trips against remote storage, all while indexing is excluded.
Reported as part of the #1614 review: "the difference between a sweep that takes a minute and one that takes an hour on the ledger this PR is aimed at."
Correctness is not affected. live_addresses already deduplicates at the ContentId level before deriving addresses, so the extra reads change only how long planning takes.
What to change
-
Thread a
HashSet<ContentId>of already-expanded branch manifests through the chain loop, so expansion approaches O(distinct manifests) rather than O(roots × branches). This is the same observation the existing CID-dedup comment atsweep.rs:191-193makes about derived addresses, applied to reads instead. It likely wants a variant ofcollect_root_cas_ids_expandedthat accepts a seen-set, since the current signature has no way to carry one across calls — noteexpanded_cas.rs:33-42keeps a "use sites (must all stay in sync)" list that a new variant would need to join. -
Use the cached walk.
plan_sweephas noartifact_cache_dirin its signature today, so this means plumbing one through from the caller, mirroringCleanGarbageConfig.
Also in scope while the function is open
These came out of the same review pass and sit in the same loop, so they are cheaper to do together than separately:
- Branch chains are walked strictly sequentially. Each chain is inherently serial — it is a linked list — but branches are independent. Bounded concurrency across branches turns an N-branch ledger's planning time into roughly one branch's. Bound it rather than using unbounded
join_all, because each concurrent walk holds a fullVec<IndexChainEntry>of decoded roots (see below). live_addressesandswept_addressesare awaited in sequence (sweep.rs:94-95) although they are independent.try_join!overlaps the prefix listings with the chain walk. Small — the listings are the cheap side — but free.- The whole decoded chain is materialised before anything is consumed.
walk_prev_index_chain_csreturnsVec<IndexChainEntry>, each holding a fully decodedIndexRootwhosedefault_graph_ordersinline aLeafEntryper leaf. On a long chain over a wide index that is substantial resident memory for data the sweep reads exactly once, in order. A streaming walk that yields per root would let each be expanded, recorded, and dropped. This shape predates the sweep — the collector has it too — but the sweep is the caller most likely to meet a pathological chain.
Acceptance criteria
- Planning a chain of N roots that share their branch manifests issues on the order of the distinct-manifest count, not N × manifests. A counting store double in the existing
gc/sweep.rstests can assert this directly. - The sweep uses the artifact cache when one is configured.
- No change to which addresses are classified as orphans. The existing sweep tests — particularly
a_dict_only_a_sibling_branch_references_survivesandsweeping_a_real_ledger_reclaims_strays_and_leaves_queries_intact— must stay green, since this issue is purely about how planning gets its data.
Related
- Reclaim superseded and orphaned index artifacts #1614 — added the sweep; raised in review there
- File storage: superseded index snapshots/dictionaries are never reclaimed in practice, and POST /reindex permanently breaks the GC chain (root published with no garbage manifest) #1548 — the reclamation work the sweep is part of
Activity