Repository navigation
fix(api): reindex reads a branch's history through its source - #2246
Conversation
A rebuild walked a branch's commits with a store of the branch's own namespace, so a branch whose history runs through its source's commits could not be reindexed (commit envelope not found).
aaj3f
left a comment
There was a problem hiding this comment.
@bplatz this looks right to me, and at a design level no pushback: the one commit-chain walker still on the flat store now goes through the branch-aware one, reusing the record already in hand. The only headline note is about a class we keep finding: a chain walk picks its store at each call site, and content_store(id) is the easy default. #1200's sweep (11dedb84d, 734f03f37) routed about 17 sites through the branch-aware store, this PR catches reindex, which that sweep missed, and the two test helpers #1984 names are still flat (optional note below). A store type the walkers require, which only the branch-aware constructors can build, would make the next one a compile error. Not necessarily asking that you do that in this PR, but it would be nice if we did it soon. On overlap with my #2157 and #1887 in admin.rs: this adds no conflict with either (#1887 needs a rebase onto main regardless), so no ordering constraint from me.
Full review below:
✅ Approve with nits.
Nice, tight fix, @bplatz. reindex handed the rebuild a store scoped to the branch's own namespace, so any branch with pre-fork history failed on its first source commit. It now builds from the record through content_store_for_record_or_id, the way the background indexer, loader, merge and rebase already do. Writes through that store still land in the branch's namespace, and the post-reindex GC rightly stays on the flat store. The test reindexes a branch with commits on both sides of the fork and reads both back from the rebuilt index, which is the check the issue asked for.
Adherence to repo commitments:
- Patterns/abstractions: ✔ uses the existing
content_store_for_record_or_idhelper; no new construct. - Performance (speed first, memory second): ✔ admin path only; pre-fork reads fall through one store, as background indexing already does. No performance-degradation risk.
- Deployment targets: ✔ n/a —
fluree-db-api's reindex, reached by the server and by any embedder (including one running inside AWS Lambda), but it only swaps which store the rebuild reads from: no new task, cache or filesystem assumption. - Testing: ✔
reindexing_a_branch_reads_its_source_commitsingrp_ledger, run green by CI's workspace nextest; red with the fix reverted. The test helpers #1984 names are the optional note above. - Conventions: ✔ self-describing subject with a body; clippy and fmt green.
Verified locally at branch HEAD: the new test passes; with admin.rs reverted to the merge-base it fails with Failed to read commit envelope …: Not found; restored, the 30 it_branch/reindex tests in grp_ledger pass; every remaining flat content_store( call in api/cli/server checked for chain walks.
Approving so you can merge when ready, but maybe worth folding in the two helper swaps first.
| /// A branch's history runs through its source's commits: reindexing it reads | ||
| /// them from the source. | ||
| #[tokio::test] | ||
| async fn reindexing_a_branch_reads_its_source_commits() { |
There was a problem hiding this comment.
Optional. #1984 names two sites with the flat store, and Fixes #1984 closes it with one of them still open: the test helper support::rebuild_and_publish_index (fluree-db-api/tests/support/mod.rs:358-359) still builds from fluree.content_store(ledger_id), and so does its sibling build_and_publish_index (:380-381).
Nothing hands them a branch with pre-fork history today (the suite would be red if something did), but the next test that indexes a branch through them gets this PR's Not found from the helper rather than from the code under test, which is a confusing place to find it.
It's a one-line swap in each, to fluree.branched_content_store(ledger_id).await.expect("branch-aware store"). It's minor and non-blocking, but if you agree it's right, I'd rather see it folded in now than lost in the backlog, especially since the issue already asks for it.
Commenting here because fluree-db-api/tests/support/mod.rs is not in this diff.
The helpers that build and publish a test ledger's index read its commits from the flat store, so a branch with history from before its fork failed in the helper, as reindex itself did (#1984), and not in the code under test. They build from the branch-aware store, as reindex now does.
Brings #2247, #2232, #2246, #2248, #2245, #2230, #2205, #2231, #2255, #2219, #2209, #2207, #2190, #2216, #2186, #2215, #2213, #2184, #2210, #2206, #2198, #2187, #2183, #2200, #2193, #2199, #2196 and #2145 into next. Resolutions: - Novelty: main's fact-state trim (a cutoff plus a bounded sweep) and the dictionary's coverage watermark sit on next's graph slots and per-graph OrdMaps. A commit's reification links count toward coverage. Planner stats from segment sums decline under annotations, whose link deltas only the walk counts, and otherwise carry the indexed link counts. - Stats-view identity: the index root's id reaches the snapshot through next's root decoder (`decode` takes the id, as `take_snapshot_metadata` does). `LedgerState::load_record` has a decoding-root form beside `load_decoding_root`. - Transact: #2184's parallel-relationship check runs in next's link cascade, counting the `rdf:reifies` links on the retracted edge that the transaction does not retract itself. Main's bundle `edge_reifiers` is dropped, and `subjects_with_prior_rows` and `enforce_single_target_reifiers` stay deleted. The upsert pre-check takes main's dictionary probe and bounded seek. - Query: geo search resolves the graph's POST tree once at open (pooled graphs keep their filter), an empty manifest when there is none. `branch_or_none` reads the dedicated branch, and the batched joins keep next's pooled lanes. The stats-view key hashes the root id. - Indexer: `apply_dict_novelty` and `compact_forward_streams` take the cycle's compaction budget, so the term dictionary keeps its reserved share. `Prefetched` holds `ContentBytes`. `relocalize_sorted_commit` rewrites next's 20-byte types records. - Disk cache: main's in-flight write registration, with an empty entry still read as crash debris that a write replaces. The process-wide eviction walk stays removed. - Graph import (#2232): fenced CAS and publishes, the seed carries the record's namespace and fence, 32-bit graph ids and next's loaders. An import into a graph of an existing ledger refuses triple terms and edge annotations: the splice merges no triple-term dictionary yet. - Iceberg: `create_iceberg_graph_source` goes with main (a source needs a mapping); the R2RML path keeps next's `model_instance`. - CLI: main's shared import flags without the leaflet flags; `graph import` routes through next's process-wide server routing, and `upload_source_import` serves next's `Destination`. Doc sources read a ledger through the command's open instance. - Tests: sibling ledger ids become distinct names, `genesis_ledger` is awaited, Cypher state dumps include each relationship's `rdf:reifies` link, and the graph-import arena test checks the refusal instead.
reindexreads a branch's history through its sourceFluree::reindexrebuilt a branch's index from a store of the branch's own namespace. A branch's history runs through its source's commits, which live in the source's namespace, so reindexing any branch with a parent failed:This reached
POST /v1/fluree/reindexandfluree reindex. Background indexing of a branch was unaffected: it, the ledger loader, merge and rebase already read through the branch-aware store.reindexnow does too.Test:
reindexing_a_branch_reads_its_source_commits(fails onmainwith the error above).Fixes #1984