Repository navigation
Description
LedgerSnapshot::build_reverse_graph builds the graph Sid → GraphId map that novelty routing uses, deriving each key with encode_iri:
let sid = self.encode_iri(iri).ok_or_else(|| {
Error::invalid_index(format!(
"graph IRI '{iri}' (g_id={g_id}) has no matching namespace prefix …"
))
})?;encode_iri has no OVERFLOW branch. It returns the split form when the canonical prefix is registered, and Sid::new(EMPTY, iri) otherwise:
fn encode_iri_inner(&self, iri: &str) -> Sid {
let (canonical_prefix, canonical_suffix) = canonical_split(iri, self.ns_split_mode);
if let Some(&code) = self.namespace_reverse.get(canonical_prefix) {
return Sid::new(code, canonical_suffix);
}
Sid::new(EMPTY, iri)
}The write path can store a third form. NamespaceRegistry::sid_for_iri (fluree-db-transact/src/namespace.rs:492) allocates a code per prefix and, when the namespace table is exhausted, stores the full IRI under the OVERFLOW sentinel:
let code = self.get_or_allocate(prefix);
if code == OVERFLOW {
Sid::new(OVERFLOW, iri) // full IRI as name
} else {
Sid::new(code, suffix)
}ensure_code documents OVERFLOW as "a sentinel, never register it", so the read side will never find a prefix for it and will produce (EMPTY, iri) against a stored (OVERFLOW, iri) — identical name, different namespace code, so the map lookup misses.
Second defect in the same expression: the error branch is dead
LedgerSnapshot::encode_iri is
pub fn encode_iri(&self, iri: &str) -> Option<Sid> {
Some(self.encode_iri_inner(iri))
}It returns Some unconditionally. The ok_or_else above therefore cannot fire, and the "graph IRI has no matching namespace prefix — namespace_codes may be incomplete" error it exists to raise is unreachable. An unregistered graph IRI does not produce that error; it silently becomes (EMPTY, iri).
encode_iri_strict is the variant that returns None for an unregistered prefix, and is presumably what this call meant to use.
Status: unmeasured
The mechanism is read from source; the symptom has not been reproduced. Reaching it requires exhausting the namespace table, which I could not do from the CLI in reasonable time — five deliberately varied graph IRIs (http, urn:uuid:, deep path, fragment, tag:) all received real namespace codes and agreed between the two derivations.
So this is filed as a defect in the construct, with an explicit note that its reachability is unestablished. Anyone picking it up should decide whether OVERFLOW is reachable in practice before weighting it.
Relationship to the export-side fix
The same mismatch existed on two export paths and was fixed there by resolving through the subject dictionary first and falling back to a fresh encode, matching ExportResolver::resolve_subject_sid:
find_subject_sid(iri).ok().flatten().unwrap_or_else(|| encode_iri(iri))That worked because a BinaryIndexStore is reachable at both export sites. Whether the same shape is right for build_reverse_graph is a core question — it may want encode_iri_strict plus a live error branch, or a store round-trip, or for sid_for_iri's OVERFLOW form to be representable on the read side — and that decision belongs with whoever owns LedgerSnapshot's API rather than inside an export change.
Activity