Repository navigation
feat(lists): each list on a property keeps its own id; lists read and edited as RDF on request - #2229
Conversation
… 64 bits A list member's place was a 32-bit position: one list per subject and property could be stored compactly, and a second was stored as an rdf:first/rdf:rest chain. The place is now 64 bits, which list of its owner in the high 32 and the position in the low 32 (fluree_db_core::list_index), so lists can carry an identity. Every list is still list 0; storing a second list compactly is the next step. - FlakeMeta gains `list` (0 for the first list and for every value with no position). Its order is position-free values first, then list, then position; serde and Debug leave out list 0, so existing JSON, transport and debug output read as before. - Commits carry the place as the varint they already used, so a commit written before reads as list 0; decoders refuse a position past i32::MAX. - The index stores a 64-bit o_i: RunRecordV2 (still 40 bytes in memory) and its run, spool and key layouts, leaf keys (leaf version 2), branch keys (version 3), history sidecar entries (versions 3 and 4, padded so every entry width differs), the leaflet OI column (8-byte elements), pool delta runs (version 2) and the root's inline leaf keys (root version 4). The import-side RunRecord grows from 40 to 48 bytes. - A v4 index, and an earlier v5 one, is served as it is: each decoder takes the width from its artifact's version (or a column's element width) and widens a 32-bit o_i into list 0, u32::MAX into none. - A ledger whose published root is of an earlier format is rebuilt in full by its next build, never incrementally, and pool compaction skips such a root, so no root mixes artifacts of two formats (index_root::is_current_format). - Query bindings (EncodedLit.i_val), the import spool and the commit JSON carry the whole place. Tests: a_v4_leaf_decodes_like_this_builds_leaf, a_main_branch_decodes (now on main's narrow layout), a_narrow_key_widens_to_the_wide_key, a_main_layout_root_reads_its_narrow_keys_and_is_an_earlier_format, a_place_packs_list_high_and_position_low.
… of its own A second list on one subject and property was stored as an rdf:first/rdf:rest chain, since a position named no list. Each list now takes the next list id of its owner and is stored compactly; a chain is left for an owner holding every id. Bulk import chunks share one id counter per owner, and ADD gives each source list a fresh id in the destination. Every reader that told a property's list members apart by position alone now uses the full place: the shared list reader, the RDF list view, CONSTRUCT list entries, JSON-LD crawls, export, delete matching, novelty netting, full-text de-staling, Cypher property maps and SHACL paths. In the RDF view a cell's triples are now read from its own list only, so a collection pattern never joins members of two lists. FlakeMeta equality and hashing now go by its language tag and list place, as its ordering does, so a list id beside no position is not identity; the JSON metadata decoder rejects a list id or position out of range instead of wrapping it.
A second list on one property is now compact under its own list id, so a shape whose sh:path, sh:alternativePath or path operator holds two lists read as one merged path. A sequence is now the members of one list only; two lists are two values, a malformed path, as before.
…ad what this release writes
…raint of its own A shape's sh:or lists were read as one list, so sh:or (A B), (C D) asked for one of the four instead of one of A or B and one of C or D, and sh:xone (A B), (C D) rejected a node conforming to A and C. Each compact list, and each stored rdf:first / rdf:rest spine, is now its own constraint. Shapes written as values with no list still read as one list together.
…hapes graph is read A value with no list was put with the plain shapes as soon as its graph held no spine for it, so two heads whose cells another shapes graph held expanded into one list, one constraint, and with the graphs the other way round never expanded at all. Such values now resolve against every graph after all are read; only those heading no spine are plain shapes. A compact list's members are pushed as read, without a spine check.
Render compact lists, stored chains and empty lists as separate @list objects. Preserve explicit list-container compaction for a sole list and keep list identities across dataset unions. Add projection round-trip coverage and document the v5 output change.
A value scan asked for every row's list place and the cursor added it for any filter, so reading the values of a property holding lists decoded a place per row that nothing read. A scan now asks for it only to hide list members or for history, and the cursor adds it only for a filter on the place, a replay, which matches rows to history on the full fact identity, and a leaflet novelty merges into, which decodes every column.
… holds A compact list's cells are no triples a pattern can match, so the standard walk to a list's members found nothing for one. The walk is now recognized where SPARQL and JSON-LD lower a path, and its three patterns alone read lists as RDF cells, in a query and in an update's WHERE: a member once per entry, a plain value of p not at all, a stored chain through its triples. Every other pattern keeps reading members as values. The JSON-LD path docs said a sequence step cannot carry a modifier; it can.
…gh its cell A request can read every list as the RDF list it denotes: the property's value is the list's head cell, a blank node the request names, and each cell has an rdf:first (its member) and an rdf:rest (the next cell or rdf:nil). SPARQL asks with `# PRAGMA rdf-lists: true` and JSON-LD with `opts.rdfLists`, in a query and in an update. A request that does not ask reads a list's members as values, as before. A request that cannot read lists so is refused with a 400 rather than answered with members: a history range, a dataset spanning ledgers, and a JSON-LD graph crawl, which reads a subject's stored triples. A policy query (which then fails closed), a rule and an sh:select refuse the pragma, since each reads lists as members. In an update, a template triple naming a compact list's cell is resolved against the list the WHERE read (fluree_db_transact cell_edits). A cell's rdf:first deletes and inserts, taken together across every solution, that leave it one value other than its member retract the member and assert the replacement at the same list and position; nothing else is rewritten, and the list keeps its id even when it comes to equal another. A cell left with its member changes nothing. Every other write naming a cell is refused and the update changes nothing: a cell left with no rdf:first or with two, an rdf:rest or owner edge written, another property on a cell, a cell as a value or graph (a member of a list the update states included), and a cell written outside its list's graph. Modify policy judges a replacement on the property holding the list. A list stored as an explicit chain is triples, written as before. The compatibility reference no longer says rdf:rest*/rdf:first finds nothing.
An update reading lists as RDF (`# PRAGMA rdf-lists: true`, JSON-LD `opts.rdfLists`) now writes as that view reads: - A list the update writes beside a cell replacement takes the next list id past the edited list, or restates it when it holds the same members. It took the edited list's id, and both lists shared position 0. - A delete naming a value of a property takes its plain value alone; a list's members are its cells' rdf:first values. It deleted every list entry holding the value as well. - A cell is refused as a predicate, including inside a triple term. It was stored as a predicate named by the request. - A list in a DELETE template is refused: in this view it is a chain of new blank nodes. - An upsert is refused: it replaces a property's values, so the lists it holds, and deleted their entries as members. A query reading lists as RDF over a dataset of one ledger at several times is refused with a 400, as one spanning ledgers is. It read the lists of the primary graph's time alone, and lost those of the others.
A subject projection writes each list on a property as an `@list` object (4944941). The list helpers in it_filtered_delete_list_meta and it_import still read the property's value as a flat array of members, so they saw no members and every list assertion compared against `[]`. They now read each list's members in order.
The first build over an index of an earlier format is a full rebuild, so the v4.2.3 fixture's index never reached the incremental path, and an_incremental_build_halts_without_falling_back saw the full rebuild run. The incremental case now rebuilds the fixture's index at t=1 in this build's format and publishes it before the build to t=2, which goes incremental, halts on the data, and does not fall back. a_build_over_an_earlier_format_rebuilds_and_halts covers the fixture as written: with incremental builds on, the build is a full rebuild and halts the same way. The Fluree is built without its own indexer: that worker's startup sweep built the ledger over the v4.2.3 index while the base was being rebuilt.
SPARQL reads a list's members as values again (#2217), so `VALUES ?s { ex:a ex:a } ?s ?p ?o` returns the name and the three members for each driving row, through the batched wildcard lane, as the JSON-LD twin does. The test expected the RDF list view's name and head cell, with the lane not firing. It now expects the members and the lane, and checks the SPARQL rows against the JSON-LD rows.
`rdf::parse` refused JSON-LD whose named graph is named by a blank node
(`{"@id": "_:g", "@graph": [...]}`), which `rdf::serialize` writes for a
quad in a blank-node graph, so a dataset holding one did not round-trip
through JSON-LD. The refusal sat in `node_graph`, which every JSON-LD
reader shares.
`node_graph` now returns a blank-node name as written (a variable is
still refused), and `to_graph_events` writes the graph under that blank
node, the one its `@id` labels. Writers whose graphs are named by IRIs
refuse it through `iri_named_graph`, with the message they gave before: a
transaction, a bulk import, and the ontology reader.
aaj3f
left a comment
There was a problem hiding this comment.
@bplatz this is a big one and a careful one, and at a design level I'm on board: the 64-bit place with list 0 as the old encoding reads every existing commit and artifact unchanged, and the opt-in RDF view is the "read-only opt-in view now" option from my #2217 note, with a write path narrow enough (replace in place, refuse everything else) that I'm not worried about #2159's cell-edit bugs coming back. Three headline notes:
(first, I'm approving despite the overall recommendation for changes below--just FYI)
(1) On the upgrade cost: I'm on board with a full rebuild on each ledger's first index after upgrading, rather than mixing formats in one root. It keeps the incremental and compaction paths to one format, and fluree reindex is already there for anyone who wants to pay it on their own schedule.
(2) The class most of this PR's commits fix by hand, a list member identified by its position alone with its list assumed, still has a live instance here (a JSON-LD delete of a @list, below) and two more on the way in from my own main PRs that will compile cleanly on next:
fixed here: the eleven readers
16eecec84lists, pluse54040a59andf26abdec6/748e2edebfor SHACL; still live:current_facts.rs:1510(a delete template's list is list 0); in flight: #2214'srecord_flake_fact(m.i as u32into the union lane's fact identity) and #2202'slisting_owners(one owner edge per subject and predicate)
I think the class fix is making the position unreachable without its list: one private packed place in FlakeMeta behind place(), so m.i stops compiling and every main → next merge that reads a position alone becomes a build error (it also takes Flake back from 184 to 176 bytes). Since this PR already reshapes FlakeMeta I'd lean toward folding it in here, but I wouldn't hold the merge on it. Either way, I'll take the #2214 and #2202 side of the main → next merge, so neither of us is waiting on the other.
(3) And I'm on board with the crawl returning each list as its own @list object: it's what JSON-LD compaction does without a list container, it matches what CONSTRUCT already writes since #2217, and @container: @list gives a client the bare array back. I did weigh the two gentler alternatives, keeping a sole list as a bare array as in 4.2, or a per-query option that restores 4.2's flattening for this major, but the first makes a property's JSON shape depend on its data, and the second is surface we'd carry for a whole major, so I think your call is the right one.
The two silent results below (the list walk over a dataset or a history range, and the delete-template list) are the ones I'd want in before this merges; the allocation fixes are one-liners.
Full review below:
🔄 Request changes.
The commit bodies on this one are again really easy to review from, @bplatz, and the format work is careful: every decoder takes its width from its own artifact's version, an old commit reads as list 0, 4.2 refuses rather than misreads what this release writes, and 2c7018e33 is a real win for plain scans over list-bearing leaflets. The cell-edit path held up under everything I threw at it, and the refusal matrix around the pragma is thorough. The request for changes is about two places where a request gets a wrong answer without being told, plus two per-row allocations:
- The
p/rdf:rest*/rdf:firstwalk returns nothing over a dataset of several ledgers, over one ledger at several times (depending on whichFROMcomes first), and in a history range (dataset_query.rs:1098, inline). The pragma is refused in exactly these cases; the walk needs the same refusal, or a view built over every graph. - A JSON-LD delete of a
@listmatches list 0 by position (current_facts.rs:1510, inline): with(1 9), (1 2)on one property, deleting{"@list": [1, 2]}leaves(9), (1 2). Pre-existing in mechanism, but this PR is where it reaches every second list. - Per-row allocations on shared read paths (inline): the language tag is allocated twice per tagged row in the range and history decoders (
binary_range.rs:991,:1595,binary_history.rs:626,block_fetch.rs:327), and the crawl allocates anArc<str>per IRI value on every ledger (hydration.rs:2516). One line each.
Smaller ones inline: the class fix for position-alone reads (which also recovers the 8 bytes per Flake), the root fetched twice per index build, and base-vs-head numbers for the format widening. One more without an anchor: release notes come from the PR title, and the title doesn't name the crawl's new @list output, which is the change most JSON-LD clients will notice.
Adherence to repo commitments:
- Patterns/abstractions: ✔ widens the existing
FlakeMeta/o_irather than adding a column, reusesListView,DeleteResolverandlists::encode, and the walk is lowered in both front ends to one IR mark;⚠️ the position stays readable without its list (pub ibesidepub list), the shape behind the delete-template bug and the in-flight #2214/#2202 instances. - Performance (speed first, memory second): ✖ CRITICAL: an extra allocation per language-tagged row in
binary_range_eq_v3,binary_range_bounded_v3,decode_event_to_flakeandblock_fetch, and anArc<str>per IRI value in every JSON-LD crawl (inline, unmeasured, one line each). On the other side, plain scans stop decodingo_i, andBindingstays at 88 bytes. Memory:Flake176 → 184 bytes, and every import and index artifact is a few bytes wider per row; no bench numbers yet. - Deployment targets:
⚠️ sharedfluree-db-api/-query/-indexercode; evidence is in-process tests and CI's server-shapedtestjob. The forced full rebuild on each ledger's first index after upgrading is the host-sensitive part: an embedder that runs the indexer in a runtime with a bounded invocation time or bounded temp disk may not finish a large ledger's rebuild there, wherenextpreviously upgraded the root incrementally (see the headline note). wasm32 compiles andwasm-smokeis green. - Testing:
⚠️ it_list_cell_edits,it_projection_listsand the extended list suites are wired intogrp_transact/grp_query_sparqland pass, with JSON-LD twins for the pragma read, the walk and cell edits; nothing covers the walk over a dataset or history, or a@listdelete beside a second list;testsuite-sparqlis green with no register change. - Conventions: ✔ multi-line, accurate commit bodies (only
5b7c9cd9dis subject-only), CI clippy and fmt green,compatibility.md,sparql.md,jsonld-query.mdand the upgrade guide updated;⚠️ the title doesn't mention the crawl output change.
Verified locally at branch HEAD: grp_transact list modules (33 passed) and grp_query_sparql it_sparql_list* (49 passed); scratch probes, reverted afterwards, for the walk over two ledgers, two times in both orders and a history range (SPARQL and JSON-LD), for the @list delete beside a second list (in novelty and after an index build), and for size_of::<Flake>() (184). CI at 476c0f2c0: test, clippy, fmt, wasm32, wasm-smoke, testsuite-sparql and python are green.
Please do get the walk and the delete-template fixes in before this merges, and the two allocation one-liners with them. The rest are small, and if you agree with them I'd rather see them folded in now than lost in the backlog.
| executable: &ExecutableQuery, | ||
| ) -> std::result::Result<(), String> { | ||
| let same = |v: &GraphDb| v.ledger_id == primary.ledger_id && v.t == primary.t; | ||
| if executable.query.rdf_list_view |
There was a problem hiding this comment.
Blocking: the p/rdf:rest*/rdf:first walk returns nothing outside one ledger at one time, and says nothing about it. The pragma is refused in exactly these cases (this function, and the history check at runner.rs:535), but the walk, which every request gets without asking, isn't.
Claude caught this while probing the refusals, and reproduced it. ListViewOperator::next_list_batch returns no list triples when ctx.is_multi_ledger() (list_view.rs:756), the view's predicate set comes from the primary snapshot alone (runner.rs:542-547 → ListView::for_db), and the runner builds no view for history (&& !planning.is_history() at runner.rs:543). So the walk's owner edge meets the members as values, and its rdf:first step finds no cell.
With ex:s ex:items (1 2) in ledger a and ex:t ex:items (3) in ledger b:
SELECT ?x FROM <a> WHERE { ?s ex:items/rdf:rest*/rdf:first ?x }→1, 2- the same with
FROM <a> FROM <b>→ no rows (?s ex:items ?xover that dataset returns all three) - one ledger whose list is written at t:2:
FROM <l@t:1> FROM <l@t:2>→ no rows, butFROM <l@t:2> FROM <l@t:1>→1, 2 FROM <a@t:1> TO <a@t:latest>→ no rows (the values read returns both)- JSON-LD,
{"@path": "ex:items/rdf:rest*/rdf:first"}with"from": [a, b]→[](with[a]alone,[[1],[2]])
The order-dependent one is the one that worries me most, since nothing in the result says a graph was skipped.
The minimal fix is to refuse these the way the pragma is refused, so the walk can't answer partially:
if (executable.query.rdf_list_view || fluree_db_query::list_view::query_has_list_walk(&executable.query))
&& !dataset.default.iter().chain(dataset.named.values()).all(same)plus the same query_has_list_walk check beside the history refusal in runner.rs:535. For the one-ledger-several-times case, building the view's predicate set over every graph of the dataset would let the walk answer instead of refusing, if you'd rather. Either way, a test over each of the three shapes would pin it (the existing rdf_lists_is_refused_where_it_cannot_be_honored is the natural home).
There was a problem hiding this comment.
Fixed in acf3731. The walk now reads where it can and is refused where it can't answer whole.
- Its view is built over every graph the dataset names, with each ledger's list predicates, list reads and cell names kept in that ledger. One ledger at two times reads in either order, so
FROM <l@t:1> FROM <l@t:2>and the reverse agree, andGRAPH ?gover two ledgers reads each one's own lists. - A default graph spanning ledgers (
FROM <a> FROM <b>, JSON-LD"from": [a, b]) gets the400any property path gets there. - A walk over compact lists in a history range is a
400. Lists stored as triples walk in history as before.
Pinned by a_list_walk_reads_each_graph_of_a_dataset (SPARQL and JSON-LD, novelty and indexed).
| None => out.push(Retraction(intent.flake)), | ||
| } | ||
| } else if facts.has_entries && list_index_of(&intent.flake).is_none() { | ||
| } else if facts.has_entries && place_of(&intent.flake).is_none() { |
There was a problem hiding this comment.
Blocking: a list in a JSON-LD delete template deletes from the wrong list. Its members are built at list 0, and this branch treats a member that carries a place as already naming a stored entry, so the delete matches list 0 by position instead of the list it names.
Claude caught this one, and reproduced it. With ex:s ex:items (1 9) , (1 2):
{"@context": {"ex": "http://example.org/"},
"delete": {"@id": "ex:s", "ex:items": {"@list": [1, 2]}}}leaves "ex:items": [{"@list": [9]}, {"@list": [1, 2]}], in novelty and after an index build. The intent (1 @ list 0, position 0) skips this branch (place_of(&intent.flake).is_none() is false), and facts.named below matches the 1 at the head of the other list by full identity; (2 @ 0, 1) matches nothing. By Claude's reading of the code (not run), a delete with a where takes the witnessed branch above, which retracts the intent as-is at its list-0 place, so it lands the same way. So the delete removes a member of a list it didn't name and leaves the list it did name whole. That fits neither the RDF reading (delete that list) nor the documented "deleting a value deletes every entry of a list that holds it … however the delete is written" (sparql.md:1387).
I don't think this PR introduced the positional match (by the diff, base took the same branch through list_index_of against its one compact list), but this is where it reaches every second list, which is now compact under an id the template can't name, and the PR's own description lists delete matching among the readers that now use the full place. SPARQL's DELETE DATA refuses the collection's blank nodes, so as far as I can tell it's JSON-LD only.
Two ways to fix it that I can see: match a template's list against the owner's stored lists by members, the way lists::encode restates with same_members, and retract that list's entries at their places (nothing when no stored list matches); or, more simply, refuse a list in a delete template outside the pragma too, as refuse_deleted_lists already does inside it, pointing at upsert. A test with two lists on one property, deleting the second, would pin either.
There was a problem hiding this comment.
Fixed in ac3993e, along the lines of your first option. A @list in a JSON-LD delete now names a list as a delete names a value. It retracts, whole, each list the owner holds with the same members in the same order and no more, and nothing else. Each member is matched as the same value deleted on its own would be.
- With
ex:s ex:items (1 9) , (1 2), your delete retracts(1 2)and leaves(1 9), in novelty and after an index build. - With a
where, each solution's list is matched on its own. List templates are never witnessed, so the witnessed branch doesn't see them. - The SPARQL twin is a
( … )inDELETE WHERE. Its owner edge and cells are read through SPARQL's list view, so it gates the solution like any pattern, matches a list stored as triples as those triples, and deletes a compact list it matched whole.
Pinned by a_deleted_list_is_the_lists_that_are_it and the other new it_list_identity tests, plus the unit test list_literals_name_whole_stored_lists. Each was checked failing with its piece reverted. Documented as a behavior change in compatibility.md.
| } else { | ||
| None | ||
| }; | ||
| let meta = fluree_db_core::FlakeMeta::from_packed(lang.as_deref(), o_i); |
There was a problem hiding this comment.
Blocking (performance): every language-tagged row now allocates its tag twice here. resolve_lang_tag returns Option<&str>; the .map(ToString::to_string) just above makes a String, and from_packed → from_place then normalize_lang_tag(l).into_owned()s a second one and drops the first. Before, the String moved straight into FlakeMeta.
This is binary_range_eq_v3, the range path behind policy, SHACL, reasoning, property paths and the crawl's subject loads, so it's one extra allocation and copy per tagged row there. The same shape is at binary_range.rs:1592-1595 (binary_range_bounded_v3), binary_history.rs:623-626 and block_fetch.rs:325-327. I haven't measured it, and per row it's small, but it's the per-row allocation class we treat as blocking and the fix is one line at each site:
// Language tag and list place.
let meta = fluree_db_core::FlakeMeta::from_packed(store.resolve_lang_tag(o_type), o_i);(dict_overlay.rs:666 and BinaryIndexStore::decode_meta go the other way, from three and two allocations down to two and one, so those are fine.)
There was a problem hiding this comment.
Done in 1ca9af2, at all four sites: binary_range_eq_v3, binary_range_bounded_v3, binary_history.rs and block_fetch.rs each pass the borrowed tag to FlakeMeta::from_packed.
| } else { | ||
| None | ||
| }; | ||
| let meta = fluree_db_core::FlakeMeta::from_packed(lang.as_deref(), o_i); |
There was a problem hiding this comment.
Same double allocation as fluree-db-query/src/binary_range.rs:991: FlakeMeta::from_packed(store.resolve_lang_tag(o_type), o_i) drops the extra String here too.
| } else { | ||
| None | ||
| }; | ||
| let meta = FlakeMeta::from_packed(lang.as_deref(), o_i); |
There was a problem hiding this comment.
Same double allocation as fluree-db-query/src/binary_range.rs:991: FlakeMeta::from_packed(store.resolve_lang_tag(o_type), o_i) drops the extra String here too.
| let FlakeValue::Ref(head) = &flake.o else { | ||
| continue; | ||
| }; | ||
| if *head == Sid::new(RDF, fluree_vocab::predicates::RDF_NIL) { |
There was a problem hiding this comment.
Blocking (performance): this allocates an Arc<str> for every IRI value of every crawled subject, on every ledger. Sid::new builds its name with Arc::from, and the check sits before the blank-node and holds_cells gates, so a crawl of a ledger that has never held a list pays it once per reference value. It's the same class as #2181 (list work paid by queries that never touch a list), in the same function #2217's holds_cells gate fixed. query_hot_list_view's listed/plain ratio won't see it, since both ledgers pay it.
fluree_db_core::namespaces::is_rdf_nil already does this without allocating:
| if *head == Sid::new(RDF, fluree_vocab::predicates::RDF_NIL) { | |
| if fluree_db_core::namespaces::is_rdf_nil(head) { |
A smaller one in the same spirit, if you agree: compact_list_property (hydration.rs:1474) does a context lookup for every property of every subject, list or not. Calling it only when has_lists is set keeps list-free crawls from paying it.
| /// (see [`crate::list_index`]); 0 for the first, and for every value | ||
| /// with no position. | ||
| #[serde(default, skip_serializing_if = "is_first_list")] | ||
| pub list: u32, |
There was a problem hiding this comment.
Optional (class fix + memory): with i and list both public, a position can still be read without its list. That's the shape most of this PR's commits fix by hand (the eleven readers 16eecec84 lists, the SHACL ones), the delete-template case is one that slipped through, and two of my open main PRs add more that will compile cleanly on next: #2214's record_flake_fact reads m.i as u32 into the union's fact identity, and #2202's listing_owners emits one owner edge per subject and predicate.
This is more of a suggestion than a must. If FlakeMeta held the place as one private packed u64 (this PR's own list_index::pack, with NONE) behind place() / packed_place() and a constructor, m.i would stop compiling, so each main → next merge that reads a position alone becomes a build error rather than a silent merge of two lists. It would also take FlakeMeta back from 40 to 32 bytes: Flake is 184 bytes at this head (measured) against 176 before, and every novelty, staging and range flake carries it. Serde would need a small hand-written impl to keep the {"i": …, "list": …} shape.
I recognize it's a wider edit than the rest, but since this PR already reshapes FlakeMeta, if you agree it's right I'd rather see it folded in now than lost in the backlog.
There was a problem hiding this comment.
Agreed that it's the class fix, and that it would turn those main → next merges into build errors. I'm leaving it out of this PR: it reaches every FlakeMeta reader across the workspace and needs the hand-written serde, and this PR is already wide. Deferring to a follow-up: #2267.
| // Try incremental indexing if conditions are met. A published index | ||
| // of an earlier format is rebuilt in full, so no root mixes artifacts | ||
| // of two formats. | ||
| let current_format = match &record.index_head_id { |
There was a problem hiding this comment.
Optional: this fetches the whole root to read its first five bytes, and the incremental path fetches it again. published_root_is_current (lib.rs:440-446) gets the root by id, and incremental_index → resolve_incremental_commits_v6 gets the same root a moment later. On a local store it's a cache hit; on a remote content store it's an extra GET of the root on every index cycle of every ledger, and roots with inline leaf keys aren't tiny.
Minimally we could pass the bytes we already have into incremental_index, or check the format where the root is first decoded there and return a "rebuild in full" outcome. It's minor and non-blocking, but if you agree it's right, I'd rather see it in this PR than lost in the backlog.
There was a problem hiding this comment.
Agreed. Deferring to a follow-up rather than growing this PR: #2268.
|
|
||
| /// Wire format size of a V2 run record (no g_id, no op). | ||
| pub const RECORD_V2_WIRE_SIZE: usize = 30; | ||
| pub const RECORD_V2_WIRE_SIZE: usize = 34; |
There was a problem hiding this comment.
Optional (performance evidence): could we get base-vs-head numbers for the format widening before merge? This change widens every import and index artifact a little: run records 30 → 34 bytes on the wire, spool 34 → 38, the import RunRecord 40 → 48 in memory, leaf keys 26 → 30, history entries 31 → 36, all for an o_i that is NONE on nearly every row.
I don't think any of these moves the headline numbers much, but I'd rather see that than assume it. import_bulk, reindex_full and reindex_incremental cover it, and bench.yml's compare job only runs the four query benches, so it'd be a local run at both SHAs (medium scale would do). If the run files turn out to matter, a writer could pick the narrow layout per run when every record in its buffer is list 0, since read_run_le_narrow already exists.
There was a problem hiding this comment.
Not run yet; deferring to a follow-up: #2269. If the run files turn out to matter, the per-run narrow layout you describe is the fallback.
| } | ||
|
|
||
| /// What the held edits write at `t` (see the [module docs](self)). | ||
| pub(crate) fn resolve(self, t: i64) -> Result<CellWrites> { |
There was a problem hiding this comment.
Praise. Resolving every cell edit once, against the lists the WHERE actually read, and refusing everything that isn't a one-for-one rdf:first replacement is exactly the narrowness I'd hoped for after #2159's cell-edit path. The "a cell left with its member changes nothing" and "several solutions agreeing replace once" cases fall straight out of the left set below, which made it easy to convince myself it holds.
Conflicts: TxnOpts and WhereStreamStats carry both the RDF-list cell edits and next's Cypher relationship deletes. compatibility.md keeps this branch's list-write text. export.md drops next's "a second list is stored as its triples", which this branch replaces: several lists on a property export as lists of their own.
p/rdf:rest*/rdf:first read lists through one view built from a dataset's first graph, with its reads keyed by graph and t alone: - A graph whose lists the first graph did not show (the same ledger at an earlier t, or after a ledger holding no list) was walked as a plain path and returned nothing. - Named graphs of two ledgers at one t shared list reads, so GRAPH ?g answered the second ledger with the first's lists. - A constant subject reached another ledger's graph in the primary's namespace codes, and matched nothing there. - Over a default graph spanning ledgers the walk returned no rows where any other property path is refused, and in a history range it returned none. The view is now built over every graph the dataset names (PrepareConfig::with_dataset). It keeps each ledger's list predicates in that ledger's namespace table, and keys list reads, subject probes and cell names by ledger. A read encodes its constants and IRIs in the ledger of its graphs, as a property path does. The multi-ledger fallbacks are gone: a default graph spanning ledgers gets the path refusal, and a walk over compact lists in a history range is refused with a 400. A walk over lists stored as triples reads them in history as before. Tests: a_list_walk_reads_each_graph_of_a_dataset (SPARQL and JSON-LD, novelty and indexed), and pooled_lists_read_as_members_and_construct_as_lists walks a pooled graph's lists again.
A @list in a JSON-LD delete deleted, at each position, the entry of the property's list holding that member there. It now names a list as a delete names a value: the property's lists with the same members in the same order and no more, each retracted whole. In an update with a where, each solution's list is matched on its own. A ( ... ) in a SPARQL DELETE WHERE matched only lists stored as their triples. Its owner edge and cells are now read in SPARQL's view of lists while the rest of the pattern reads members as values, so the collection gates the solution like any pattern, matches a stored chain as its triples, and deletes a compact list it matched whole. Members may be variables. Documents the empty list (rdf:nil) exception and that a second list on a property is now stored as a list of its own.
…t rdf:nil in the crawl without one Each decode site built an owned lang tag only to have FlakeMeta copy it again; it now hands over the borrowed tag. The crawl compared every IRI value against a freshly built rdf:nil Sid; it now uses is_rdf_nil.
…hat holds no list
Continues the list work of #2217 on
main. That PR has SPARQL read a list's members as values of the property that holds it, and CONSTRUCT write lists back. This PR, for the v5 major, gives each list an identity of its own, so a property can hold several lists compactly. It also adds an opt-in RDF reading of lists, through which an update can replace a member in place.Partially addresses #2171: list identity is done, and a second list on a property stays compact. Cell identity is not part of this design. A list whose cells carry other triples, are referenced, are nested or are shared stays stored as its
rdf:first/rdf:resttriples.Storage (index and commit format)
fluree_db_core::list_index).FlakeMetagainslist. Serde andDebugomit list 0, so existing JSON, transport and debug output read as before.o_i. The new artifact versions are leaf v2, branch v3, history sidecar v3/v4, pool delta v2 and root v4. A v4 index, or an earlier v5 alpha's, is served as it is: each decoder takes the width from its artifact's version and widens a 32-bito_ito list 0.index_root::is_current_format). No root mixes two formats.Writes
ADDgives each source list a fresh id in the destination.FlakeMetaequality and hashing go by language tag and list place, as its ordering does.Deletes
A list in a delete now names a list, as a value names a value. This is a behavior change, documented in
compatibility.md.@listin a JSON-LDdeleteused to delete, at each of its positions, the entry there of the property's list 0, so with a second list compact it could delete from a list it didn't name. It now retracts, whole, each list the owner holds with the same members in the same order and no more, and nothing else. Each member matches as the same value deleted on its own would. With awhere, each solution's list is matched on its own, and one with an unbound member names nothing.( … )in a SPARQLDELETE WHEREused to match only a list stored as triples. Its owner edge and cells are now read through SPARQL's list view, while the rest of the pattern reads members as values.()or{"@list": []}, is the IRIrdf:nil, as SPARQL and JSON-LD define it. It deletes as that value does, an entry of a list that holdsrdf:nilincluded. This is documented as the exception.DELETE DATArefuses a( … ). Under therdf-listspragma, a list in a DELETE template and an owner-edge delete are refused.Reads
@listobject. This output change is documented.p/rdf:rest*/rdf:firstreaches each member of the listspholds, in SPARQL and JSON-LD, in queries and in an update's WHERE. Every other pattern still reads members as values. Over a dataset, it reads each graph in that graph's own ledger and time. A default graph spanning ledgers gets the 400 any property path gets there, and a walk over compact lists in a history range is a 400.Lists as RDF, on request
# PRAGMA rdf-lists: true(JSON-LD"opts": {"rdfLists": true}) reads every list as the RDF list it denotes. The property's value is the head cell, a blank node named by the request, and each cell has anrdf:firstand anrdf:rest. Requests that don't ask read lists as before.Where the view cannot be honored, the request is refused with a 400 rather than answered with members. That covers a history range, a dataset of several ledgers or of one ledger at several times, and a JSON-LD graph crawl. A policy query (which then fails closed), a rule and an
sh:selectrefuse the pragma.In an update, this first phase supports replacing a member through its cell's
rdf:first(fluree_db_transact::cell_edits).Every other write naming a cell is refused, and the update changes nothing:
rdf:first, or with two;rdf:restor owner edge written;A list in a DELETE template and an upsert are refused as well. Cell names generated by a request are never persisted.
In this view, a delete naming a value removes its plain value only, since a list's members are its cells'
rdf:firstvalues. A list written beside a cell edit takes the next id past the edited list.Lists stored as explicit
rdf:first/rdf:restchains are stored triples and are edited as before.SHACL
sh:pathterm (or onsh:alternativePathor a path operator) are two values, not one merged path.sh:or,sh:xoneandsh:andlist on a shape is its own constraint, including when its cells are in another shapes graph. This grouping was also wrong on 4.2; it is fixed here only.Upgrade
docs/operations/upgrading-from-4.2.md:Tests
it_list_cell_editsandit_projection_lists.it_list_identity,it_sparql_list_members,it_sparql_lists,it_export_lists,it_transact_list_container, the policy and rule refusals, and the pragma parser.it_filtered_delete_list_metaandit_join_batched_overlayremoved one entry of a list with a positional@listdelete, which no longer exists. They now make the same edit through a cell underrdfLists, with their assertions unchanged.Not in this PR
Inserting, removing and reordering members through their cells is the next phase. Until then those edits are refused with a 400, and a list is rewritten by an update without the pragma.
DELETE WHEREnaming one by that subtype misses it after an index build. That holds for a collection member as for a plain value.DELETE WHERE: an anonymous[]deletes nothing #2266. An anonymous[]in aDELETE WHEREwith noGRAPHblock deletes nothing. It predates this PR and is onmain.FlakeMeta: hold a list place as one private packed value #2267. Hold a list place as one private packed value, so a position can't be read without its list.