Repository navigation
feat: DROP takes a graph and its history out of the ledger - #2251
Conversation
SPARQL DROP used to retract the graph's facts, as CLEAR does: one commit sized by the graph, capped by FLUREE_MAX_GRAPH_SCAN_FLAKES, with the facts still queryable as of an earlier t. A drop is now a record in the commit: Commit::graph_drops names each dropped graph by IRI (urn:default for the default graph), behind envelope flag 0x20. The commit retracts nothing, so it costs the same for a graph of any size. - The graph registry keeps a floor t per dropped graph (GraphDrop). Nothing from before the floor is queryable: until an index build covers the drop, readers serve the graph from novelty alone (BinaryIndexStore:: without_graphs), and a query naming it as of an earlier t is refused. Writing the IRI again revives it under the same g_id at the writing commit's t, on every write path: transactions (each op of a multi-op request at its own t), replay, commit transfer and graph import. A DELETE alone does not revive it. - Index roots carry the drops at or before index_t in a graph_drops section (FIR6 extended flag bit 3) that older decoders refuse. An incremental build purges a dropped graph's leaves; a rebuild's resolver skips ops before a later drop, and root assembly filters annotation events by the same floors, including those merged from the previous root's arena. A rebuild numbers graphs differently from the ledger state, so drops carried across an index install match by IRI. - Dropping needs an identity without a restricting policy (403 otherwise). DROP of a graph that does not exist, or was dropped, is an error unless SILENT. A drop advances the schema and SHACL epochs even when the graph is only in the index, so cached shapes from it go too. - A non-fast-forward merge or rebase, and the merge preview, refuse a drop on either side. Revert and its preview share one check, which refuses reverting a drop or a write to a graph dropped later. Push and paged pull refuse commits that drop graphs. - fluree graph drop, POST /drop-graph, the Graph Store Protocol's DELETE of a named graph, Python Ledger.drop_graph and MOVE's source all drop this way. A graph import can fill a dropped IRI again. Tests: it_graph_drop.rs, it_import_into_graph:: an_import_refills_a_dropped_graph, and the ledger unit test installing_a_renumbered_root_keeps_drops_on_their_graphs.
…apshots A BM25 or vector sync walks the commits since its watermark and re-indexes the subjects their facts touch. A drop commit names graphs and carries no facts, so the walk found nothing to remove: the index kept serving the dropped graph's documents, and BM25's older snapshots kept them for searches as of an earlier t. - ir::GraphReads lists the graphs a parsed query reads beyond the one it runs on, from every form the parser lowers to a graph pattern (["graph", ...], a node-level @graph or an alias of it), through optional, union, minus, exists, subqueries and solution modifiers. A graph variable, a service, the union default graph or reasoning counts as every graph. - graph_source::helpers::latest_drop_read resolves those names as a query does (TargetLedger::graph_position), adds the default graph, and returns the latest drop among them from the ledger's graph registry; a query that does not parse counts as reading every graph. - An incremental BM25 or vector sync with such a drop past its watermark takes the full rebuild. A drop of a graph the query does not read leaves the sync incremental. - Every BM25 rebuild (the resync that sync falls back to, an explicit resync_bm25_index, sync_bm25_index_to) retires the manifest's snapshots from before that drop (Bm25Manifest::retire_before) in the same publish that adds the new one, and deletes their blobs after it. A search as of a t before the drop finds no snapshot. Vector indexes keep only their head. Searches still serve the snapshot they had until the next sync, as after any write. Tests: it_bm25_graph_drop.rs and vector_sync_after_a_drop_rebuilds_from_what_the_ledger_holds, plus GraphReads and retire_before unit tests.
The schema-bundle caches key on (ledger, to_t), which assumed what a ledger held as of a t never changes. A drop changes it: once a reasoning query as of t had cached the bundle of its f:schemaSource graph, the same query as of t after DROP GRAPH of that graph still reasoned with the dropped schema, while a cold process read the graph as empty. resolve_schema_bundle now refuses, cached bundle or not, a bundle reading a named graph that a commit after to_t dropped (404, as a GRAPH naming it as of to_t is). The default graph is never a cached source: build_schema_bundle_flakes leaves it to the query's own reads. Test: reasoning_as_of_before_a_schema_graph_drop_is_refused.
aaj3f
left a comment
There was a problem hiding this comment.
@bplatz this is really nice, and at a design level no pushback from me: recording the drop in the commit, a floor per graph in the registry, and without_graphs as the one place every index reader learns of it is pretty much exactly the shape I'd have hoped for, and it closes the dead end from #2232 where a big imported graph couldn't be dropped or re-imported. A few headline notes:
(1) The one design element I'd change is how an as-of read learns of a drop after the index. historical.rs:161 walks every unindexed commit's envelope on every time-travel read at or below index_t, on every ledger, dropped graphs or not. Claude measured ~0.24 ms per commit on local disk (500 unindexed commits: 118.6 ms vs 2.9 ms), and on object storage each one is a GET. The cached head already knows those drops, so I think taking them from it (and walking only when there's no matching head) keeps the correctness without the cost. Details below.
(2) This PR is the class fix for "a reader that must notice a dropped graph", and without_graphs covers the index readers well. The class it leaves open is graph_id_for_iri answering for a dropped graph, which the configured-source resolvers use as their existence check:
f:policySource(policy_builder.rs:82),f:shapesSource(tx.rs:1211,config_resolver.rs:717),f:constraintsSource(tx.rs:2363),f:rulesSource(view/fluree_ext.rs:1344), a datalog rule's target graph (execute.rs:521),validate.rs:630; andf:schemaSource, whose as-of casede06cdbddfixed by hand
The policy one is a must: Claude's probe shows a governed read as of a t before the drop of the policy graph returning what that policy hid. Splitting the lookup into "assigned id" (routing) and "exists as of t" would make every caller choose, and I'd like that in this PR since it already touches the chokepoint.
(3) On the semantics, I'm on board with both calls. DROP taking the graph and its history out of queries while the commits keep the facts is what the spec means by DROP, and it closes the import dead end from #2232. One small ask there: let's say plainly in compatibility.md and the SPARQL page that a drop is not a deletion, since the commits keep the facts and a branch from before the drop still reads them (the compatibility.md entry is a natural home, next to the inline note on its recipe). And dropping needing an unrestricted identity makes sense to me: a drop takes history the caller's policy may hide, and CLEAR stays available under policy. If a governed client ever needs to drop, a drop permission in the policy vocabulary seems like the additive path later, but that's just a thought for down the road, not something I'd want in this PR.
(4) More of a question than an ask: shipping this while push and pull refuse drop-bearing commits seems fine to me, with the release notes saying so. But I'd like your read on whether the release that carries this should also carry #2252, so a DROP never strands a ledger's push/pull in the meantime. Since #2256 merges the latest main in before it tags, that's partly a question of whether this lands before or after the 4.2.6 tag.
Merge-wise: it conflicts with main in 8 files, all mechanical (both sides adding a field or a variant), and on Claude's box the resolved tree is green apart from the one failing test below; no CI test job has run on this head. It merges cleanly with my #2214, and neither PR's fast lanes bypass the other's graph selection, so no ordering constraint between them. With your #2249 it conflicts in the registry and replay code, and the two interact: once any #config IRI resolves to the config slot, a drop record naming one (which a #2069-era branch can hold today) would drop the branch's config on replay, so whichever lands second needs the reserved-id guard noted inline. I'd guess #2249 lands first, since it's closer, in which case this one carries the guard.
Full review below:
🔄 Request changes.
This is carefully built, @bplatz, and the test surface is great: it covers revival in a multi-op request, a transferred write, a restart, both index builds, annotations and branch operations, and the crux tests are real guards: Claude reverted the transact path's revival t, the BM25 sync trigger, the reasoning cache-hit refusal and the as-of window walk, and each one turns its tests red. Four things need to land first. Time-travel reads below index_t now pay one envelope read per unindexed commit on every ledger (CRITICAL, with a fix that keeps the correctness). A governed read as of a t before the drop of the f:policySource graph runs without that policy, because a dropped graph still resolves where an unknown one fails closed. Hydration shows a dropped edge annotation's empty @annotation until the next build. And one existing test fails on this head. Beyond those, the one small ask from the headline is the "a drop is not a deletion" sentence in the docs. The rest below is optional.
Adherence to repo commitments:
- Patterns/abstractions:
⚠️ without_graphsis the right chokepoint for index readers and extends the existing novelty-only path; the gap isgraph_id_for_iristill serving as an existence check for configured sources, and the lifecycle rule is implemented twice (registry and indexer). - Performance (speed first, memory second): ✖ CRITICAL:
historical.rs:161adds O(unindexed commits) serial envelope reads to every time-travel read at or belowindex_t, on every ledger (measured 118.6 ms vs 2.9 ms at 500 commits on local disk). The query, commit, replay and indexing paths are otherwise neutral: the new checks return early on ledgers without drops, andwithout_graphsclones a map ofArcs once per drop. - Deployment targets:
⚠️ Shared code in core, ledger, query and the API, so the embedded library, the server and wasm32 all run it. The schema-bundle cache is per-process and keyed onto_t, but the refusal re-checks the registry on every hit, so it doesn't depend on cross-process invalidation; no background task is added. The time-travel walk is worst exactly on an embedder over object storage (each envelope a GET, e.g. AWS Lambda over S3), which no CI job models. - Testing:
⚠️ The new tests are wired (grp_ledger,grp_graphsource,grp_import,grp_reasoning,it_graph_source_vector, unit tests) and all pass on Claude's box, but the workspace suite has one failure (it_delete_stored_facts, below), no CI test job ran on this head, and nothing pins the as-of policy-source, arena or time-travel-cost cases. - Conventions: ✔ Thorough multi-line commit bodies, a self-describing title, fmt and clippy (
--all-features --all-targets -D warnings) clean, W3C SPARQL suites green, and docs updated across compatibility, SPARQL, CLI, Graph Store, BM25, vector and the index format.
Verified at branch HEAD (de06cdbdd) on an EC2 box: fmt and clippy clean, cargo nextest run --workspace --all-features 15146/15147 (the one failure is inline), doctests 48/48, default-features cargo check clean, testsuite-sparql 36/36 suites. Four mutation checks go red as they should: reviving one t late on the transact path (2 tests), the BM25 sync ignoring a drop (3 of 5), the reasoning cache hit skipping its refusal (1 of 1), and the window walk removed (1 test, with the time-travel cost back to 2.9 ms). Three probes: the time-travel cost (above), an as-of read under a dropped f:policySource, and hydration of a dropped edge's annotation before the next build.
Requesting changes for the time-travel walk, the configured-source resolvers (above all f:policySource), the arena and the failing test; once those are in, I'm happy to approve. Happy to talk through any of these.
| // commits up to target_t (index_t=0), producing a correct time-travel snapshot | ||
| // without relying on index history coverage. | ||
| let overlay = if let Some(head_cid) = &record.commit_head_id { | ||
| if target_t <= index_t && record.commit_t > index_t { |
There was a problem hiding this comment.
CRITICAL (blocking, performance): every time-travel read at or below index_t now reads one commit envelope per unindexed commit, on every ledger.
This branch runs window_lifecycles whenever target_t <= index_t && commit_t > index_t. Before this PR that case read no commit at all: it loaded the root and answered from the index. Now it walks the first-parent chain from the head down to index_t, one load_commit_envelope_by_id per commit, each a 128 KiB range read (ENVELOPE_PROBE_LEN, commit.rs:402), and serial because each envelope names its parent. Nothing gates it on the ledger ever having dropped a graph, and "indexing lags the head" is the normal state of a server under write load.
Claude measured it on a file-backed ledger (index at t=1, then N unindexed commits, db_at_t(ledger, 1) plus a one-pattern query, median of 15): 500 commits → 118.6 ms with this branch, 2.9 ms with it disabled; 2000 commits → 486.9 ms vs 3.7 ms. That's about 0.24 ms per envelope on local disk. On object storage each one is a network GET, so an embedder on S3 with a few hundred unindexed commits would pay on the order of seconds per as-of query (Claude measured local disk only; that's the GET count times typical object-store latency).
The walk is load-bearing, though. With it disabled, write_clear_write_drop_recreate_survives_restart_index_and_reindex goes red (an as-of read below the index stops knowing about a drop after it). So the fix is to keep the information and stop re-reading it. load_graph_db_at_commit (view/fluree_ext.rs:361) already holds the cached head, and its registry has applied every drop in that window on commit, catch-up or load. When the head's commit is the record's head, its graph_drops() (by IRI) are exactly what the walk computes, so they could be passed into HistoricalLedgerView::load_at and the walk skipped; walk only when the caller has no matching head (a stale handle in another process, say). A small in-process cache keyed by (head_cid, index_t) would also work, but the head is already in hand. I'd also like a time-travel-below-index_t scenario in a bench, since nothing would catch this coming back.
| /// Forward lookup: IRI → GraphId. | ||
| /// Forward lookup: IRI → GraphId. A dropped graph keeps its id, so this | ||
| /// answers for it too; [`Self::is_dropped`] tells it apart. | ||
| pub fn graph_id_for_iri(&self, iri: &str) -> Option<GraphId> { |
There was a problem hiding this comment.
(Real location: fluree-db-api/src/policy_builder.rs:82.)
Blocking (security): a governed read as of a t before the drop of the f:policySource graph runs without the policy that was in force then.
graph_id_for_iri keeps answering for a dropped graph (by design, for write routing), and resolve_policy_source_g_ids uses it as its existence check. So a dropped policy graph resolves, the policy loader reads it as of t, and what it held as of t is gone, so it reads no rules. Reasoning has the same shape and this PR refuses it (refuse_dropped_sources, ontology_imports.rs:159); policy doesn't.
Claude's probe: ex:alice ex:ssn in the default graph; a view-deny on ex:ssn in <http://example.org/policies>; config with f:defaultAllow true, f:policyClass f:AccessPolicy and f:policySource naming that graph (t2). As of t2, a governed read hides the ssn. Then DROP GRAPH <…/policies> and an INSERT DATA writing a replacement rule into it (the way an operator swaps a policy set). Afterwards the governed read at the head still hides the ssn, but the same read as of t2 returns it. With CLEAR in place of DROP, the read as of t2 keeps hiding it, as main's DROP did.
The fix is to treat a dropped graph the way these resolvers treat an unknown one, which it_config_graph.rs:6434 already pins as a fail-closed contract for f:policySource, and refuse as of a t before the drop the way refuse_dropped_sources does. The same resolver shape sits at f:shapesSource (tx.rs:1211, config_resolver.rs:717), f:constraintsSource (tx.rs:2363), f:rulesSource (view/fluree_ext.rs:1344), a datalog rule's target graph (datalog_rules/execute.rs:521) and the validate API (validate.rs:630). I think the cleanest version is a registry method that answers existence rather than assignment, roughly:
/// The graph `iri` names as of `t`: `Err(floor)` when a drop after `t`
/// took it, `Ok(None)` when it does not exist (never written, or dropped
/// and not written since).
pub fn existing_graph_id(&self, iri: &str, t: i64) -> Result<Option<GraphId>, i64>with graph_id_for_iri renamed to something like assigned_graph_id so each caller has to pick one. More on this in the headline.
Commenting here because policy_builder.rs and the other resolvers are not in this diff.
| /// registry marks them, and their index statistics go, since the index | ||
| /// facts they count are no longer visible. Applies before the commit's | ||
| /// own writes; see [`Self::revive_graphs`] for those. | ||
| pub fn apply_graph_drops(&mut self, g_ids: &[crate::GraphId], t: i64) { |
There was a problem hiding this comment.
Blocking (wrong results): an edge the drop took and a later write brought back hydrates with the dropped annotation's (empty) @annotation, until an index build covers the drop.
The annotation arena is ledger-wide and lives on the snapshot (annotation_index). LedgerState::apply_graph_drops has novelty forget the dropped graph's attachments, and the index builds filter or drop the arena, but nothing takes the sealed arena off the snapshot in between. So HydrationFormatter::arena_lookup_annotations still finds the pre-drop reifier for the edge, merged with novelty events that no longer retract it.
Claude's probe, the same setup as a_full_reindex_leaves_out_the_annotations_a_drop_took but without the reindex: index the annotated ex:alice ex:worksFor ex:acme {| ex:source "hr" |}, then DROP DEFAULT ; INSERT DATA { ex:alice ex:worksFor ex:acme . }. The SPARQL annotation query correctly returns nothing, but hydration, through a fresh load and through the cached head alike, returns {"@id":"ex:alice","ex:worksFor":{"@id":"ex:acme","@annotation":{}}} where the reindexed ledger returns {"@id":"ex:acme"}.
The incremental build already handles this by dropping the arena when it purges a graph ("Annotation reads fall back to scanning until a full reindex seals one", incremental.rs:877-883). Doing the same on the snapshot when the drop takes a graph the arena can hold edges of (the default graph always can) keeps reads right until the build. It costs the same as it does there: annotation reads take the scan path until the next build seals an arena, which on an annotation-heavy ledger is worth gating on the arena actually holding edges of a dropped graph, or else filtering arena hits by the registry's floor instead.
Roughly:
// in LedgerSnapshot::apply_graph_drops, after the registry and stats
if self.annotation_index.is_some() && arena_may_hold_edges_of(g_ids) {
// The arena may hold the dropped graphs' edges; the scan path reads
// through the masked store until a build seals a new one.
self.annotation_index = None;
}A test is the probe with its assertion: the a_full_reindex_… case minus the reindex.
| /// The refusal a policed (non-root) identity gets for an operation that | ||
| /// drops a graph: the drop takes facts and history the identity's policy may | ||
| /// not let it see, let alone modify. | ||
| fn drop_needs_unrestricted_identity(verb: &str) -> TransactError { |
There was a problem hiding this comment.
(Real location: fluree-db-api/tests/it_delete_stored_facts.rs:1670.)
Blocking: cargo nextest run --workspace --all-features fails one test on this head, and no CI test job has run on it.
it_delete_stored_facts::add_copy_and_move_are_refused_regardless_of_destination_contents (on main since ce9e6c197) checks that ADD/COPY/MOVE under a restricting policy are refused with the standard modify-policy refusal. All four MOVE cases now get this function's message instead ("MOVE drops a graph with its history, which only an identity without a restricting policy may do; …"), which not_refused doesn't recognize. It's the intended refusal, so it's one of two small changes: have not_refused accept it for MOVE (and update the test's doc comment, which still says MOVE "retracts the source"), or lead the message with the standard "Policy enforcement prevents modification" text, which keeps any client that matches on it working. I lean toward the second, since it's a policy refusal either way.
Commenting here because the test file is not in this diff.
| /// The ids of the graphs a commit's drop record names (`Commit:: | ||
| /// graph_drops`): [`DEFAULT_GRAPH_IRI`] for the default graph, else a | ||
| /// registered IRI. An IRI the registry does not hold names nothing here. | ||
| pub fn graph_ids_of_drops<'a>( |
There was a problem hiding this comment.
This is more of a hardening note than a bug on its own, but it becomes one with #2249. The authoring side never drops a system graph (stage.rs:1690 refuses a reserved g_id, and DROP NAMED/ALL take only user graphs), but nothing where a drop record is consumed checks that again. graph_ids_of_drops maps a record's IRIs through graph_id_for_iri with no reserved-id filter, and so does everything downstream of it: replay and catch-up (fluree-db-ledger/src/lib.rs:206, :1134), merge_graph_drops_by_iri, the rebuild's dropped_later (resolver.rs:1397), and apply_lifecycles / purge_dropped_graphs (incremental_resolve.rs:1029, :1073; the purge would even take a reserved graph's routing out of the root). And a record does arrive from outside the authoring path: a clone (import_commits_bulk, commit_transfer.rs:1903) stores commit blobs as they come, and a fast-forward merge adopts a branch's commits as committed.
The case that makes it real: on main, a branch of a never-indexed source holds the source's urn:fluree:<src>:main#config as an ordinary graph (#2069), so DROP ALL, DROP NAMED or DROP GRAPH of it on that branch records a drop naming a config IRI. #2249 makes any ledger's #config IRI resolve to the config slot (its graph_id_for_iri falls back to CONFIG_GRAPH_ID when the IRI isn't registered). So replaying that branch from its commits, or the fluree reindex #2249 prescribes for such ledgers, would map the record to g_id 2 and take the branch's config with it: its novelty, the store's index of it, and every config flake before the floor.
Skipping reserved ids where a record is consumed closes it, roughly:
// graph_ids_of_drops, after the filter_map
.filter(|g_id| *g_id == DEFAULT_GRAPH_ID || *g_id >= FIRST_USER_GRAPH_ID)with the same guard in the rebuild's floor mapping (dropped_later, apply_lifecycles). Minor today, but if you agree it's right, I'd rather see it folded in now than lost in the backlog.
| @@ -854,7 +854,7 @@ pub async fn incremental_index( | |||
| e => IndexerError::StorageWrite(format!("V6 incremental resolve: {e}")), | |||
There was a problem hiding this comment.
So minor, but IncrementalResolveError::NeedsRebuild (a dropped graph that may hold schema) lands in this catch-all as StorageWrite, so the expected fallback to a rebuild logs "incremental indexing failed, falling back to full rebuild" at warn. Mapping it to IndexerError::IncrementalAbort, which exists for exactly this, would keep the logs honest. If you agree, I'd fold it in.
| /// commit, `for_each_op` is a single linear pass over the ops buffer, so | ||
| /// finishing one commit's iteration after the flag is set is essentially | ||
| /// free relative to the work we save. | ||
| /// One commit's graph lifecycle: its `t`, the graphs it drops |
There was a problem hiding this comment.
The new block went in between chunk_has_vector_ops's doc comment (the "Detect whether any commit in the new chunk asserts or retracts a vector flake…" paragraph just above) and the function, so that doc now documents CommitLifecycle and chunk_has_vector_ops has none. Moving the block above the "Vector-op pre-scan" section header fixes both.
| /// The drop records `drops` (by this run's graph ids) become once | ||
| /// `lifecycles` apply, oldest first: each commit's drops, then the dropped | ||
| /// graphs it writes again. The default graph is revived by its own drop. | ||
| pub(crate) fn apply_lifecycles( |
There was a problem hiding this comment.
I don't think this is wrong today, but the lifecycle rule ("drops apply, then a dropped graph the commit writes revives at its t; the default graph revives at once") is implemented here over a raw BTreeMap<u16, GraphDrop> and again in GraphRegistry::apply_drops / revive, with three shapes for one commit's lifecycle (CommitGraphLifecycle in core, a tuple in the ledger crate, another here). We may want one helper in fluree-db-core that both the registry and the indexer call, so a later change to the rule (say #2254's clear marker) changes one place. Minor and non-blocking, but if you agree it's right, I'd rather see it folded in now than lost in the backlog.
|
|
||
| #### `DROP` drops a graph's history (breaking) | ||
|
|
||
| SPARQL `DROP GRAPH`, `DROP DEFAULT`, `DROP NAMED` and `DROP ALL` used to retract the graph's facts, as `CLEAR` does. They now take the graph out of the ledger: what it held is no longer queryable at the head or as of any earlier `t`, and a query that names the graph as of a `t` before the drop is refused with a 404. The drop commits without retracting anything, so it costs the same for any size of graph and is not limited by `FLUREE_MAX_GRAPH_SCAN_FLAKES`. Writing to the graph again starts it afresh, under the same IRI. The commits that wrote the dropped facts keep them: a branch created at a `t` before the drop reads them. The same applies to `fluree graph drop`, `POST /v1/fluree/drop-graph`, the Graph Store Protocol's `DELETE` of a named graph, the Python `Ledger.drop_graph`, and the source graph of `MOVE`. |
There was a problem hiding this comment.
Not a big deal, but the migration recipe further down this file (:478-481, ADD GRAPH <mydb:main> TO DEFAULT ; DROP GRAPH <mydb:main>) now also takes the old graph's history and needs an unrestricted identity. A clause saying CLEAR GRAPH <mydb:main> keeps the history (and works under policy) would keep the recipe honest. If you agree, I'd fold it in.
| /// | ||
| /// The derived store gets its own id: a cache keyed by store id may hold | ||
| /// what this store read of the removed graphs. | ||
| pub fn without_graphs(&self, g_ids: &[GraphId]) -> Self { |
There was a problem hiding this comment.
I really like without_graphs. A store that simply has no index for the dropped graph turns every reader of the index (scans, fast lanes, per-graph arenas, statistics) into the existing "graph created since the last build" path, so none of them has to know drops exist. (The ledger-wide annotation arena is the one reader it can't reach, inline above.) Claude traced every place a store gets attached to a state or view, and each one masks (index install after apply_loaded_db has carried the drops, load, catch-up, the historical view, build_commit, the multi-op fold). It also composes cleanly with #2214: its several-graph lanes take the graph set and the shared store from the dataset loads, which already come through select_graph_id, user_graphs and this mask.
Both sides extended the graph registry: the drop records here, and main's config graph aliases (#2249). has_unregistered keeps both rules: a dropped graph counts as unregistered, and any ledger's config graph IRI is the config graph, registered. Snapshot metadata carries both graph_drops and main's index_root_id; apply_index decodes the root through main's from_root, mutably, to carry the drops. Main's GraphPosition::OtherLedgersSystemGraph reads no graph, so the search-index drop probe (latest_drop_read) counts no drop for it. Main's add_copy_and_move_are_refused_regardless_of_destination_contents expected MOVE under policy to be refused by the modify check; here MOVE drops its source and is refused for a policed identity before either graph is read, a policy violation (403) of its own.
A drop record names graphs by IRI, and an IRI that named an ordinary graph where the drop was recorded can name a system graph where the record replays. Any ledger's config graph IRI is now the config graph, so a reindex of an index that held a source's config graph as an ordinary graph, after a drop of that graph, would drop the ledger's config graph. A record from a branch that held its source's system graph IRIs as ordinary graphs names the source's own system graphs once fast-forwarded into it. Every reader of a record now keeps only the default graph and user graphs: replay and catch-up, the merge of drops across numberings, and both index builds' floors and drop records. On an index that held the config graph as an ordinary graph, what a drop of it took comes back as the config graph after a reindex, which is how its commits read now.
A read as of a t the index covers must learn of the graphs a commit after the index dropped, and it read one commit envelope per unindexed commit for them, serially, on every such read: about 0.24 ms a commit on local disk, one GET each on object storage. The cached head already knows those drops, so a caller holding a state at the ledger's head commit hands its registry to the historical loader, which carries the drops over by IRI instead of reading the commits. Without a head at that commit (a handle another process left stale, or the public ledger_view_at), the loader still reads them. The query_time_travel_below_index bench measures both, against the unindexed commit count.
The lookup answers for any graph ever assigned an id, a dropped one among them, which routes a write but does not say the graph exists. The name says which question it answers, so a caller that needs the graph to exist has to pick the existence lookup instead.
The configured-source resolvers (f:policySource, f:shapesSource, f:constraintsSource, f:rulesSource, f:schemaSource and owl:imports, a datalog rule's target graph, the validate API, the cross-ledger materializers) used the id lookup as their existence check, and a dropped graph keeps its id. So a governed read as of a t before the drop of the f:policySource graph read that graph as empty and ran with no policy, showing what the policy hid. existing_graph_id(iri, t) answers whether the graph exists as of t: a graph a drop after t took is refused, as a query naming it as of t is, and one dropped by t and not written since does not exist, failing closed as an unknown source does. Every resolver above uses it. A dropped source therefore now refuses the writes or reads it governs until the graph is written again or the config changes, where it used to read as empty. An export as of t judges graphs the same way: one named as of a t before its drop is refused, and the graphs an export leaves out are counted as of t rather than at the head.
… novelty The sealed annotation arena is ledger-wide and predates a drop until the next index build covers it, so hydration and export still found the attachments the drop took: an edge written again after DROP DEFAULT hydrated with an empty @annotation, and exported with its old marker. Every arena event of a graph dropped after the index is older than the drop, so the drop took all of them: an edge of such a graph now takes its annotations from novelty alone, which forgot what the drop took and holds what came after. Other edges keep reading the arena, and a ledger with no drop since its index pays nothing.
The refusal of a drop to an identity under a restricting policy is a policy refusal, and clients match the standard "Policy enforcement prevents modification" text to recognize one. It now leads with that text, so MOVE's refusal reads as ADD's and COPY's do and the transfer test checks all three the same way again.
A dropped graph that may hold schema sends the incremental build to a full rebuild, as designed, but the resolver's NeedsRebuild reached the caller as a storage write failure, so the expected fallback logged as one. It now maps to IncrementalAbort, the error for exactly this.
A commit's drops apply, then the dropped graphs it writes come back at its t, and the default graph comes back at once. The registry and the indexer's drop records each implemented that over the same table, and the ledger crate and the indexer each carried a tuple for one commit's lifecycle beside core's CommitGraphLifecycle. record_graph_drops and record_graph_writes in core now hold the rule, which keeps a system graph out of every drop table, and every walk carries CommitGraphLifecycle. The indexer's graph lifecycle code moves under its own section, which also puts chunk_has_vector_ops's doc comment back on it.
The commits keep what a drop took, so the facts stay in the ledger's storage; the compatibility entry and the SPARQL page now say so plainly. The recipe that moves an address-named graph into the default graph notes that its DROP takes the old graph's history and needs an identity without a restricting policy, where CLEAR keeps the history and works under policy.
|
(3) Addressed in dc6a300 |
Every declared bench needs a budget entry; this one takes its sibling query_cold_reload's placeholder numbers until a nightly baseline lands.
Policies stored in the default graph went with DROP DEFAULT or DROP ALL, so a governed query as of an earlier t ran with none and showed what they hid. It is now refused with a 404, as a dropped f:policySource already was. The check runs only when an identity or policy class reads stored policies, and returns at once when the ledger has no drops; queries without policy never reach it.
A second process over the same storage, as a query peer or a raft follower is, catches up by applying each new commit. Pin that this applies the commit's drops before its flakes, so the peer's novelty lets go of the dropped graph and a read from before the drop is refused there as on the writer.
Brings #2251 (graph DROP) and #2249 (config graph across ledgers) into next. Resolutions: - Root format: `graph_drops` takes main's extended bit 3 in every root version; next's term dictionary moves to bit 7. The section's graph ids follow the root's width (16-bit v2, 32-bit v5), in `IndexRoot::decode` and the core metadata decoder alike. It comes after the term dictionary. - Commit envelope: `graph_drops` beside next's 32-bit `graph_delta`; the drop-count cap covers next's graph id space. - Pooled graphs: `BinaryIndexStore::without_graphs` takes a dropped graph out of the pool's membership as well as `graph_indexes`, and `has_graph_index` counts pool members, so a drop after the index hides a pooled graph's rows too. An incremental build whose window drops a pooled graph returns `NeedsRebuild`: its rows share the pooled tree, so the purge cannot take them out. New test in it_import_pooled_graphs. - Annotations: main's arena handling of dropped edges (`forget_graphs`, `arena_dropped_graphs`, `edge_graphs_dropped_since_index`, the arena floors in `Fir6Inputs`) is dropped. On next an annotation and its `rdf:reifies` link live in the edge's graph, so the drop takes them, and link synthesis sees only ops the resolver keeps. The two arena-specific graph-drop tests check the same behaviour through links. - Novelty: `drop_graphs` and `forget_graph` work on next's graph slots and per-graph OrdMaps. - Indexer: the lifecycle and purge helpers take 32-bit graph ids; `graph_dict_id_or_insert*` keeps next's u32 overflow check. - Transact/push: `StageOptions` takes main's `graph_ids` (Sid → GraphId); `replaying_commit` stays deleted with the bundle reifier rule. - Api: store masking (`store_without_dropped_graphs`) runs before next's `install_link_base`; `take_snapshot_metadata` carries the drops. Export and hydration keep next's link readers. Graph import refills a dropped graph with 32-bit ids. - Tests: main's new tests take next's async `genesis_ledger`, storage namespaces, `without_storage_lock` for a peer beside a live writer, and the ledger config provider.
Brings in main at 467f0da, with #2271's LaneOutput admission, #2251's graph drop and #2226's language-tag pushdown. - cyclic_bgp.rs: the per-member subject probe plan takes LaneOutput::Encoded, since the cascade emits encoded bindings. - join.rs: the batched gate takes main's deferred overlay plan and eager rule, and keeps this branch's one-graph scope test. The union probes' per-member plans take LaneOutput::Encoded: the union variant emits encoded rows and declines eager materialization. The one-graph object probe takes main's branch_or_none, Arc'd ops and eager subject decoding; the subject probe takes main's subject_lane_object_binding. - join.rs: main's flush now hands a declined plan's rows to the per-row path. The one-graph plan declines every union scope, so that check skips the union variant, which carries its members' own plans. - join.rs: open_per_row_scan takes the scope's TermView, which this branch threads through the per-row path. - registers: main greened the optional-complex cluster, this branch open-eq-05/06; both leave the register. - tests: graph_id_for_iri is assigned_graph_id on main.
What changes
SPARQL
DROPused to retract every fact of the graph, asCLEARdoes:FLUREE_MAX_GRAPH_SCAN_FLAKES;t.DROPnow takes the graph out of the ledger. What it held is no longer queryable at the head or as of any earliert, and a query naming the graph as of atbefore the drop gets a 404. The drop commit retracts nothing, so it costs the same for a graph of any size and has no cap. Writing the IRI again starts the graph afresh. The commits that wrote the dropped facts keep them, so a branch created at atbefore the drop still reads them.CLEARis unchanged.Every way of dropping a graph works like this:
DROP GRAPH,DROP DEFAULT,DROP NAMEDandDROP ALL;fluree graph dropandPOST /v1/fluree/drop-graph;DELETEof a named graph;Ledger.drop_graph;MOVE.How
Commit record.
Commit::graph_dropsnames each dropped graph by IRI (urn:defaultfor the default graph), behind envelope flag0x20. A commit applies its drops before its graph delta and its flakes.Registry.
GraphRegistrykeeps a floortper dropped graph (GraphDrop), and a write of the IRI after the floor revives the graph under the sameg_id. Every write path revives at the writing commit's ownt:A
DELETEalone does not revive a graph.Reads before an index build covers the drop. The store hides the dropped graph (
BinaryIndexStore::without_graphs), so novelty alone serves it. Novelty forgets the graph's flakes and annotations, and replay skips flakes from before a later drop. A query naming the graph as of an earliertis refused (QueryError::GraphDropped, orGraphNotFoundwhen selecting a graph view). The sealed annotation arena predates the drop, so an edge of a dropped graph reads its annotations from novelty alone until the next build.Time travel below the index. A read as of a
tthe index covers takes the drops after the index from the cached head (HeadDrops). It reads the commits after the index for them only when no state at the ledger's head commit is in hand.Replaying a drop record. A drop never takes a system graph, wherever its record is read: replay, the merge of drops across a renumbered root, and both index builds. A record can name another ledger's config graph IRI, or a branch's source's system graph IRI, as an ordinary graph where it was made.
Indexing.
index_tin agraph_dropssection (FIR6 extended flag bit 3), which older decoders refuse.g_id.Search indexes. A BM25 or vector sync whose indexing query reads a dropped graph takes the full rebuild.
ir::GraphReadsfinds the graphs a query reads, in every form the parser lowers to a graph pattern:["graph", …], node-level@graphand its aliases, including inside subqueries,optional,union,minusandexists. A graph variable, a service, the union default graph or reasoning counts as reading every graph. Every BM25 rebuild retires the manifest snapshots from before the drop in the same publish, so a search as of an earliertfinds no snapshot. Until the next sync, searches serve the snapshot they had, as after any write.Configured sources.
GraphRegistry::graph_id_for_iriis nowassigned_graph_id: it answers for a dropped graph, which routes a write.existing_graph_id(iri, t)answers whether the graph exists as oft. Every configured-source resolver uses it:f:policySource,f:shapesSource,f:constraintsSource,f:rulesSource,f:schemaSourceandowl:imports, a datalog rule's target graph, the validate API and the cross-ledger materializers. A source a drop afterttook is refused as oft, so a governed read from before the drop of its policy graph no longer runs without that policy. The same holds for policies stored in the default graph: a governed read as of atbeforeDROP DEFAULTorDROP ALLis refused. That check runs only when an identity or policy class reads stored policies, and returns at once on a ledger with no drops. A source dropped and not written since does not exist, and fails closed as an unknown one does. Reasoning checks again on a schema-bundle cache hit, since the caches key onto_t. An export as oftjudges graphs the same way.Epochs. A drop advances the schema and SHACL epochs even when the graph is only in the index, so shapes and hierarchy built from it are rebuilt.
Breaking changes
DROPno longer keeps the graph's history. See the new entry indocs/reference/compatibility.md.CLEARstill works under policy.DROP GRAPHof a graph that does not exist, or was already dropped, is an error unlessSILENT. It used to be a no-op.f:shapesSourceorf:constraintsSourcegoverns are refused, and reasoning with a droppedf:schemaSourceerrors, until the graph is written again or the config changes. A write to the config graph alone still goes through.Tests
it_graph_drop.rscovers:DELETEnot reviving a graph;CLEARthenDROP;SILENT;DROP DEFAULT,DROP NAMEDandDROP ALL;MOVEandCOPY;--features shacl);tbefore a drop;it_import_into_graph::an_import_refills_a_dropped_graph.The ledger unit test
installing_a_renumbered_root_keeps_drops_on_their_graphs.it_bm25_graph_drop.rscovers:sync_bm25_index_to;@graphand a subquery graph.Also
vector_sync_after_a_drop_rebuilds_from_what_the_ledger_holds, plusGraphReadsandretire_beforeunit tests.it_reasoning_imports::reasoning_as_of_before_a_schema_graph_drop_is_refused.it_config_graph::a_read_before_the_drop_of_its_policy_source_is_refused,a_governed_read_before_a_drop_of_the_default_graph_is_refused, anda_reindex_does_not_drop_the_config_graph_a_drop_named_as_an_ordinary_graph.Registry and indexer unit tests for
existing_graph_idand for drop records naming system graphs.The bench
query_time_travel_below_indexreads as of the index with and without the cached head, against the count of unindexed commits.Each new test fails with its fix reverted.
Not in this PR
mergeable: false. Follow-up: Merge preview errors over a graph drop instead of reporting it unmergeable #2253CLEARof a graph of any size. Today it is still one retraction per fact under the scan cap; the proposal is to record the clear in the commit, reusing this PR's drop machinery. Follow-up: CLEAR at any graph size: record the clear in the commit instead of retracting each fact #2254main:sync_bm25_index_tostores compact@iddocument keys.Partially addresses #1943. A dropped graph no longer appears in
named-graphsfrom ledger info, so the Graph StoreDELETEcase is fixed. A Graph StorePUTwith an empty body, or a sync withallowEmpty, still leaves the emptied graph listed.