Repository navigation
fix: db() reflects owned-state commits (read-your-writes) - #1385
Conversation
The owned-state API (`insert`/`update`/`transact(ledger, ...)` and the `transact(...).execute()` builder) committed and published to the nameservice but returned a new `LedgerState` without writing it back to the `LedgerManager` cache. A subsequent `fluree.db()` / `ledger_cached()` on a warm cache then served the pre-commit view — a read-your-writes violation (issue #1330). Add `Fluree::finalize_owned_commit`, a shared tail for the owned-state commit methods that writes the committed state back into the cache (monotonic, only when already cached) before computing indexing status and triggering background indexing. This also consolidates six duplicated post-commit tails. The guarded builder path is unaffected — it already updates the cache via `finalize_commit` under the write lock, which is why the server transaction path was never affected. - `LedgerManager::get_loaded_handle`: fetch a cached handle without forcing a load from the nameservice. - Drop the `db_at_t` workarounds in `it_cyclic_bgp_probe` and `it_join_batched_overlay`; add `it_read_your_writes` regression test. - `it_notify_incremental` now creates a genuine cross-writer gap via a peer `LedgerManager` (in-process commits no longer leave the writer's own cache stale — that's the fix). - `it_query_sparql_indexed`: head-with-novelty views now take the production overlay fast path, which renders a decimal AVG as a string. Closes #1330
| @@ -195,18 +189,16 @@ async fn cyclic_bgp_bounded_probe_matches_fallback() { | |||
|
|
|||
| clear_cyclic_env(); | |||
| std::env::set_var("FLUREE_CYCLIC_BGP_PROBE_SCAN_RATIO", "1"); | |||
| let (spans, guard) = span_capture::init_test_tracing(); | |||
| let probed = run_query(&fluree, &view, query).await; | |||
| drop(guard); | |||
| assert_eq!( | |||
| probed, expected, | |||
| "{name}: probed cascade under novelty != fallback" | |||
| ); | |||
| if name == "directed-triangle" { | |||
| assert!( | |||
| spans.has_event("cyclic cascade: probing edge per-subject"), | |||
| "{name}: bounded probes should engage under novelty" | |||
| ); | |||
| // At head the view is the binary index plus a separate | |||
| // novelty overlay; the bounded probe declines on that fast | |||
| // path (the overlay-merging fallback serves these rows), so | |||
| // we assert the merged result rather than probe engagement. | |||
There was a problem hiding this comment.
This is a claude-code-discovered item re: test coverage and I'm just going to paste-in as-is:
— The switch from `db_at_t(novelty_t)` to `db()` is correct for the
read-your-writes story, but it changes which lane serves the query: at head the
view is the binary index plus a separate novelty overlay, so the bounded probe
declines and the overlay-merging fallback serves the rows. To accommodate this
the test **dropped its only assertion that the bounded cyclic probe actually
engages** (the former `spans.has_event("cyclic cascade: probing edge
per-subject")` check). Verified repo-wide there is no other coverage of probe
activation: the event is emitted only at `fluree-db-query/src/cyclic_bgp.rs:1340`
and `:1442`, and `span_capture`/`has_event` no longer appear anywhere in this
test file. Bounded-probe activation in `cyclic_bgp.rs` is now uncovered;
only result-equivalence remains. Suggest retaining the probe-engagement
assertion on a separate case that still engages the probe (e.g. a time-pinned /
merged view) while keeping the new `db()` result comparison.
The read-your-writes switch from db_at_t(novelty_t) to db() moved the Phase 2 novelty query onto the head-with-separate-overlay lane, where the bounded probe declines (overlay unmergeable), so the probe-engagement assertion was dropped — leaving only fallback-equivalence checks that a silently always-declining probe would still pass. Restore activation coverage in Phase 1 instead: at the indexed HEAD with no novelty the overlay lane is Clean and probing is allowed, so a probe-eligible query emits the per-subject probe event. Capture spans across the probed lane and assert the bounded probe engaged at least once.
|
Addressed in 21ce914 Note on approach: I restored the probe-engagement assertion in Phase 1 (indexed HEAD, no novelty) rather than on a time-pinned/merged view as suggested — post-fix that view no longer engages the probe. |
Problem
Closes #1330
Calling
fluree.db(ledger_id)after committing through the owned-state API could return a previously cachedGraphDbview that predates those commits — a read-your-writes violation.The owned-state API (
insert/update/transact(ledger, ...)and thetransact(...).execute()builder) consumes a caller-suppliedLedgerState, commits, and publishes to the nameservice, then returns a newLedgerState— but it never wrote that state back into theLedgerManagercache. A subsequentdb()/ledger_cached()on a warm cache therefore served the pre-commit view.The guarded builder path (
fluree.stage(&handle).execute()) was never affected: it holds the ledger write lock across stage + commit and replaces the cached state viafinalize_commit. The server transaction path (LocalCommitter) uses that guarded path, so server-side read-your-writes was already correct — this only affected the embedded owned-state API.Fix
Fluree::finalize_owned_commit, a shared post-commit tail for the owned-state methods that writes the committed state back into the cache (viasync_owned_commit_to_cache) before computing the indexing status and triggering background indexing. This also consolidates six duplicated post-commit tails into one.sync_owned_commit_to_cacheis monotonic (skips when the cache has advanced past the new state) and only touches an already-cached handle — an uncached ledger loads fresh from the nameservice head on next access. On arefresh_indexfailure it evicts the entry so the next access reloads rather than serving stale state.LedgerManager::get_loaded_handleto fetch a cached handle without forcing a load.Tests
db_at_tworkarounds init_cyclic_bgp_probeandit_join_batched_overlay(the sites the issue called out).it_read_your_writesas a direct regression test.it_notify_incremental: in-process commits no longer leave the writer's own cache stale, so these now create a genuine cross-writer gap via a peerLedgerManager(the realistic scenarionotifycatch-up exists for).it_query_sparql_indexed: head-with-novelty views now take the production overlay fast path, which renders a decimalAVGas a precision-preserving string.Verification
fluree-db-apisuite (2253 tests) +fluree-db-server/fluree-db-consensustests pass.cargo fmt --all --checkandcargo clippy --all --all-features --all-targets -- -D warningsclean.Docs
Updated
docs/getting-started/rust-api.mdanddocs/concepts/time-travel.mdto state that a writer reads its own writes in-process, with eventual consistency remaining a cross-process concern.