Repository navigation
fix(indexer): a fact deleted before an incremental build stays deleted in a graph new to the index - #2118
Conversation
… after an incremental build Red on main: an incremental build writes a fresh branch for a graph with no partition in its base index, and a fact inserted and deleted inside the window comes back as a live row. Covers SPARQL and JSON-LD deletes, a new named graph and a default graph with no indexed rows, strings, integers, language-tagged strings and refs, a replaced value, and the window's history.
…ow events An incremental build writes a fresh branch for a graph, or an order, with no branch in the base root: a named graph first written after the last build, or the default graph of a ledger whose indexed data all sits in named graphs. That branch was written from the window's net records with their ops ignored, so a fact whose net op was a retraction became a live row, and the events lifecycle dedup superseded were dropped with a warning. The fresh branch now resolves each fact's events from absent, as a full rebuild does: transitions go to the history sidecar and only a final assert becomes a row. Both use one LeafWriter::push_lifecycle, and the fresh path reuses the leaf merge's identity gather. The default- and named-graph fresh builders were the same function; they are now one.
With retraction winners now resolved, a fresh branch can come out with no leaves: every fact in the window netted to no row and no history. A branch with no leaves routes no novelty, so a later incremental build would drop the graph's writes. Publish nothing instead; the next build sees the graph as fresh again. The default- and named-graph fresh arms are merged.
No build is driven: the insert stays under the soft threshold and the delete commit crosses it, so the background indexer's own incremental build covers both, in the default graph of a ledger indexed only in a named graph and in a new named graph.
…d takes the insert and the delete With small data the background indexer builds after every commit, so the insert was indexed before the delete committed and the test passed on main. A large write in flight now holds the insert and the delete for one later build, under the default thresholds, and the test checks that shape before it reads.
…d novelty A published branch with no leaves holds no base facts, the same as no branch. The incremental build routed its novelty into the leaf merge, where slicing found no leaf and returned no slices, so the window's writes for that graph and order were dropped. Such a branch now takes the fresh path, decided once the branch is known (from the root's inline leaves for the default graph, from the fetched manifest for a named graph), and slicing refuses novelty for a branch with no leaves instead of returning nothing. A full rebuild no longer publishes a graph whose log nets to no row and no history, matching an incremental build's empty fresh branch. The incremental build also refuses a base root in which a graph has some but not all four sort orders. No writer produces one (each builds a graph's four orders from one fact set); a missing order would otherwise be built fresh from the window alone, without the graph's base facts. The refusal is an incremental abort, so the caller falls back to a full rebuild.
bplatz
left a comment
There was a problem hiding this comment.
Approving. Please review the inline feedback before merging.
| orders.dedup(); | ||
| orders.is_empty() || orders == all | ||
| }; | ||
| let default_orders = default_graph_orders.iter().map(|o| o.order).collect(); |
There was a problem hiding this comment.
A bulk import whose quads are all in named graphs writes a root whose default graph has only a leafless SPOT. build_spot_index_from_commits in build_from_commits.rs returns its graph even with no leaves, unlike build_index, so the next incremental build aborts here and falls back to a full rebuild. Treating a leafless default-graph order as absent before the none-or-all check, and not emitting the leafless SPOT on import, would let it build incrementally. Repro: import a TriG file with one quad in GRAPH <g>, insert one default-graph fact, then call build_incremental_index_for_record.
There was a problem hiding this comment.
Thanks, this reproduced exactly as you describe, and the import turned out to have a second shape I hadn't expected: an empty GRAPH <g> { } block gets its graph id too, and import wrote that graph a SPOT with no leaves and nothing else. I've taken both halves of your suggestion.
- The import no longer writes such an order (
9c946b45b).PersistingLeafWriter::finishnow returnsNonewhen it wrote no leaf, so the import's SPOT build and the full rebuild's order builds both leave a graph with nothing to hold out of the root, rather than each checking for it on its own. - An order with no leaves counts as absent in
check_order_sets(2eaa71549, narrowed in77cef24d9), for the default graph and named graphs alike. The default graph's leaves are inline in the root. For a named graph I didn't want a branch fetch per order on every build, but a branch with no leaves is exactlybuild_branch_bytes(order, g_id, &[])(one decodable branch version, and every writer builds through that function), so its CID identifies it from the root alone. I checked that against a root main's import actually wrote, and the CIDs match. Hashing every named branch on every build turned out to cost about as much as decoding the root itself (5.4 ms vs 4.5 ms at 10,000 named graphs), so it's only done for a named graph with some orders but not all, which is exactly the older import's shape.
So a root an older import wrote reads as having no facts for those graphs, and the next build takes them incrementally. graphs_an_import_left_empty_take_facts_incrementally runs your repro (one quad in GRAPH <g2>, plus the empty block, a default-graph insert, then build_incremental_index_for_record) against both a fresh import and a root rewritten to the older import's shape. It fails at 1309f8af5, where the import still writes those orders, and with either half of the absent-count turned off the older root's build aborts.
| // all, so it is built fresh too: the merge has no leaf to route its | ||
| // novelty into. | ||
| let route = match kind { | ||
| Phase2TaskKind::DefaultExisting { leaves } if !leaves.is_empty() => { |
There was a problem hiding this comment.
Main can already have written a root from that import shape with a leafless SPOT and the other three orders populated, because main drops SPOT's novelty on a default-graph write. That root passes check_order_sets, so SPOT is built fresh from this window only and permanently misses the earlier default-graph facts. I reproduced it by building on main and then on this branch: the fact stays missing by subject. The leafless-as-absent check above would flag it as partial and repair it through the rebuild. Since main drops default-graph writes from SPOT after a named-graph-only import, this is worth a line in the description, along with a note that affected indexes need a reindex.
There was a problem hiding this comment.
Good catch, and you're right on every count. This one is on main already, and the description's line that no writer produces a partial order set was wrong, since import did. I've corrected that and added a section on what main does here.
With leafless-as-absent, the root you describe (SPOT with no leaves, the window's facts in the other three) is partial, so the next build aborts and the full rebuild it falls back to restores SPOT. For the default graph check_order_sets sees that from the inline leaves. A named graph gets into the same state on main once a graph from an empty GRAPH block is written to, and for one with all four orders the check is check_base_facts_agree after Phase 2 (2eaa71549). That refuses a graph whose four tasks disagree on whether the base holds its facts, and it knows each fetched branch's leaves at no extra cost. facts_missing_from_spot_are_rebuilt builds that root the way main writes it, for the default graph and for such a named graph. It checks that by subject the fact is missing while by predicate it's there, then writes another fact and checks that the incremental build refuses and the rebuild brings both back by subject.
On what a user sees on main (probed at 04e1a6d37): every default-graph fact written after a named-graph-only import is missing from SPOT once it's indexed, and so is every fact later written to a graph an empty GRAPH block created. Reads that go through SPOT miss them. That covers a subject-bound pattern (ex:s ex:p ?o, ex:s ?p ?o), a fully bound ASK, ?s ?p ?o (so DISTINCT ?s and GROUP BY ?s too), CONSTRUCT by subject, the JSON-LD subject crawl (just the @id comes back), time travel by subject, and a join whose plan looks the subject up. Predicate- and object-bound patterns still see them, and so do COUNT(*), a FILTER(?s = …) over a predicate scan, and the OPTIONAL and property path I tried. The part I'd flag most is that writes whose WHERE binds the subject miss them too: DELETE { ex:s ex:p ?o } WHERE { ex:s ex:p ?o } deletes nothing, and a JSON-LD upsert keeps the old value next to the new one. An affected index is repaired by a reindex. With this PR the next build repairs it too: for the default graph whatever the window touches, and for a named graph the next time that graph is written.
| Named { | ||
| branch_cid: ContentId, | ||
| }, | ||
| /// A fresh branch with nothing to hold: the graph keeps no branch for |
There was a problem hiding this comment.
If the base root had a leafless branch for this order, the graph keeps that branch, so "keeps no branch" isn't quite accurate.
There was a problem hiding this comment.
Right, fixed in 2eaa71549. The comment now says the root keeps what it had for that order, no branch or one with no leaves, which the next build again finds no base facts in. Since the build now treats an order with no leaves the same as a missing one, keeping it is harmless, and no writer adds a new one.
| //! named graph first written after the build, or the default graph of a | ||
| //! ledger whose indexed data all sits in named graphs. | ||
| //! | ||
| //! Background indexing is off: these tests drive each build themselves, and |
There was a problem hiding this comment.
background_indexing_keeps_deleted_facts_deleted runs with background indexing on, so this header isn't true for that test.
There was a problem hiding this comment.
Thanks, fixed in b117c1de3. The header now says background indexing is off in all but that test, and that that one holds the indexer under its soft threshold rather than racing it.
| .expect("nameservice lookup") | ||
| .expect("ledger record") | ||
| .index_t; | ||
| assert!( |
There was a problem hiding this comment.
This is timing-dependent. With the default threshold nearly every commit triggers a build, so an insert-only build can publish before the delete commits (a spurious failure). It can also start without publishing, in which case the test passes without one build covering both. The four deterministic tests carry the real coverage, so this one could be made deterministic or noted as supplementary.
There was a problem hiding this comment.
Agreed, and I went with deterministic (b117c1de3), using a gate the code already has rather than a test hook: the soft threshold. The test now sets reindex_min_bytes to 100 KB and turns catch-up sweeps off, since those ignore the threshold. A commit over the threshold builds the G2-only base. The insert and the delete each stay under it, and the test asserts that from each commit's own indexing.needed, which is exactly what decides whether the commit starts a build, so it fails loudly if either one could have. Then one commit crosses the threshold, so the only build after the base's takes both writes in one window. On main's sources it fails at the final read (["\"x\""] for the default graph), and it passes here. Related, and the same class of problem: the branch now also carries a change to the test helpers that publish an index (326fe7c06). They go through one publish_built_index that asserts the nameservice holds the build the test just made, since publish_index quietly declines one at a t the background indexer already published. That turned up 31 tests elsewhere reading an index other than the one they built, mostly background-indexer races; the description has the details.
The import builds SPOT for each graph on its own, and returned a result for the graph even when it had no records, unlike the secondary orders. So an import whose quads were all in named graphs wrote a default graph whose only order was a SPOT with no leaves, and an empty GRAPH block wrote the same for its named graph. The persisting leaf writer now returns no result when it wrote no leaf, so the import's SPOT build and the full rebuild's order builds leave such a graph out of the root alike.
A root an older import wrote can give a graph a SPOT with no leaves and no other order. The incremental build took that for a partial order set and fell back to a full rebuild, though the graph holds no facts at all. An incremental build used to leave that SPOT empty while writing the window's facts to the other three orders. The root it wrote had all four orders and passed the check, so a later window would build SPOT fresh, without those facts. The order-set check now counts an order with no leaves as absent: a default-graph order by its inline leaves, a named-graph order by its branch CID, since a branch with no leaves has fixed bytes for its order and graph. The first root is then complete and builds incrementally; the second is partial and falls back to a full rebuild, which restores SPOT. After Phase 2 the build also refuses a graph whose tasks disagree on whether the base holds its facts, for a branch with no leaves that the root alone doesn't show.
Two tests on a TriG import with no quads for the default graph or for an empty GRAPH block's graph: the next build takes their first facts incrementally, also from a root an older import wrote; and an index whose SPOT lacks facts the other orders hold, as an incremental build wrote after such an import, is refused and rebuilt so the facts read by subject again. The background test is now deterministic: the indexer is held under its soft threshold, with catch-up sweeps off, until one commit after the insert and the delete crosses it, and each commit's indexing status proves no build started in between.
Clippy's type-complexity lint refused the table of branch-builder closures; a flag for whether the root can recognize the branch says the same thing.
… partial Telling a named branch with no leaves by its CID costs a SHA-256 per branch, which measured about as much as decoding, cloning and encoding the root itself (5.4 ms against 4.5 ms at 10,000 named graphs), on every incremental build. The order-set check now does it only for a named graph with some orders but not all, the older import's shape. A graph with all four is taken as having facts in all four, and the Phase 2 check, which already knows each touched branch's leaves, refuses one whose SPOT has none. The SPOT test's case with a branch the root can't recognize is gone: a named graph's case now takes that same path. The leafless-branch unit test checks that such a task reports no base facts.
`a_transfer_keeps_a_value_both_graphs_hold` failed in CI on a MOVE whose source was written since the destination's build: the source read back its moved value after a reload. `FlureeBuilder::file` starts a background indexer, which can run an incremental build between the transfer and the read, and an incremental build brings back a fact inserted and retracted since its base in a graph the base holds nothing for (#2118, a separate fix). The read before any build is right. Every instance in this PR's file-backed transfer, merge/revert, multi-op and temporal-ordering tests is now built `without_indexing()`, and the tests build the index themselves. The transfer test reads with no build since the transfer, after an incremental build, and after a full rebuild. After the incremental build it reads the source only where #2118 cannot reach it (any verb but a MOVE out of a graph written since the base), and after the full rebuild it reads both. The full rebuild after an incremental one is published through `Fluree::reindex`. `publish_index` declines an index whose `t` is not newer than the published one, so the rebuild the multi-op test ran after its incremental build was never published, and its "after a rebuild" read repeated the incremental one.
`publish_index` declines, silently, an index whose `t` is not newer than the one already published. The test helpers that build and publish an index (`rebuild_and_publish_index`, `build_and_publish_index`, `build_incrementally_and_publish_index`) published through it and never looked, so a second build at one `t` left the test reading the index it meant to replace: - `repeat_full_rebuild_restores_retracted_history` rebuilds a second time at one `t` to show that re-running a reindex restores history; the second rebuild was never published, and the test read the first; - 30 tests on a file-backed `Fluree` with its background indexer running had their rebuild declined whenever the indexer published at that `t` first. Over three runs of the API suite, 16 to 21 of them hit this per run. At `t` 2 or 3 (seven tests) they read the indexer's build in place of the full rebuild they asked for. Every helper now publishes through `support::publish_built_index`, which publishes as `Fluree::reindex` does, replacing an index of the same `t`, and then checks that the nameservice holds this build. A newer published index can't be replaced, and the check panics, naming the background indexer as the likely cause. The nine direct publishes in `it_import_v3`, `it_indexing_fuel`, `it_storage_encrypted` and `it_merge` (including its `index_branch` helper) go through it too. With the builds published, the whole API suite passes: no test relied on reading the replaced index.
The SPOT and import tests publish a root they rewrote; they now go through the shared helper, which asserts the nameservice holds that root before the test reads it.
…ferences Brings in #2137, #2118 and #2109. The one conflict is stage.rs's fluree_db_core import: #2109 dropped `FlakeMeta` from it, and this branch added the dataset-reference types. #2109's FactIdentity DELETE naming and fold, and this branch's typed graph resolution for USING / WITH and the write table, sit in separate hunks and merge as both wrote them.
Brings main since 1888006 onto next, #2109 and #2118 among it. Resolved: - template_sink: main's statement hashes for the content identity, with next's rdf:reifies link and its datatype check; no bundle templates. - incremental: main's Phase2Route (a leafless branch is built fresh, the fresh builder keeps in-window history, an empty fresh branch is not published) on next's storage handle, without cache_dir. - build_from_commits tests: main's helpers with next's term fields. - commit_transfer, rebase: the imports both sides still use. - test support: main's publish_built_index, publishing allow-equal under the ledger's fence; its callers take main's side. Ported to next: - index_key_may_merge_terms answers for a triple term: its key merges two terms only through its object's. - The SPARQL triple-term literal drops IllTyped, which main removed; it refuses an ill-typed literal, as it did. - Main's new tests read a ledger's store through its storage namespace, await the async genesis_ledger, and the ill-typed upsert test names a ledger per iteration rather than a branch.
#2118 (via main) and this branch both write an order with no base leaves from the window alone. The folded tree here does it for every such order, including a pooled graph's promotion, so #2118's fresh-branch builder is not carried over. Its other rules are: a graph's folded tree with nothing to hold is not published, a base root with a partial order set falls back to a full rebuild, and a dedicated graph's four tasks must agree on whether the base held its facts. The pool's orders are not checked there, since its secondary orders take writes as delta runs. The leaf merge's identity gather takes slices, as #2118 needs, and the order's identity, as the pool needs. #2118's tests pin a named graph's own trees, so they keep the graph dedicated.
The parent now carries main 4a0d14a (#2109, #2118, #2133). Four files conflicted: - temporal.rs: main's `cmp_with_lexical` body is the one this branch already had (#2109's); the two docs are merged, so it says both that a dateTime or time lexical is held to the microsecond and that the evaluator and the bounds pass it only a plain xsd:string. `lexical_as_kind_of` stays, over the same parse functions. - query_bounds.rs: this branch's string-vs-temporal arm (the plain-string guard and the per-kind parse cache) replaces main's simplified one, which called `cmp_with_lexical` with no guard. `string_bound_otypes` stays. - eval/compare.rs: the plain-string guard stays on the evaluator's coercion. - binary_history.rs: main's shared object check (#2133) is kept, with the term-aware `matches(&f.o, &f.dt)`; this branch's separate bound test in the novelty walk is dropped, as the shared check covers both lanes.
An incremental index build can bring a deleted fact back. It happens when the fact was inserted and then deleted between two builds, in a graph the base index holds nothing for: a named graph first written after the last build, or the default graph of a ledger whose indexed data all sits in named graphs. Reads are right until the build (novelty has the retraction), and after it the fact is a live row again, in every order. A full rebuild never does this, and neither does a graph that already has a partition in the base index, which is why it mostly looks like it "only happens with named graphs". The fix is small and lives in the indexer: the fresh branch an incremental build writes for such a graph now resolves each fact's events the way a full rebuild does, through one shared
LeafWritermethod, so a retraction can't become a row there anymore and the window's history isn't dropped either.Three neighbouring gaps in the same routing are closed here too, rather than left for an issue. A published branch with no leaves silently swallowed a window's writes. Bulk import wrote exactly such a branch, a SPOT with no leaves, for every graph it had no quads for, and an incremental build then kept that SPOT empty while writing the next window's facts to the other three orders, so on
maindefault-graph writes after a named-graph-only import never reach SPOT (more on what that looks like below). And a base root missing some of a graph's sort orders would have had them rebuilt from the window alone.What main does
Reproduced on main at
f3c3b00ec, file-backed, background indexing off:GRAPH <g2> { ex:a ex:q "base" }.INSERT DATA { ex:s ex:p "x" }(the default graph, which has no partition), thenDELETE DATA { ex:s ex:p "x" }.ex:s ex:p ?ois empty. Build incrementally and publish, and it returns"x".The same happens with
GRAPH <g1>(a graph new since the build), with a JSON-LDdeleteinstead ofDELETE DATA, and for an integer, a language-tagged string and a ref, not just strings. A value replaced in the window (DELETE … INSERT … WHERE) keeps both the old and the new value after the build. And the window's history is gone: at thetbetween the insert and the delete, the fact reads as absent.<g1>(new)<g2>(new)<g2>only<g2>only<g1>(new)<g2>only<g2>Each row is run with SPARQL and JSON-LD deletes, so 24 cases in the test, 8 red on main.
It doesn't take an explicit build either. With the default settings the background indexer runs this same incremental build, and while it's busy with an earlier write, an insert and a delete in such a graph land in one window for its next build. In a probe with the production defaults and a large write in flight, the fact came back after the background build every time (10 of 10 runs for each graph).
background_indexing_keeps_deleted_facts_deletedpins that shape deterministically: it holds the background indexer under its soft threshold until a commit after the insert and the delete crosses it, drives no build itself, and on main reads"x"after that build.Fwiw, the original report also saw a full build resurrect the fact, and answers that changed when a ledger id was reused across tempdirs. As far as I can tell both come from the background indexer
FlureeBuilder::filestarts by default, which runs this same incremental build on its own and publishes alongside the explicit one. Running the report's own probe (ten cases, includingMOVE <g1> TO <g2>) twice in each of four setups on main: with background indexing on, the full-build cases came back too; withwithout_indexing(), only the incremental ones did; and running the cases in reverse order, or reusing a ledger id, changed nothing in either setup. So I don't think there's a cache keyed by ledger id that outlives aFlureeinstance here. With this branch, all 80 of those reads stay deleted. The tests in this PR turn background indexing off for that reason, except the one that's about the background indexer.What main does after a named-graph-only import
Reproduced on main at
04e1a6d37. Bulk-import a TriG file whose quads are all in named graphs (here one quad inGRAPH <g>, plus an emptyGRAPH <e> { }block), then write to the default graph and build:<e>the same. (An emptyGRAPHblock gets a graph id, and the import's SPOT build published a result for a graph even when it had no records for it, unlike the other three orders.)<e>.What that looks like, once those facts are indexed:
ex:s ex:p ?o,ex:s ?p ?o), a fully boundASK(false),?s ?p ?o(empty, soDISTINCT ?sandGROUP BY ?sare too),CONSTRUCT { ex:s ?p ?o } WHERE { ex:s ?p ?o }, the JSON-LD subject crawl (only the@idcomes back), time travel by subject, and a join whose plan looks the subject up (?s ex:p "x" . ?s ex:r ?o2came back empty).?s ex:p ?o,?s ex:p "x",?s ?p ex:o),COUNT(*)(so it counts rows that?s ?p ?odoesn't return), aFILTER(?s = ex:s)over a predicate scan, and theOPTIONALand property path I tried.WHEREbinds the subject misses them too.DELETE { ex:s ex:p ?o } WHERE { ex:s ex:p ?o }deletes nothing, and a JSON-LD upsert ofex:s2keeps the old value next to the new one.An index in this state is repaired by a reindex, which builds every order from the commits. With this PR the next build repairs it as well. For the default graph that's whatever the window touches; for a named graph it's the next time that graph is written.
Cause
incremental_indexgroups the window's novelty by graph and gives each (graph, order) a task. A graph with no branch in the base root takesDefaultFreshorNamedFresh, which built the branch withbuild_fresh_default_graph_v3. That function pushed every net record as a row and never looked at its op ("Currently only assertions appear in fresh branches so ops are not consulted"), andbuild_fresh_named_graph_v3passed it no ops at all. But lifecycle dedup leaves one net record per fact, and for a fact inserted then deleted in the window that record is the retraction, so the retraction was written as a live row. The events dedup superseded (here, the insert) were dropped with a "permanent gap" warning, which is the lost history.The leaf merge (
merge_novelty) and the full rebuild (index_build.rs) both get this right, because each resolves a fact's events withresolve_transitionsbefore deciding what's a row. The fresh branch was the one writer that didn't.The fix
LeafWriter::push_lifecycletakes one fact's events, resolves them from absent, sends the transitions to the sidecar and writes a row only for a final assert. The full rebuild's loop now calls it instead of its own copy of that logic, so the rebuild and the fresh branch can't drift apart.build_fresh_branch_v3replaces the two fresh builders (they were one function already). It walks the net records with their ops, gathers each fact's superseded events with the leaf merge's owngather_identity_events, and hands them topush_lifecycle. A superseded event left without its fact is an error rather than a warning, since it would mean lost history.slice_novelty_to_leavesroutes nothing into a branch with no leaves, so publishing it would silently drop that graph's later writes. The task reportsUnchangedinstead, and the next build sees the graph as fresh again. The two fresh arms ofexecute_phase2_taskare one arm now.slice_novelty_to_leavesfound no leaf and returned no slices, so that window's writes for the graph were dropped without an error. The task now takes the fresh path whenever the base branch has no leaves: from the root's inline leaves for the default graph, and from the fetched manifest for a named graph, since that's the first point the branch's contents are known. Andslice_novelty_to_leavesnow refuses novelty for a branch with no leaves instead of returning nothing, so a caller that misses this can't drop writes quietly again (it's an error, and the build falls back to a full rebuild).PersistingLeafWriter::finish, which both use, returns no result when it wrote no leaf, so neither writer can publish a branch with no leaves. On main a full rebuild published one for a graph whose log nets to no row and no history (a lone retraction of a fact never asserted, say), and the import's SPOT build published one for every graph it had no quads for. Readers already treat a missing branch and an empty one the same.build_branch_bytes(order, g_id, &[])(the decoder reads one branch version, every writer builds branches through that function, and the CIDs match what main's import wrote), so it needs no fetch. That's a SHA-256 per branch, though, which measured about as much as decoding the root itself, so it's only done for a named graph with some orders but not all, the older import's shape. A root an older import wrote then has no facts for those graphs and builds incrementally. The default graph's SPOT-missing root is partial, so it's refused as an incremental abort, and the caller falls back to a full rebuild, which builds every order from the commits.GRAPHblock is written to): the tasks have fetched its branches by then, so their leaves are known at no extra cost. Such a graph is repaired the next time it's written; until then it's carried as it is, as any graph the window doesn't touch is. The check costs nothing on a consistent root.No API, wire format or index format change. An index already built with a resurrected row, or with facts missing from SPOT, is repaired by a full reindex, which walks the commits from genesis.
8049948e4cf1ba3f9feaaaf0891910e08ddc1309f8af5b53f4d17b,dab12594e9c946b45b2eaa71549b117c1de3227104dddmain(57bf7a944)ebbea4ff577cef24d9326fe7c06af9f5bf94: test helpers that publish an index fail closed (see "Test harness")ba1430dd8main(1d06ae2ef)01a49799dpublish_built_indexTests
it_delete_survives_index_build.rs(ingrp_index):deleted_facts_stay_deleted_after_index_build: the 24-case table above, with a string, an integer, a language-tagged string and a ref in each, read through the instance that built and through a fresh instance over the same storage.replaced_value_stays_replaced_after_incremental_build:DELETE … INSERT … WHEREin the default graph and in a new named graph keeps only the new value.history_of_new_graph_survives_incremental_build: after the build the fact is absent before its insert, present between the insert and the delete, and absent at the delete.background_indexing_keeps_deleted_facts_deleted: the default graph and a new named graph, indexed only by the background indexer. It's held under its soft threshold (100 KB, catch-up sweeps off, since those ignore the threshold): the insert and the delete each assert from their own commit'sindexing.neededthat they started no build, and the next commit crosses the threshold, so the one build after the base's provably takes both.graphs_an_import_left_empty_take_facts_incrementally: a TriG import with one quad in<g2>and an emptyGRAPH <g3> { }block publishes no order with no leaves; a default-graph and a<g3>write then build withbuild_incremental_index_for_record(no fallback) and read by subject. The same runs against the import's root rewritten to what an older import wrote (a SPOT with no leaves for each).facts_missing_from_spot_are_rebuilt: after the same import, a write and an incremental build, the root is rewritten to the shape main publishes (SPOT with no leaves, the window's facts in the other three orders), which reads by subject as empty and by predicate as"x". A second write's incremental build is then anIncrementalAbort, and the full rebuild brings both facts back by subject. It runs for the default graph, which the order-set check refuses, and for<g3>, which the Phase 2 check refuses.Unit tests in the indexer:
fresh_branch_writes_no_row_for_a_retracted_fact(one row, one sidecar, and a stranded superseded event refused) andfresh_task_with_nothing_to_hold_publishes_no_branch.leafless_branch_is_built_fresh: a default-graph order with no leaves and a stored named-graph branch with no leaves each take an asserted fact into a row. With main's routing and slicing it gets 0 rows, i.e. the write is dropped.leafless_branch_refuses_novelty: slicing novelty into a branch with no leaves is an error; slicing nothing is fine.build_publishes_no_branch_for_a_graph_with_nothing_to_hold: a rebuild over a lone retraction publishes no graph.graph_without_records_publishes_no_branch: the import's build for a graph with no records publishes no branch in any order, SPOT included.partial_order_root_is_refused: a default graph or a named graph with facts in two of the four orders is an incremental abort, and so is a default graph's SPOT with no leaves beside three orders with leaves; none, all four, a lone SPOT with no leaves, or four orders with no leaves are fine, and a named graph with all four orders is left to the Phase 2 check.tasks_that_disagree_on_base_facts_are_refused, andleafless_branch_is_built_freshnow also checks that such a task reports no base facts.Non-vacuity: with the indexer and binary-index sources reverted to main (
f3c3b00ec) and the tests kept, all six integration tests fail: 8 of 24 cases come back, the replaced value keeps"old", the history read is empty at the insert'st, the background test reads"x"after its one build, the import publishes a SPOT with no leaves for the default graph and for<g3>, and the incremental build accepts the SPOT-missing root (after reading it as empty by subject and"x"by predicate, as above). At1309f8af5the two new tests fail as well: the import still publishes those orders, and the build refuses the root it makes. Each mechanism goes red under a mutation of its own, applied after the commit and restored after:push_record(2 rows, not 1), the empty-branch check off, either half of the leafless routing off (both off with main's slicing gives the 0-row drop above), and the slicing refusal off, each red in its unit test;PersistingLeafWriter::finishpublishing a result with no leaves:build_publishes_no_branch_for_a_graph_with_nothing_to_hold,graph_without_records_publishes_no_branchand the import test fail;partial_order_root_is_refusedand the import test's older-import root fail (an abort for graph 0); the same for a named branch with no leaves (an abort for<g3>'s graph);tasks_that_disagree_on_base_facts_are_refusedfails, and so does the SPOT test's<g3>case, where the incremental build accepts the root;Test harness
This branch also carries a test-support change, merged from
af9f5bf94.publish_indexdeclines, without an error, an index whosetisn't newer than the one already published, so a test that builds an index at atthe background indexer has already published goes on to read the indexer's build instead of its own. The helpers that publish a test's build (rebuild_and_publish_index,build_and_publish_indexandbuild_incrementally_and_publish_indexinsupport,it_merge'sindex_branch, and eight direct publishes init_import_v3,it_indexing_fuel,it_storage_encryptedandit_merge) now go through onesupport::publish_built_index. It publishes allow-equal, the wayFluree::reindexdoes, then asserts that the nameservice holds the root that was just built, and panics otherwise. In three runs of the API suite onmainwith a detect-only version of the helper, 31 tests hit this: one deterministically (it_query_time_travel_bgp::repeat_full_rebuild_restores_retracted_history, whose second rebuild at the sametwas never published, so it re-read the first), and 30 through the background indexer of a file-backedFlureepublishing first. None of their verdicts changes with the fix. The background indexer can still build between a test's other writes and reads in those files; moving them towithout_indexing()isn't done here. The tests this PR adds publish through the same helper.Performance
Release builds of one harness, file-backed:
<g2>.<g9>or the existing<g2>.inc_many_named: 2,000 named graphs of 10 subjects, with a 100-subject window in the default graph.<g2>, and the same plus 40,000 in the default graph.Each figure is the median of 7 builds in one process, three rounds interleaving the two sides. The box was shared with other work (load 18–37, pageouts at most about 7 a second), so the comparison rests on instructions retired and allocations, both read for the whole process around each build, which don't move with load. Wall-clock is secondary.
This PR against
main(57bf7a944), instructions per build (each run's minimum, the least affected by spinning threads; the three rounds' spread is within 0.5%):<g9>+ default)<g2>(the named-graph merge)<g9>inc_many_namedisn't in the table because its instruction count is bimodal within a single run, on both sides: about 2.75 G or about 3.93 G per build, depending on whether threads spin. In six more interleaved rounds the high mode was 3,940 M onmainand 3,934 M here. Its allocations are deterministic: +0.47% here (one smallVecper named graph for the order-set check).This review round alone (the PR at
1309f8af5vs77cef24d9, both on57bf7a944): every row is within ±0.3% instructions, with identical allocations. So the import fix, the order-set check and the Phase 2 check cost nothing measurable. The small increases above come from the lifecycle resolution the fresh branch and the rebuild loop now share.mainwas dropping (two transitions per deleted fact, four orders), the same history the merge path already writes for an existing graph. An earlier quiet-box run showed that with the fresh writer's history turned off, that window costs what it costs onmain.main's 1.3% spread across rounds, and an earlier quiet-box run had it within noise. The rest were within their spread.Gates
At
01a49799d, after mergingmainat1d06ae2ef, with--all-features:cargo check --workspace --all-targets --all-features: clean.cargo fmt --all --check: clean.cargo clippy -p fluree-db-binary-index -p fluree-db-indexer -p fluree-db-api --all-targets --all-features --no-deps -- -D warnings: clean, with the edited files touched first so they're actually re-linted.cargo test -p fluree-db-binary-index: 433 passed, 0 failed, 2 ignored.cargo test -p fluree-db-indexer: 464 passed, 0 failed, 7 ignored.cargo test -p fluree-db-api --no-fail-fast: 5,078 passed, 0 failed, 138 ignored. The import tests (grp_import) are 122 passed,grp_index145 andgrp_query531. In two earlier full runs on this branch,it_jsonld_join_batched_lane::jsonld_join_takes_batched_subject_probe_like_sparqlfailed once each: its rows were right but the routing event it captures came back empty. It fails the same way onmainat57bf7a944(1 of 3grp_queryruns) and passes alone, so it's intermittent there and not from this PR.cargo test -p fluree-db-cli --test integration(itscreate --fromtests go through import): 177 passed, 0 failed.