Repository navigation
fix(transact): a delete of an overflow-IRI object retracts the stored fact - #2142
Conversation
… fact Once the namespace table is full, a new IRI is stored whole under the OVERFLOW code. Two decodes of a stored subject id instead resolved its IRI and re-encoded it through the namespace table, which gives an uncoded prefix the EMPTY code: - the store's object-reference decode, through which staging reads the current facts every retraction is built from; - staging's materialization of WHERE solutions. DELETE DATA's retraction then named no stored fact and was dropped; DELETE WHERE's carried the object under EMPTY. Indexing that left the fact in place and gave the IRI a second, empty subject, which reads by IRI found first: the IRI's own facts and every reference to it disappeared from bound-IRI queries. Both now decode a subject id as subject positions already do, to the Sid it is stored under.
The explanation's budget also bounds the materialization it starts with. At 2 seconds a loaded CI runner capped that materialization before it derived the fact, so the test failed on its precondition, not on the replay. The replay costs about thirty times the materialization, and an 8-second budget sits between the two.
aaj3f
left a comment
There was a problem hiding this comment.
@bplatz nice find, and decoding an object ref the way a subject is decoded, instead of resolving its IRI and re-encoding it, is the right identity. Three headline notes:
(1) The one must below lives in the helper this now routes through. subject_sid_of_parts still looks a full-IRI subject up by its IRI, EMPTY first (binary_index_store.rs:2374-2378), so every overflow object decode now pays a reverse-dictionary lookup, and on a ledger that already holds #2138's empty twin it hands the twin back, so deletes there still don't take. Returning the stored parts for OVERFLOW fixes both (numbers below).
(2) "An IRI's Sid" is still derived per site. Besides the two this PR fixes, DictOverlay::decode_value (dict_overlay.rs:601), decode_overlay_object and term_matches_probe_value in join.rs, export.rs:375, geo_search.rs:285, shortest_path.rs:132, fluree-db-shacl/src/sparql.rs:504 and the indexer's class lookups (incremental.rs:2418, :3773) all resolve an id to its IRI and re-encode it, and query constants still take encode_iri's EMPTY fallback (#1842, #1891). I ran 15 bound-object query shapes on indexed overflow data, with and without novelty, and they all come out right at this head, so not this PR. The structural direction I'd suggest is that all of those go through resolve_subject_sid/subject_sid_of_parts and nothing re-encodes.
(3) For ledgers that already took one of these deletes, the must below makes new deletes work again, but a bound-IRI read of a twinned IRI still finds the empty twin, and changing the fallback lookup order didn't bring those reads back in my run. I think that's the query constant itself (Sid(EMPTY, iri)) naming the twin exactly, which makes it #1842's decision rather than this PR's. It might be worth saying so on #1842, since until it's settled a bound-IRI read of an IRI that already has a twin stays empty on that ledger.
Claude-assisted review below:
✅ Approving to unblock you — with 1 thing that needs to be addressed before this merges.
Must address:
subject_sid_of_partsresolves an OVERFLOW subject by IRI, EMPTY first (fluree-db-binary-index/src/read/binary_index_store.rs:2374-2378; inline at:1585). With the object decode routed through it, a PSOT range read over 40,000 rows whose objects are overflow IRIs (range_with_overlay, debug build, min of 7) takes 298 ms onmainand 447 ms at this head. And on a ledger whose dictionary already holds #2138's empty twin (written bymain'sDELETE WHERE), this head'sDELETE WHEREstages the retraction with the twin'sSid(EMPTY, iri)again, so the facts stay. ReturningSid::new(OVERFLOW, suffix)for an OVERFLOW subject fixes both: 99 ms on the same read, the PR's test still passes, and the deletes on that corrupted ledger take.
Otherwise this looks right to me. A few smaller things:
- 🟡 the decode change also fixes upsert, which the test doesn't cover (inline at
it_overflow_iri_delete_index.rs:93). - On the "Not in this PR" list: #1842 is genuinely separable, since it needs the
encode_iridecision the issue lays out and touches every caller of that fallback. For ledgers that already committed such a delete, the write side is the must above and the read side is note (3), which I think belongs with #1842. - The replay-deadline budget bump in
it_datalog_explain.rsreads fine to me as its own commit; CI ran it at 8.1 s.
Adherence to repo commitments:
- Patterns/abstractions: ✔ moves both decodes onto the existing subject-decode helper instead of adding a third rule;
⚠️ about eight other resolve-then-re-encode sites remain (headline note 2). - Performance (speed first, memory second): 🔴 the object decode now inherits
subject_sid_of_parts' reverse-dictionary lookup for every overflow object: +50% on the range read above, on exactly the ledgers this PR is for (#2135: a BSBM import leaves 95.6% of subjects in overflow). The one-line change in the must makes that read faster thanmain. - Deployment targets: ✔ n/a — host-neutral decode and staging code; it behaves the same in the server, the embedded library and wasm32, and touches no runtime fence.
- Testing: ✔
it_overflow_iri_delete_index(wired throughgrp_transact) coversDELETE WHERE,DELETE DATAand a JSON-LD where/delete across pending, incremental and full-rebuild reads, ran in CI by name, and goes red with the two decodes put back tomain.⚠️ No upsert row, and nothing exercises a ledger that already holds the twin. - Conventions: ✔ multi-line commit bodies; the CI-budget fix is its own commit with its reasoning.
Verified locally at branch HEAD (000d37c69): deletes_of_overflow_iri_objects_read_the_same_once_indexed passes; with binary_index_store.rs and stage.rs put back to main it fails exactly as the PR body describes (each deleted offer keeps 2 facts, and ?s vendor <V> and <V> ?p ?x read 0 after both builds). Scratch tests next to it: the 15 bound-object shapes (both join orders, a three-pattern star, VALUES, FILTER EXISTS, MINUS, OPTIONAL, FILTER =/sameTerm/IN, COUNT), identical with and without novelty; an upsert replacing an overflow-IRI vendor (wrong on main, right here); the range read above at main, this head and with the one-line change; and a ledger corrupted by main's code, then deleted from under this head and under the change. git merge-tree against #2144, #2154 and #2153 is clean.
Approving now so you can merge without waiting on another pass from me — just be sure the subject_sid_of_parts change is in before you do.
| // code, a Sid no stored fact has. | ||
| let sid = self | ||
| .resolve_subject_parts(o_key) | ||
| .and_then(|(ns_code, suffix)| self.subject_sid_of_parts(ns_code, suffix)) |
There was a problem hiding this comment.
🔴 Must address before merge: subject_sid_of_parts looks an OVERFLOW subject up by IRI, which makes this decode slower on overflow-heavy ledgers and gives back #2138's twin on ledgers that already have one.
fluree-db-binary-index/src/read/binary_index_store.rs:2374-2378: for a full-IRI namespace (EMPTY or OVERFLOW) it returns find_subject_sid(&suffix), which goes through find_full_iri_subject_fallback and tries EMPTY before OVERFLOW. 09aea1b kept that lookup on purpose for subject positions; routing the object decode through it adds a reverse-dictionary lookup to every overflow object this decode sees (BinaryGraphView::decode_value, so the range provider, staging's current-fact reads, history and the decode_value_v3 query paths), where before it was a namespace-map miss in encode_iri.
Two things I measured. A PSOT range read (range_with_overlay, p = vendor) over 40,000 rows whose objects are overflow IRIs, debug build, min of 7 runs: 298 ms on main, 447 ms at this head. And I wrote a ledger with main's code (the PR's fixture plus DELETE WHERE { <O1> ?p ?o }, then an incremental build), so its dictionary holds the empty twin of the vendor IRI the way #2138 describes. Then from this head, DELETE WHERE { <O3> ?p ?o } stages its vendor retraction with o = Ref(Sid { namespace_code: 0, name: "http://vendors.example/v/1" }), while page comes out under 65534. After an incremental build, O2, deleted the same way, keeps 1 of its 3 facts, and O1 still has both of its survivors.
The narrow fix I tried is to return the stored parts for OVERFLOW, since an OVERFLOW subject is stored under its full IRI and nothing can register its prefix once the table is full:
if ns_code == namespaces::OVERFLOW {
return Ok(Sid::new(ns_code, suffix));
}With that, the same range read takes 99 ms, deletes_of_overflow_iri_objects_read_the_same_once_indexed still passes, the 15 bound-object shapes come out the same, and on the corrupted ledger DELETE WHERE of O1, O2 and O3 leaves all three empty after an incremental build. It also drops the lookup for overflow subjects in subject position, which is most of a BSBM import (#2135). If an OVERFLOW subject can also be stored under a coded prefix in some state I'm not thinking of, that's the case to check, and a test for it would be worth adding either way.
Commenting here because subject_sid_of_parts is not in this diff.
| ), | ||
| ) | ||
| .await; | ||
| let ledger = fluree |
There was a problem hiding this comment.
🟡 Optional: an upsert row would pin a path this PR fixes but doesn't test.
Upsert's replacement wave reads the current values through the same store decode, so it had the same bug. I ran it as a scratch test with this fixture: upsert O1's vendor from V to another overflow IRI, then an incremental build. On main, O1 ends up with both vendors and V reads empty by IRI; at this head it has one vendor and V reads right. Sync's whole-graph scan goes through the same decode too, though I didn't run that one.
Something like a fourth offer replaced by fluree.upsert(ledger, &json!({"@id": O4, VENDOR: {"@id": V2}})) (with V2 another overflow IRI), and its reads added to checks, would cover it. 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.
… under Decoding a persisted OVERFLOW subject looked its IRI up in the reverse dictionary, EMPTY first. Object references now decode through the same helper, so every overflow object paid that lookup. On a ledger that already holds an EMPTY subject with the same IRI (left by #2138's deletes), the lookup returned that subject, and a delete staged from it still named no stored fact. An OVERFLOW subject is stored under its full IRI, so its stored parts are its Sid. They are returned directly, without the lookup. The overflow-delete test now also replaces one offer's vendor by upsert. Upsert retracts the current value it reads through the same decode, and before this branch it kept both vendors.
Brings #2142, #2144, #2154, #2155, #2156, #2158, #2159, #2165, #2166 and #2167 into next. Where main's RDF lists (#2159) meet next's RDF 1.2 links: - The list view walks an EdgeAnnotation's body; next has no AnnotationTarget. - Export marks annotated edges skipping list rows, and writes an rdf:reifies row as next's @reifies block through main's JsonLdNode, untranslated rows included. - The JSON-LD and import readers keep next's graph argument and triple-term spool records beside main's gap-free list positions and list chunking. - One collection writer: main's shared module, which both JSON-LD and Turtle use, replaces next's Turtle-only one, and now also keeps the labels of blank nodes inside triple terms, of reifiers, and of blank graph names. A reified cell keeps its triples while the well-formed tail after it folds, as JSON-LD's list conversion does; next's writer test now says so. - Hiding list members also turns off next's wildcard lane, which reads leaflets directly, and next's independent-scan count builds its right scan with the same hiding. Elsewhere: - List-predicate discovery opens a leaf ranged unless the store cannot read ranges, which next fetches whole. - GC reports main's walk stop reason without next's removed artifact cache directory. - Tests from main await next's async genesis_ledger, reload with without_storage_lock, and build stores without a cache directory.
Fixes #2138
Follow-up: #1842
Problem
Once a ledger's namespace table is full, a new IRI is stored whole under the OVERFLOW code. Deleting a fact whose object is such an IRI wrote a retraction that didn't match the stored fact:
DELETE DATA: the retraction was dropped, because it named no stored fact.DELETE WHERE: the retraction carried the object asSid(EMPTY, iri).Indexing the
DELETE WHEREcommit left the fact in place. It also gave the IRI a second, empty subject under EMPTY, and lookups by IRI check EMPTY first. After that, the IRI's own facts and every reference to it disappeared from bound-IRI queries. On BSBM this affected 37 of 38 deleted offers in one update window. Q10 lost correct rows.Cause
Staging builds every retraction from the stored fact. Two decodes of a stored subject id produced the wrong identity. Each one resolved the id to its IRI, then re-encoded that IRI through the namespace table, which gives an uncoded prefix the EMPTY code:
decode_value_v3,IriRef). Staging reads current facts through it.materialize_one_binding,EncodedSid).Fix
Both now decode a subject id the way subject positions already do:
resolve_subject_partsplussubject_sid_of_parts, giving theSidthe subject is stored under. In staging that goes through the graph view'sresolve_subject_sid, which also covers ids from pending commits.subject_sid_of_partsnow returns an OVERFLOW subject's stored parts directly. It used to look the IRI up in the reverse dictionary, EMPTY first. That cost every overflow object a lookup once objects decoded through it. On a ledger that already holds #2138's empty subject, the lookup also returned that subject, so deletes there still missed.Ordinary query lanes don't go through these decodes. I ran 15 query shapes over indexed overflow data, covering bound objects,
FILTER =,sameTerm,VALUES,IN, joins through the object,GROUP BYandDISTINCT. They returned the same rows with and without this change.Not in this PR
Sid(EMPTY, iri)and names the empty subject, so its bound-IRI reads stay empty until Bound-IRI lookups miss overflow-namespace subjects in novelty #1842 is settled. A rebuild replays the old commits, so it brings the empty subject back.DictOverlay::decode_value,decode_overlay_objectandterm_matches_probe_valueinjoin.rs, the export resolver's object decode,geo_search.rs,shortest_path.rs,fluree-db-shacl/src/sparql.rs, and the indexer's two class lookups inbuild/incremental.rs. Bound-object queries over indexed overflow data come out right. Export, geo, shortest path, SHACL and the class lookups weren't exercised.Testing
it_overflow_iri_delete_index(ingrp_transact) fills the namespace table, then changes four offers whose vendor and page are overflow IRIs:DELETE WHERE;DELETE DATA;It checks the reads pending, after an incremental index, and after a full rebuild. With the store decode reverted, all three deletes fail, the upserted offer keeps both vendors, and the empty subject appears. With the staging change reverted, the
DELETE WHEREoffer survives.overflow_subject_decodes_to_its_own_sid_beside_a_twinbuilds a store that holds an OVERFLOW subject and a second subject with the same IRI, once under EMPTY and once under a coded prefix. Either way, a lookup by IRI finds the second subject first. The test checks that subject and object decodes of the OVERFLOW id both give the OVERFLOWSid. Both cases fail without the OVERFLOW early return.