Repository navigation
fix: typed dataset and graph references: one grammar, one resolver - #2007
Conversation
|
Full mutation log for this PR's non-vacuity runs, moved out of the description to keep it under GitHub's size limit. Each new regression test was run against its fix reverted (the file text saved, mutated, the named test run, the text restored, and the tree checked clean after each). Every mutation below turned its test red. Earlier rounds ran on the commits as they were then, before the rebase onto api: typed dataset members (ac7394c)
query/api: graph-source probes fail closed (3591cb4)Test: it_sql_pushdown_lane::graph_source_probes_fail_closed_and_skip_ledger_graphs.
api: graph() and db() take any ledger address; view refuses another ledger's from (9dde79a)
query: SERVICE endpoint names a dataset member or the query's own ledger (6597d79)
transact: an update's WHERE dataset resolves in the transaction's ledger (1e6c466)
server: the ledger routes resolve dataset references in the path's ledger (9e486b6)
cli: route a query after resolving its dataset in the target ledger (6c72522)
api: keep the dataset parsers' public shape (6b1a876)
api/cli: typed query advisories (cb9cd66)Test: it_query_dataset::a_named_only_dataset_advises_when_the_query_reads_its_empty_default_graph.
cli:
|
Two benches for the request shapes whose dataset references are parsed,
classified and resolved per request, so the typed-reference work that
follows has before numbers to compare against.
fluree-db-server dataset_http: warm in-process HTTP requests with SPARQL
FROM / FROM NAMED, JSON-LD from, and GRAPH scopes on /query and
/query/{ledger}, a bearer-token request, a query with a 2 KB VALUES block,
and three streaming requests on /stream/query/{ledger} (10k default-graph
rows with and without a policy input, and 16 FROM NAMED members under a
policy input). Each case checks its row count once before timing.
fluree-db-api dataset_build: build_dataset_view and FROM NAMED x 1/4/16
through query_from() on a file-backed connection, for members that are
graphs of one ledger and for members that are separate ledgers, plus the
same query with the graph-source providers attached (iceberg feature).
A ledger, a time, a graph of a ledger and a bare graph IRI are all written
as text, and each surface split that text itself: at HEAD there are seven
parsers of the address grammar, and they disagree about '#', '@' and
'urn:fluree:'. This adds the one typed form they can all share, in a new
fluree-db-core module, dataset_ref:
- GraphIri: an absolute IRI (validate_absolute_graph_iri), the only way to
name a graph by IRI.
- GraphSel { Default, TxnMeta, Config, Named(GraphIri) }: which graph of one
ledger. The one keyword table for 'default' / 'txn-meta' / 'config'. A
relative name is refused instead of being looked up literally.
- LedgerRef { id, at: Option<TimeSpec>, graph: GraphSel }, private fields:
the parsed address for ledger positions. Replaces the raw-string struct
of the same name (its pin was a String and its fragment unvalidated).
- DatasetRef { Address | GraphIri | Ambiguous }: what a dataset-position
string (FROM, FROM NAMED, a JSON-LD from string) names before resolution.
Ambiguous carries both readings of text that is lexically both, such as
'mydb:main', for a resolver that holds a graph registry to choose.
- TimeSpec moves here from fluree-db-api (re-exported at both of its old
paths, with From<LedgerIdTimeSpec>), together with its grammar tests.
Two grammar rules keep the address grammar from swallowing graph IRIs:
- A branch may not begin with '/': LedgerId::parse refuses one, so
'http://ex.org/g' is no longer read as ledger 'http', branch
'//ex.org/g'. Legacy branches that merely contain '/' still parse, and
stored records keep parse_persisted.
- '@' starts a pin only before a known tag. In a ledger position any
other '@' is a bad pin; in a dataset position it means the text is not an
address ('http://ex.org/@alice/g', 'mailto:a@b').
With the first rule a hierarchical graph IRI no longer parses as an id, so the SQL and
Delta dispatch probes, which receive the GRAPH IRIs a query writes, now
classify the IRI first: one that does not parse as a graph-source id names
no source and is declined without a lookup, while a failed lookup of a
well-formed id still fails the query: the same guard #1997 added
(dispatch_record).
The existing LedgerRef callers (server path parsing, scope_id, the MCP
ledger argument, the graph-source fallback, same_ledger) move to the typed
accessors.
A dataset member was a GraphSource with an `identifier: String` that every
consumer re-read: a SPARQL FROM IRI went through its own stringifier
(prefixed names unexpanded), then a third address parser that split '@' and
'#' textually, and a graph IRI on a connection route was looked up in the
nameservice as a ledger. Members are now parsed once into typed values and
resolved by one table.
- GraphSource keeps the text as written, what it names (MemberRef: a graph
keyword, or a DatasetRef), its time and its per-source options, behind
private fields. It is built by parsing (GraphSource::parse, TryFrom,
FromStr) or from a typed address (GraphSource::ledger); `identifier` is
gone. dataset::GraphSelector is now an alias of core's GraphSel.
- One JSON-LD dataset parser: DatasetSpec::from_json reads the `opts` and
`ledger` spellings that only from_query_json used to. An object's `@id`
is a ledger address and its `graph` a graph of that ledger; naming a
graph in both is refused.
- SPARQL dataset clauses are read from resolve_dataset_clause, so prefixed
and BASE-relative FROM / FROM NAMED IRIs expand against the prologue on
every route (DatasetSpec::from_sparql / from_sparql_ast). A dataset IRI
written in full is taken as written: FROM <mydb:main> is not a misused
prefix even when the query declares `mydb:`.
- core gains MemberRef and TargetLedger, the resolution table for a
ledger-scoped surface: the ledger's own address in any spelling is its
default graph; the written text as an exact registry IRI (reserved slots
included) is that graph; a keyword or `L#graph` selects within; another
ledger is CrossLedger; an unknown graph IRI is GraphNotFound. The view
path's within-ledger FROM and every graph selection (`db("L#g")`, a
member's graph) resolve through it, so the short alias `FROM <L>`,
`FROM <L#iri>`, `FROM <L#config>`, a keyword, and the main branch's
`urn:fluree:L:main#config` read from a branch all work there (#1512).
- On a connection surface a bare graph IRI or keyword names no ledger: a
400 that names the fix, instead of a nameservice lookup of the IRI.
- A named member is known by its alias, else its text as written, pin
included: `FROM NAMED <L@t:2>` answers `GRAPH <L@t:2>` and two pins of
one ledger are two members. The time-stripped name it had before stays a
non-enumerated alias while exactly one member claims it, so
`GRAPH <L>` over one pinned member still matches (DataSetDb gains the
alias map).
- Caller mistakes in this area are no longer 500s: an unknown graph is a
404 (new ApiError::GraphNotFound, which is not is_not_found(), so it
never falls back to a graph-source lookup); a missing dataset, a
cross-ledger or pinned within-ledger member, and the within-ledger
history-range refusal are 400s. An unknown pin tag in a dataset position
reports the pin, not "not an IRI".
- sparql_dataset_ledger_ids returns the canonical ids a clause names by
address (graph IRIs are not ledgers), and the CLI's "already has a
dataset clause" guards use the new sparql_has_dataset_clause.
- Fluree::is_single_ledger_fast_path (test-only callers) is removed.
The ledger route keeps its own FROM classifier for now and only moves to
the typed constructors; routing it through TargetLedger follows.
…robed `R2rmlProvider::has_r2rml_mapping` returned `bool`, and the api's provider turned every nameservice error into "no mapping"; the GRAPH operator and the fused R2RML aggregate also `.ok()`-ed `compiled_mapping`. During a nameservice outage a GRAPH-addressed R2RML, Iceberg or SQL source therefore read as an empty native graph, with a 200. The probe now returns `QueryResult<bool>`. An IRI that is no graph-source id is still `Ok(false)` without a lookup; a lookup that fails fails the query, and so does a failed mapping load for a graph found to be a source. Failing closed alone would have made every query that carries the R2RML provider (every `query_from()` and `graph().query()` on an iceberg build) depend on the graph-source registry, because the executor probed the primary snapshot and each dataset member on every query. Views now say what they read: a `MemberKind` (`Native`, `GraphSource`, or `Unclassified` for callers that do not say) on each runtime `GraphRef`, and on `ContextConfig` for the no-dataset primary. The executor's precomputed set, the GRAPH operator, the fused aggregate and the SQL lane never ask about a graph loaded as a ledger graph. Graph-source members are probed as before, and a GRAPH IRI that is not a member is the one remaining run-time probe. A probe failure surfaces as the provider's existing "Nameservice error" (`QueryError::Internal`, which the api maps to 400 like the provider's other nameservice errors). Test: it_sql_pushdown_lane `graph_source_probes_fail_closed_and_skip_ledger_graphs` runs against real SQL sources with every graph-source lookup failing: `GRAPH <source>` errors on and off the lane, in SPARQL and JSON-LD; the native twin answers exactly as with a healthy nameservice through its own view, `FROM`, and `FROM NAMED` + `GRAPH`; a GRAPH IRI that is no id answers without a lookup.
… ledger's from
`graph()` stored the raw string and handed it to the ledger loader, which
takes only `name[:branch]`, so `graph("L#txn-meta")`, `graph("L#<graph IRI>")`
and `graph("urn:fluree:L")` failed although `db()` accepted them (#1961).
The handle now parses a `LedgerRef` once. Queries and `load()` read the
address's graph through the loader `db()` uses. A pin in the address
(`L@t:5`) is honored, and one that disagrees with `graph_at`'s is a 400;
`db()` honors a pin the same way. A transaction applies to the whole ledger
at HEAD, so `.transact()` through a graph-qualified or pinned handle is
refused with a 400. The commit builder reads the address's ledger.
A JSON-LD query on a view reads the view's ledger, but a `from` or
`fromNamed` naming another ledger, or one that does not exist, was ignored
and the query silently answered from the view. All four view entry points
refuse it now with a 400 that points at `query_from()`. A `from` naming the
view's own ledger, in any spelling, still answers. The other within-ledger
JSON-LD `from` shapes keep their current reading; honoring them on the view
path belongs to lane consolidation (part 2).
The tracked view paths report the within-ledger FROM resolver's own status
(404 for a graph the ledger lacks), as the untracked paths already do.
Tests: it_named_graphs `graph_handles_take_the_addresses_db_takes` and
`a_missing_ledger_reads_as_not_found_at_every_entry_point`; it_query_dataset
`a_view_refuses_a_jsonld_from_naming_another_ledger`.
…edger `SERVICE <fluree:ledger:X>` looked X up among the dataset's members and, when X was not one, ran the block against the current dataset. An endpoint naming another ledger, or no ledger at all, therefore answered with this dataset's rows. A non-member endpoint is now a 400 that points at FROM NAMED, and it contributes no rows under SILENT. It is never loaded on the spot, because a SERVICE endpoint is not authorized the way a dataset member is. With no dataset, the endpoint must still name the query's own ledger, as before. The endpoint's address is parsed with the shared ledger grammar, so the `urn:fluree:` spelling works. A pin or a graph in it is malformed: the member's time and graphs come from the dataset. Tests: service unit tests for the endpoint grammar; it_service_cross_ledger_iri `service_to_a_non_member_is_refused_not_answered_by_the_dataset` and `a_service_endpoint_is_never_loaded` (a recording nameservice sees no lookup of the endpoint's ledger).
A single `USING <g>` or `WITH <g>`, or a JSON-LD update `from` / `graph`,
that the graph registry did not resolve fell back to g_id 0, so the WHERE
read the ledger's real default graph. `DELETE { ?s ex:v ?o } USING <typo>
WHERE { ?s ex:v ?o }` deleted it, `WITH <new> INSERT … WHERE …` copied it,
and `USING <L#config>` read the default graph instead of the config graph.
Two or more `USING` graphs skipped an unresolved IRI, which dropped
the ledger's own address. JSON-LD refused `"from": "L:main"` as an
undefined prefix.
Every WHERE-dataset reference (`USING`, `USING NAMED`, `WITH`, and the
JSON-LD `from`, `fromNamed` and `graph` keys) now resolves once, in the
transaction's ledger, through the table a query's FROM uses:
- the ledger's own address, in any spelling, names its default graph;
- `L#config` or its URN names the config graph;
- a registered IRI names its graph.
A graph the ledger does not have contributes nothing, so a WHERE over it
binds nothing (SPARQL 1.1 Update §3.1.3, Query §13.2). Another ledger's
address, or a pinned address, is a 400, since the WHERE reads only this
ledger as it stands. The single and multi branches share the resolver. The
JSON-LD dataset keys are dataset references: a prefix the context defines
still expands, and any other text is kept as written for the resolver.
rule (own address, else registry, else empty). This is its generalization;
the rebase onto #1997 keeps this side.
Test: it_named_graphs
`update_where_dataset_references_resolve_in_the_transactions_ledger`, each
shape above in SPARQL and JSON-LD, with the cross-ledger and pinned
refusals.
…dger
The ledger routes (`/query/{L}`, `/stream/query/{L}`, `/explain/{L}`) loaded,
authorized and compared the path as spelled, so `/query/b2x` with
`FROM <b2x:main>` or `"from": "b2x:main"` was a ledger mismatch, and
`/query/urn:fluree:b2x:main` could not load at all (#1982). `PathLedger` now
carries the canonical id (plus any graph the path selects), and every
downstream use reads it.
Each SPARQL `FROM` / `FROM NAMED` IRI, and each JSON-LD `from` / `fromNamed`
source, was classified by string shape: an IRI with `#` or `@` was taken for
ledger syntax ("Ledger mismatch" for `<http://ex.org/vocab#products>`,
"Invalid time travel" for `<http://ex.org/@alice/g>`), the short
alias or the URN of the path's own ledger read as a graph name (500 Unknown
named graph), and a graph IRI in `fromNamed` was loaded as a
ledger (404). The clause is now expanded against the prologue first
(prefixed and BASE-relative IRIs), and each reference resolves once, in
the path's ledger, through the table the view path and updates use, with the
ledger's graph registry:
- the ledger's own address in any spelling names it, or the graph the
address names;
- a keyword or a registered IRI names that graph;
- an IRI the registry does not hold is left to loading, which answers 404
`err:db/GraphNotFound`;
- another ledger is a 400.
A single JSON-LD `from` must name the path's ledger. A `from` array and
`fromNamed` may also name other ledgers, as before. The dataset lane and its
per-member loading are unchanged.
`ApiError::GraphNotFound` now maps to 404 with the new `@type`
`err:db/GraphNotFound` on the server (it fell through to a 500).
Tests: sparql_dataset_semantics
`ledger_route_dataset_references_resolve_in_the_paths_ledger` (graph IRIs
with `#` and `@`, the config graph by its URN, each spelling of the path and
of the ledger in `FROM` and `from`, a prefixed `FROM NAMED`, a graph IRI in
`fromNamed`, an unknown graph, another ledger in each language); unit tests for the path id and the JSON-LD
normalization.
`fluree query` chose between the target's own view and the connection path by comparing base names (`mydb:feature-x` and `mydb` share `mydb`) and by reading only a string or string-array JSON-LD `from` (#1972). A branch other than the target's ran against the target's branch; a JSON-LD `from` naming one of the ledger's graphs, in string or object form, or naming a ledger that does not exist, ran on the view path, which ignored it and answered from the default graph; SPARQL `FROM` of another branch failed there. The router now resolves each reference in the target ledger through the table every surface shares, using the ledger's graph registry when it is local. Locally: - the view path keeps what it reads: its own ledger in any spelling, and SPARQL graphs of that ledger; - another ledger or branch, a time pin, and every JSON-LD source other than the whole ledger (a graph, `fromNamed`, a history `to`) take the connection path, which reads them. For a remote target, the ledger route resolves references against its own registry, so only a reference that names another ledger leaves it. The base name comparison and the `from` scraper are gone. Tests: unit routing decisions for the local and remote rules; CLI integration `local_query_reads_the_graph_or_branch_its_dataset_names` (graph by address and object form, config graph, another branch in JSON-LD and SPARQL, a missing ledger).
Callers outside db read which ledgers a query names before running it,
through `DatasetSpec::from_query_json` (each member's `identifier` and
`policy_override`) and `sparql_dataset_ledger_ids`, so these two must report
every ledger the query can read. The typed members had made `identifier` and
`policy_override` private and changed what `sparql_dataset_ledger_ids`
reported.
Both fields are public again. `identifier` is the reference as the query
named it, with an address's `@` pin removed and a `#graph` kept, as before.
Both are derived from the typed parse, and resolution reads the typed
reference, never them. `sparql_dataset_ledger_ids` reports every member's
identifier (minus `#graph`) and the history range's ledger, as before. A
reference whose reading depends on a ledger's graph registry is reported
too.
The typed ids the connection path loads are the new `sparql_dataset_ledgers`,
which the server's own authorization, refresh and comparisons now use.
A dataset clause's prefixed name whose prefix is not declared
(`FROM ledger:main`) is again the ledger address as written; a declared
prefix still expands.
Tests: dataset unit tests `from_query_json_reports_every_named_ledger` and
`sparql_dataset_ledger_ids_reports_every_named_ledger` (string, array and
object `from`, `{"@id", "t"}`, `fromNamed` object, legacy `from-named`,
`opts.from`, `ledger`, `FROM<x>` with no space, a bare `FROM ledger:main`,
several clauses, a commented-out clause, a history range, a per-source
policy); it_query_dataset
`reported_dataset_ledgers_cover_every_ledger_the_engine_reads`, which runs a
corpus through a recording nameservice and checks that every ledger whose
record the engine reads was reported. The recording nameservice moves to
the shared test support.
…ferences Conflict in fluree-db-api/src/view/fluree_ext.rs: main's `graph_db_from_cached_head` and `ContentId` (opening the model ledger at its head commit) kept; this branch's typed-reference imports kept, and the `GraphRef` enum it replaced stays removed.
…ferences Conflicts in fluree-db-api/src/error.rs and fluree-db-server/src/error.rs: main's single status table (`ApiError::status_code`, `ApiError::error_type`) kept, and the server's own table dropped as main drops it. `QueryError::Nameservice` is classified in `query_error_status` (500) and in the `@type` table (`err:system/NameServiceError`), with a row in the every-variant test. This branch's `From<TargetError>`, `scope_id` and nameservice tests are kept. Conflicts in fluree-db-api/src/query/connection.rs and view/query.rs: this branch's dataset readers (`connection_dataset_spec`, `connection_sparql_dataset_spec`, `refuse_cross_ledger_from`) kept, each error wrapped with main's `TrackedErrorResponse::from_api`, so a tracked query answers the status the one table gives.
bplatz
left a comment
There was a problem hiding this comment.
Approving: one grammar and one resolver is the right shape, and the docs and tests are thorough. There are items inline to look at and address:
Regressions against main, worth fixing before merge
- CLI
--remotewithFROM <other:main>/{"from":"other:main"}stays on the ledger route and gets a 400. - An update's
USING <urn:g1>(an ambiguous IRI with no graph yet) is now a 400, not an empty match. - With a
BASEdeclared, bare and pinned ledger names inFROMare BASE-resolved on the connection route.
Fix or file as follow-ups
- The JSON-LD ledger route resolves its dataset before the min-t wait.
- The CLI loads the ledger twice to choose a route.
L:feature#configwrites on a branch that inherited its source's labels.- A legacy
urn:defaultgraph shadows the default graph. scope_registryswallows registry errors.
Nits
- Repeated parsing in
target_dataset. - Duplicated graph-id lookups.
- Written text re-split after parsing.
main has moved 67 commits since the last merge. It merges cleanly except for one BENCHMARKING.md table conflict (keep both rows), and the merged tree passes cargo check --workspace --all-targets, clippy and fmt.
| match resolver.resolve(written, &member, pinned) { | ||
| Ok(_) => local && pinned, | ||
| Err(TargetError::GraphNotFound(_)) => false, | ||
| Err(TargetError::CrossLedger { also_iri, .. }) => local || !also_iri, |
There was a problem hiding this comment.
Regression for --remote. A remote target has no registry, so FROM <other:main> reads as ambiguous and local || !also_iri keeps it on /query/mydb, where the server answers 400 "Ledger mismatch". JSON-LD {"from":"other:main"} has the same gap through names_another_ledger (it only counts DatasetRef::Address). On main, the base-name comparison sent both to /query. Suggest: when the registry is unknown, an ambiguous reference to another ledger goes to the connection path. The tests cover only the bare and pinned forms.
There was a problem hiding this comment.
Good catch, and the mechanism is exactly that: the CLI holds no registry for a remote ledger, so other:main read as possibly a graph and stayed on /query/mydb. In 42c41706f, with no registry to consult, text that reads both as a graph IRI and as another ledger's address is read as that address, as on any surface with no target, so it goes to /query the way it did on main. On the JSON-LD side that's names_another_ledger, which now counts the ambiguous reading when the registry is unknown; on the SPARQL side it's the router's CrossLedger arm. remote_routing_sends_only_another_ledger_to_the_connection now covers the bare, pinned, @t:, urn:fluree:, #config and #<iri> forms, as FROM, FROM NAMED, and from (string, object, array) / fromNamed, and it fails with the change reverted. One side effect worth naming: FROM NAMED <urn:x> leaves the route too now, again as on main. A graph spelled that way is reached through the ledger (mydb:main#urn:x), which docs/cli/query.md now says.
| match TargetLedger::new(target_ledger, &resolve_graph_id).resolve(iri, &member, false) { | ||
| Ok(graph) => Ok(Some(graph.g_id)), | ||
| Err(TargetError::GraphNotFound(_)) => Ok(None), | ||
| Err(TargetError::CrossLedger { named, .. }) => Err(TransactError::Parse(format!( |
There was a problem hiding this comment.
An ambiguous IRI the registry doesn't hold (USING <urn:g1>, USING NAMED <ex:g>, JSON-LD "fromNamed": ["urn:g1"]) now fails the whole update with "names ledger 'urn:g1'". The comment above says a graph the ledger doesn't have contributes nothing. Suggest mapping CrossLedger { also_iri: true, .. } to Ok(None) here, and keeping the 400 for a definite other-ledger address.
There was a problem hiding this comment.
Agreed, the comment was right and the match arm wasn't. In d6bbda4b5, CrossLedger { also_iri: true, .. } maps to Ok(None) alongside GraphNotFound. So USING <urn:g1>, USING NAMED <ex:g> and "fromNamed": ["urn:g1"] contribute nothing again, and only an address that can't be anything else (USING <other>) is still the 400. The update matrix in it_named_graphs has those rows now (and w-other-ledger:main moved from refused to empty), and it fails with the arm reverted.
| // query also declares a `mydb:` prefix, so the misused-prefix check | ||
| // that pattern IRIs get does not apply to a dataset clause. | ||
| crate::ast::term::IriValue::Full(s) => Ok(match base.as_deref() { | ||
| Some(base) if !fluree_vocab::iri::is_absolute_iri(s) => { |
There was a problem hiding this comment.
is_absolute_iri is false for several ledger spellings (mydb, mydb@t:3, my_db:main). With a BASE declared they become http://ex.org/mydb@t:3 and so on, and the connection route answers "names no ledger". On main the connection path read them as written. Suggest trying the text as an address before BASE-resolving it, or documenting the change.
There was a problem hiding this comment.
This one needed a narrower version of the suggestion, fwiw. Trying every relative IRI as an address first would also keep FROM <data-g1.ttl> as written, and the W3C dataset tests depend on BASE resolving exactly that (the harness prepends BASE <query-url>). data-g1.ttl and mydb are lexically the same kind of text, so nothing can tell them apart. I tried it to be sure: with every address-shaped relative IRI kept as written, the 12 dawg-dataset tests fail. So in a82e3953b, an address that names its branch or a time (my_db:main, mydb@t:3, tenant/db@t:3) stays as written under a BASE, since no relative reference is spelled that way (RFC 3986 keeps a : out of the first segment), and a bare name follows BASE as SPARQL says. That leaves FROM <mydb> under a declared BASE as the one difference from main, documented in datasets-and-named-graphs.md. The tests are base_leaves_an_address_with_a_branch_or_time_as_written, in the sparql crate and in grp_query, and both go red with the check taken out. If you'd rather keep main's reading for bare names too, I think it would have to be a dataset-position rule that the W3C harness opts out of, which seems worse.
| // Ledger-scoped endpoint: resolve `from` / `fromNamed` in the path's ledger, | ||
| // rejecting attempts to target a different ledger than the URL. | ||
| let registry = if fluree_db_api::jsonld_names_dataset(&query_json) { | ||
| scope_registry(&state, &path.id).await |
There was a problem hiding this comment.
This reads the cached head's registry before the Fluree-Min-T wait below; the SPARQL ledger route refreshes first. On a peer, a graph registered by the commit being waited for is misread: in from it is a 400 mismatch, and in fromNamed it is loaded as a ledger and gets a 404. Could the path ledger's header min-t be awaited before scope_registry?
There was a problem hiding this comment.
Yes. In 7adc15fd8 the ledger routes await the path ledger's min-t before scope_registry, on /query, /stream/query and /explain. That covers the header, opts.min-t, a pinned path, and a numeric pin on the ledger's own address. Writing the test turned up a SPARQL twin of the same problem. The SPARQL route did wait first, but it keyed the header's min-t to whatever sparql_dataset_ledgers reported, so FROM <urn:g1> waited on a ledger called urn:g1, which doesn't exist. Both languages now go through one path_ledger_min_t. ledger_routes_wait_for_the_path_ledgers_min_t_before_resolving_the_dataset puts the route's head one commit behind (a second instance on the same storage commits the graph) and runs six shapes across the three routes. It fails with the JSON-LD pre-wait reverted, and separately with the SPARQL keying reverted.
| _ => Vec::new(), | ||
| impl EndpointGraphs { | ||
| async fn of_local(fluree: &fluree_db_api::Fluree, alias: &str) -> Self { | ||
| match fluree.ledger_cached(alias).await { |
There was a problem hiding this comment.
The CLI builds Fluree with without_ledger_caching(), so ledger_cached here is a full ledger load, and the query then loads the ledger again. Every local query that names a dataset now pays two loads just to choose a route. Suggest reusing this handle for the query, or reading the graph names some cheaper way.
There was a problem hiding this comment.
Reused the handle. In 7db0c3aab the router keeps the LedgerHandle it loaded, and the local path builds its view from it (Fluree::db_with_default_context_from_handle, plus an --at twin that resolves the time against that head). So a local query that names a dataset loads the ledger once again, and the plain NDJSON path reuses it too. Measured with dev-fast binaries at 7adc15fd8 and 7db0c3aab, interleaved, on a 302-commit unindexed ledger: FROM <bench:main> went from 31.5 to 21.1 ms median, FROM NAMED <g> from 34.4 to 22.1 ms, and JSON-LD "from": "bench:main" from 32.7 to 21.4 ms, which is where the no-dataset control sits (20.8 → 21.6 ms). --at drops the same ~10 ms (28.8 → 19.1 ms at the head). The box was shared, so take the medians as rough, but the minimums line up the same way.
| } | ||
| } | ||
| } | ||
| if let Some(found) = self.registered(written, || { |
There was a problem hiding this comment.
Minor: the exact-registry lookup runs before the keyword reading. So a graph registered literally as urn:default before #2005 shadows the default graph in FROM/USING/WITH, while graph_position and the WITH template still write the real default graph. Then WITH <urn:default> DELETE {…} WHERE {…} reads one graph and retracts from another. main checked DEFAULT_GRAPH_IRI first.
There was a problem hiding this comment.
Fixed in ba06dd75c: a keyword member now resolves before the exact-registry lookup, as main checked DEFAULT_GRAPH_IRI first. No write can create such a graph anymore, so the test renames one to urn:default in the loaded registry. It then runs WITH <urn:default> DELETE … WHERE …, USING <urn:default>, and the JSON-LD graph / from twins, and each one reads and retracts the default graph. With the registry-first order put back, the test fails at its first case, WITH <urn:default>, which leaves the default graph's fact in place.
| match state.fluree.ledger_handle(target).await { | ||
| Ok(handle) => Some(ScopeRegistry::Ledger(handle.graph_names().await)), | ||
| Err(e) if e.is_not_found() => Some(ScopeRegistry::Empty), | ||
| Err(_) => None, |
There was a problem hiding this comment.
Minor: proxy mode, and any load error other than not-found, both give None. With no registry, resolve_in_target reads an ambiguous other-ledger reference as a graph of the path's ledger. So {"from":"other:main"} becomes a 404 GraphNotFound instead of the 400 mismatch, and the storage error is dropped. Suggest propagating the error.
There was a problem hiding this comment.
Propagated in 7adc15fd8. On proxy mode, I think we can do better than no registry: a proxy peer's queries load through the same cached handle (execute_query_proxy → db() → ledger_cached), so it can read the registry the way a shared-storage peer does, and now it does. So {"from": "other:main"} on a proxy peer is the 400 mismatch, and {"from": "urn:g1"} reads the graph. test_proxy_peer_ledger_route_resolves_the_dataset_in_its_registry drives that through a real proxy peer, and with an empty registry put back for proxy mode it fails at the urn:g1 read. A load error other than not-found now fails the request instead of quietly dropping the registry. With no registry at all, which is now only the CLI against a remote server, an ambiguous other-ledger reference reads as that ledger, per the --remote fix above.
| fn source(&mut self, written: &str) -> Result<Option<InTarget>> { | ||
| if self.scope == Scope::AnyLedger { | ||
| let registered = self.graphs.is_some_and(|graphs| graphs(written).is_some()); | ||
| let other_ledger = MemberRef::parse(written) |
There was a problem hiding this comment.
Nit: each source is parsed with MemberRef::parse here, again in names_another_ledger, and again in resolve_in_target. That runs on every ledger-route request that names a dataset. Parsing once and passing the MemberRef down would match the parse-once design.
There was a problem hiding this comment.
Done in 42c41706f: Sources::source parses once and hands the MemberRef to resolve_member_in_target and names_another_ledger. The target's own id, written exactly as it stands, still takes no parse at all.
| let store = view.binary_store.as_ref(); | ||
| // Fallback for safety: if registry is missing an entry but a binary | ||
| // store has it (should not happen in a consistent ledger), use the store. | ||
| let lookup = |iri: &str| { |
There was a problem hiding this comment.
Nit: the "registry, then binary store" lookup is here, in view/query.rs's SPARQL FROM resolution, and in transact as ledger_graph_lookup, as well as ledger_view::graph_id_in. One shared helper would stop the fallback drifting between copies.
There was a problem hiding this comment.
Done in ba06dd75c: fluree_db_binary_index::HeadGraphNames is the one registry-then-store table. fluree_ext, the SPARQL FROM resolution in view/query.rs, transact (its ledger_graph_lookup is gone) and LedgerView/GraphNames all read through it. It implements the new core GraphNameTable, which is also what the L:feature#config fix needed. After main brought in #2009, aa60ba924 moved the last readers that still spelled the reserved keywords themselves onto the same tables. ledger_info's graph selector takes a keyword's slot from GraphSel::keyword; its IRI lookups still read the binary store alone, since ledger-info's stats come from the index. config_guard's cross-branch check reads the IRI through AddressText and LedgerRef::parse. An update's from keywords and the CLI's target alias go through GraphSel and AddressText too.
| /// reported as `name[:branch][#graph]`, whatever its spelling (the | ||
| /// `urn:fluree:` wrapper and the `@` pin removed, a bare name kept bare), and | ||
| /// anything else is kept as written. | ||
| fn identifier_of(written: &str, reference: &MemberRef) -> String { |
There was a problem hiding this comment.
Nit: this function and unpinned_name re-split the written text at # and @ after MemberRef::parse has already split it. Building both from the typed parts, or from a pin span recorded at parse time, would keep the grammar in one place.
There was a problem hiding this comment.
Done in ba06dd75c, through the parser's own lexer rather than the typed parts. The typed LedgerRef doesn't keep the spelling these need: the identifier keeps a bare name bare, and the pin alias keeps a URN's wrapper. So core has one lexer, AddressText, that LedgerRef::parse and DatasetRef::parse split through, and identifier_of / unpinned_name read the text's parts through it instead of splitting at # and @ themselves. It's one more lex of a short string per member, fwiw, not a second grammar.
…ferences # Conflicts: # BENCHMARKING.md
A reserved keyword in a graph position was looked up by this ledger's own `urn:fluree:` IRI. A branch made from an indexed ledger holds its source's IRI at the reserved slots, so `GRAPH <L:feature#config>` missed the config graph, and a write registered a new graph that `FROM <L:feature#config>` never read. `TargetLedger` now reads names through `GraphNameTable`, which also says which IRI a reserved slot is registered under, and a reserved keyword names the graph at its slot in every position. `fluree_db_binary_index::HeadGraphNames` is the one registry-then-binary-store table. The view's graph selection, its SPARQL `FROM`, transact's lookups and `LedgerView` / `GraphNames` read through it instead of four copies. A keyword now resolves before the exact registry lookup, as main checked `DEFAULT_GRAPH_IRI` first. A graph an earlier version registered as `urn:default` no longer shadows the default graph in `FROM` / `USING` / `WITH`, where a graph position and the `WITH` template read the real one. `AddressText` splits an address's text at `#` and `@` in one place. `LedgerRef::parse` and `DatasetRef::parse` split through it, and a member's reported identifier and a pinned member's alias read its spans instead of splitting the written text again. Tests: core unit tests for the slot, the keyword order and the lexer; `a_branch_of_an_indexed_ledger_writes_its_config_address_to_the_config_slot` (it_named_graphs) and `a_legacy_urn_default_graph_does_not_shadow_the_default_graph` (it_default_graph_name).
`USING <urn:g1>`, `USING NAMED <ex:g>` and JSON-LD `"fromNamed": ["urn:g1"]` read both as a graph IRI and as another ledger's address. When the ledger had no graph by that IRI, the update failed with "names ledger 'urn:g1'"; on main it matched nothing. It contributes nothing again, and only an address that can name nothing but another ledger (`USING <other>`) is refused. The update matrix in it_named_graphs covers each form.
With a `BASE` declared, `FROM <mydb@t:3>` and `FROM <my_db:main>` were resolved against it and named no ledger. A ledger address that names its branch or a time is no relative IRI reference (RFC 3986 keeps a `:` out of a relative reference's first segment), so `resolve_dataset_clause` takes it as written. A bare name (`mydb`) is also a relative reference, the same kind of text as the W3C dataset tests' `FROM <data-g1.ttl>`, so `BASE` still resolves it, as SPARQL specifies. Tests: `base_leaves_an_address_with_a_branch_or_time_as_written`, in the sparql crate and in grp_query.
`fluree query --remote` holds no graph registry for the remote ledger.
`FROM <other:main>` and `{"from": "other:main"}` read both as a graph IRI
and as another ledger, so the router kept them on the ledger route, which
answered 400 "Ledger mismatch". With no registry to consult, such text is
now the address, as on a surface with no target, so it goes to `/query`, as
on main; `resolve_in_target` reads it the same way, where it read it as a
graph of the target. A graph spelled that way is reached through the ledger
(`mydb:main#urn:x`).
`Sources::source` parses each JSON-LD source once and passes the parsed
member to the resolver and to the other-ledger check.
…egistry
The JSON-LD ledger routes (query, stream, explain) read the cached head's
graph registry before the `Fluree-Min-T` wait, so on a peer a graph the
awaited commit registers was misread: a 400 mismatch in `from`, and in
`fromNamed` a ledger to load and a 404. They now await the path ledger's
min-t first. The SPARQL ledger routes waited first, but keyed the header's
min-t to the ledgers the dataset parser reports, so `FROM <urn:g1>` waited
on a ledger named `urn:g1` (a 404). Both now wait on the path's ledger
through `path_ledger_min_t`: every reference on a ledger route resolves in
it.
`scope_registry` returns a load error other than not-found instead of
dropping the registry. A proxy-storage peer reads the registry too: its
queries load through the same cached handle, so it resolves a dataset as a
shared-storage peer does (`{"from": "other:main"}` was a 404
GraphNotFound there).
Tests: `ledger_routes_wait_for_the_path_ledgers_min_t_before_resolving_the_dataset`
(a second instance on the route's storage registers the graph) and
`test_proxy_peer_ledger_route_resolves_the_dataset_in_its_registry`.
The CLI builds its `Fluree` without a ledger cache, so the router's `ledger_cached` was a full load, and the query then loaded the ledger again. The router keeps the handle it loaded, and the local path builds its view from it (`Fluree::db_with_default_context_from_handle`, and `db_at_with_default_context_from_handle`, which resolves an `--at` time against that head). Plain NDJSON reads the same head.
…ferences Brings in #2009 and #2119. The two PRs each grew a typed graph-name module and an answer for the ledger's own address in a graph position; the merge keeps one of each: - fluree-db-core dataset_ref: #2007's module, a superset of #2009's GraphIri/GraphSel, with #2009's tests. GraphSel::bare_keyword is the keyword table as a JSON-LD graph name is written (`urn:default` is an IRI there); GraphSel::keyword adds `urn:default`. - transact: #2009's lexical GraphScope/WriteGraphs and its JSON-LD parser, without #1997's template-default flag (staging reads every scope through the graph-position table); the parser keeps a ledger address under strict compact-IRI checking and notes it, and reads `from`/`fromNamed` as dataset references. The reifier anchor follows its edge to the graph the table reads the scope as. - A top-level `values` cell reads through #2009's ledger encoding; this branch's IriMatch carrier is dropped, as planned for whichever landed second.
Four readers still spelled the reserved graph keywords, or split an address at `#`, themselves: - `config_guard::other_branch_system_graph` parsed `urn:fluree:<name>:<branch>#<role>` by hand; it now reads the IRI through `AddressText` and `LedgerRef::parse`, and the role through `GraphSel::bare_keyword`, with the same answers (the `urn:fluree:` form, an explicit branch, no pin, another branch). - `ledger_info::resolve_graph_selector` matched `default` / `urn:default`, `txn-meta` and `config` itself; it takes the slot from `GraphSel::keyword`. - An update's `from` matched `default` and `txn-meta` itself; it reads `GraphSel::bare_keyword`. - The CLI split a target's alias at `#`; it reads `AddressText::before_graph`. The merge-check role label comes from `GraphSel` too. `parse_graph_ref`, the view API's own keyword reader, was already gone on this branch: `db()` and `graph()` parse a typed `LedgerRef` and select its graph through `GraphSel`. Two comments that still named it are updated.
The merge with #2009 read every written graph name as an absolute IRI, so `"@graph": "mydb#config"` (no scheme) was refused, and so was `"graph": "mydb:main"` under strict compact-IRI checking when the context defines no `mydb` prefix. Before the merge they named the config graph and the default graph. A name that expands to no absolute IRI but is an address of the ledger being written is now `GraphName::Address`. It is built only by `AddressName::parse`, which checks the address against the ledger the parser writes, and staging reads it through the graph-position table like any graph IRI. Another ledger's address is refused at parse with the error the name had before. So staging no longer checks it, `Txn::address_graph_names` and `WriteGraphs::into_parts` go, and #2009's `into_iris` is back. `annotation_under_a_graph_named_through_the_address_anchors_to_that_graph` pins the reifier anchor following its edge to `<g>` when the scope is written `L#<g>`.
…efined-prefix error Since `ce0a70771`, a graph name that expands to no absolute IRI and is not an address of the ledger being written keeps the error it had before: under strict compact-IRI checking, the parser's "prefix 'exx' is not defined in @context", which is what `main` answers for `"@graph": "exx:g"`. Staging's own wording for it went with its check.
`ce0a70771` moved one refusal from staging to the parser: a graph name that expands to no absolute IRI is kept as an address only of the ledger being written. This pins the whole set at parse, in each graph position (the update `graph` key, a node `@graph`, a `["graph", …]` item): - this ledger's address (bare, with its branch, `#config`, `#<g>`, a time, `#txn-meta`) is kept for staging's graph-position table; - another ledger's address (with a keyword, a graph IRI or a time, a name without a scheme, a name sharing this ledger's as a prefix) and an unknown keyword on this ledger's address are refused with the error the name has without the address reading. The api test gains the JSON-LD twins of its SPARQL staging refusals: the address at a time, and `L#<L>` with no such graph.
…ferences Brings in #2137, #2118 and #2109. The one conflict is stage.rs's fluree_db_core import: #2109 dropped `FlakeMeta` from it, and this branch added the dataset-reference types. #2109's FactIdentity DELETE naming and fold, and this branch's typed graph resolution for USING / WITH and the write table, sit in separate hunks and merge as both wrote them.
|
Every new test in this PR, by name. These moved here from the description, which is at GitHub's size limit. New integration tests, each with its SPARQL and JSON-LD twin where the surface has both:
This round's new tests:
Existing tests whose expectation changed on purpose in earlier rounds, or that are retired:
This round's mutation log, at The merges' revert runs, at the head |
|
Thanks for the careful pass. All eleven are addressed in the PR rather than filed, on top of a fresh merge of |
…cord kept #2097 published and dropped such a branch. On this branch the id no longer parses, so the test now pins that: publish, lookup and drop are refused, nothing is written for it, and a record an older version wrote stays where it is.
Brings #2007 (typed dataset and graph references) onto next. Resolved: - import: a TriG block naming the ledger's own address writes the default graph, as main now reads it; its reified triples take next's rdf:reifies link in that graph, not main's bundle. - lower_sparql_update: next's DELETE WHERE helpers, without the graph_from_template_default field main removed. - graph_source provider: next's lookup_live, which already carries main's nameservice error. - nameservice: main's test that a branch beginning with '/' is refused and an older record for one kept, on next's create and lifecycle drop. - BENCHMARKING: main's dataset_build row; next has no annotation benches. - imports and re-exports from both sides. Ported to next: - advisory: next has no AnnotationTarget pattern; TermComponents reads no graph of its own, the link triple beside it does. - Main's new tests await the async genesis_ledger, publish fenced, name their ledgers name:main rather than as branches of one name (the multi-query mq:* ledgers and their spellings), and open a second instance beside a live server's storage without the storage lock.
This is more than any one issue below needs, on purpose. Dataset and graph references were strings that each site interpreted on its own, and the sites disagreed: SPARQL couldn't read the config graph JSON-LD could (#1512),
graph()refused namesdb()took (#1961), and the CLI silently ignored afromnaming the ledger's own graph (#1972). So rather than patch each site, this parses a reference once, at the edge, into a typed value, with one grammar and one resolver for reads and writes, so every surface reads it the same way and there's one place to reason about and tune. Fwiw, it's one of five PRs taking this approach, with #2006, #2008, #2009 and #2010.A dataset or graph reference —
FROM,FROM NAMED, JSON-LDfrom/fromNamed,USING/WITH, aSERVICEendpoint,db()/graph(), the ledger path of a route — used to be text that every surface split and classified on its own. Before this PR there were seven parsers of the address grammar and nine string-shape classifiers, and they disagreed about#,@andurn:fluree:. This PR parses a reference once, at the edge, into typed values influree-db-core, and resolves it through one table. Most of the fixes below fall out of that: each was a surface where a classifier guessed wrong.This is part 1 of two. It changes how references are parsed and resolved, not which execution lane the server or the embedded API picks for a shape: each shape runs where it ran before, with two exceptions that follow from reading a query the way the engine's parser reads it. A JSON-LD dataset written under
optsnow takes the lane the same dataset takes at the top level (the parser has always readoptsfirst), and the CLI's router sends a query whose dataset names a graph or another branch to the connection path, which reads it (#1972). Moving shapes between lanes is lane consolidation, which comes in a follow-up PR (part 2); see the end.Base.
main, with #2019 merged (3da440dbc). This branch's own 52 commits sit on #2019's last head,b061c5fcd, andmainis merged in (85183e83f;a0050eb49atba694ee79;1fbb44a4bat58b53238a;6ad964919atba4a982ec, with #2102;03e4b43edatf3c3b00ec;86cd7e2c2at04e1a6d37, with #2120;893521fb1at1d06ae2ef, with #2009 and #2119;06190d23catd9a1d2004, with #2122, #2126, #2127, #2131 and #2133;d68a3e871at4a0d14a1a, with #2109, #2118 and #2137).Where #1997's review left off. This also picks up the rest of bplatz's review comment on #1997: #1997 (comment). #1997 made the ledger's own address name its default graph in an update's default-graph positions (
WITH, a JSON-LD top-levelgraph). This PR makes it do so in every graph position of a query and an update, including templates, data quads, TriG blocks and bulk import — see "Graph positions" below.Fixes #1972
Fixes #1961
Fixes #1982
Fixes #1512
Follow-up: #1975
Follow-up: #1996
Since the last review (bplatz, 2026-10-19)
mainis merged in again (86cd7e2c2;BENCHMARKING.mdkeeps both table rows). Every item from the review is addressed here, in six commits;mainis then merged in with #2009, and four more commits finish the keyword consolidation, fix what that merge broke, and pin it (see "Merged with #2009", below the table):ba06dd75c, core: one graph-name table and one address lexer.TargetLedgerreads names throughGraphNameTable, which also answers which IRI a reserved slot is registered under. A reserved keyword in a graph position (L:feature#config, and the branch's ownurn:fluree:spelling) now names the graph at its slot. On a branch made from an indexed ledger, a write lands whereFROM <L:feature#config>reads; before, it registered a new graph.fluree_db_binary_index::HeadGraphNamesis the one registry-then-binary-store lookup. The API's view and dataset paths, transact, andLedgerView/GraphNamesall read through it.maincheckedDEFAULT_GRAPH_IRIfirst. A graph an earlier version registered asurn:defaultno longer shadows the default graph inFROM/USING/WITH.AddressTextis the one place an address's text splits at#and@.LedgerRef::parseandDatasetRef::parsesplit through it, and so do the member identifier and the pinned member's alias.d6bbda4b5, transact: an update'sUSING <urn:g1>,USING NAMED <ex:g>or"fromNamed": ["urn:g1"]naming a graph the ledger lacks contributes nothing again. Only an address that can be nothing but another ledger (USING <other>) is a 400.a82e3953b, sparql: under aBASE, a ledger address that names its branch or a time (my_db:main,mydb@t:3) is taken as written, since no relative IRI is spelled that way. A bare name (mydb) still followsBASE: the W3Cdatasettests depend onBASEresolvingFROM <data-g1.ttl>, which is lexically the same kind of text. That is the one difference frommainhere; see the table.42c41706f, api/cli: with no registry to consult (fluree query --remote), text that reads both as a graph IRI and as another ledger's address is that address, soFROM <other:main>and{"from": "other:main"}go to/query, as onmain. Each JSON-LD source is parsed once.7adc15fd8, server: the ledger routes (/query,/stream/query,/explain) await their ledger's min-t before they read its registry. The SPARQL routes keyed the header's min-t to whatever the dataset parser reported, soFROM <urn:g1>waited on a ledger namedurn:g1; both languages now sharepath_ledger_min_t.scope_registrypropagates a load error other than not-found. A proxy-storage peer reads the registry too: its queries load through the same cached handle.7db0c3aab, api/cli: a local query reads the head its route was chosen on (Fluree::db_with_default_context_from_handle, and an--attwin), so naming a dataset no longer costs a second ledger load.Against
main, for the shapes this round touches:main6ad964919)fluree query --remote,FROM <other:main>or{"from": "other:main"}/query/query--remote,FROM NAMED <urn:x>(a graph of the remote ledger)/query, read as a ledger/query, read as a ledger;FROM NAMED <mydb:main#urn:x>reads the graphUSING <urn:g1>,USING NAMED <ex:g>,"fromNamed": ["urn:g1"], no such graphBASEdeclared,FROM <mydb@t:3>or<my_db:main>BASE-resolved, names no ledgerBASEdeclared,FROM <mydb>BASE-resolvedBASE-resolved, as SPARQL specifiesurn:defaultby an earlier version,WITH <urn:default> DELETE …GRAPH <L:feature#config>urn:fluree:L:feature#configFluree-Min-T: N,"from": "urn:g1"or"fromNamed": ["urn:g1"], the graph registered by commitNurn:text read as one)N: 400 (from), 404 (fromNamed)Fluree-Min-TwithFROM <urn:g1>urn:g1, which doesn't exist{"from": "other:main"}GraphNotFoundMerged with #2009
#2009 landed after the review;
893521fb1merges it (with #2119). Both PRs grew a typed graph-name module and an answer for the ledger's own address in a graph position, so the merge keeps one of each, andaa60ba924moves the last readers that spelled the keywords themselves onto the one table:dataset_refis this PR's module, a superset of fix: JSON-LD graph scoping, config integrity and explicit-only SHACL #2009'sGraphIriandGraphSel, with fix: JSON-LD graph scoping, config integrity and explicit-only SHACL #2009's unit tests. fix: JSON-LD graph scoping, config integrity and explicit-only SHACL #2009's keyword table isGraphSel::bare_keyword, as a JSON-LD graph name is written (urn:defaultis an IRI there, and a write still refuses it);GraphSel::keywordaddsurn:default, for the positions that read it as the default graph.GraphName/GraphScope/WriteGraphsand JSON-LD parser, without fix: unresolvable graph references fail closed, and TriG directives apply in document order #1997's template-default flag: staging reads every scope through the graph-position table. fix: JSON-LD graph scoping, config integrity and explicit-only SHACL #2009's reifier anchor (f:reifiesGraph) follows its edge: dropped when the scope reads as the default graph,<g>when it was writtenL#<g>."@graph": "mydb#config", or"graph": "mydb:main"under strict compact-IRI checking with nomydbprefix) is that address (GraphName::Address), which staging reads through the table; another ledger's address is refused at parse, as before. The merge first refused these too;ce0a70771fixes that, and82e2b054cpins every name the reading admits or refuses, in each position.valuescell reads through fix: JSON-LD graph scoping, config integrity and explicit-only SHACL #2009's ledger encoding;931873eb5's carrier is dropped (see "Overlap with fix: JSON-LD graph scoping, config integrity and explicit-only SHACL #2009").aa60ba924:config_guard's cross-branch check,ledger_info's graph selector, an update'sfromkeywords and the CLI's target alias read throughGraphSelandAddressText, with the same answers. (parse_graph_refwas already gone:db()andgraph()parse aLedgerRef.)#2009's tests run unchanged (the one edit to its files is
it_txn_meta.rscallingGraphSource::parse). Againstmainwith #2009, the tables hold, except that a JSON-LD graph writtenmydb#configor a baremydbwas a 400 there (no absolute IRI).06190d23candd68a3e871mergemainagain, conflicting only in imports (fluree-db-api's re-exports;stage.rs, where #2109's FactIdentity DELETE resolution and this branch's graph resolution sit in separate hunks).What changes for users
Grammar
A ledger address is
[urn:fluree:]name[:branch][@<tag>:<value>][#<graph>], parsed by one parser (LedgerRef::parse). Two rules keep it from swallowing graph IRIs:/.http://ex.org/gused to parse as ledgerhttp, branch//ex.org/g; it is now never a ledger id. The rule lives inLedgerId::parse, so it holds for every caller of that function, not only at the input edges. Stored records deserialize throughLedgerId::parse_persistedand are unaffected, and branches that merely contain/(feature/x) still parse. (A branch whose name begins with/, creatable from v4.0.0 through v4.2.1, is not addressable; see "Persisted data".)@starts a time pin only before a known tag (t:,time:/iso:,commit:,recorded:,snapshot:). In a ledger position any other@is a malformed pin (400); in a dataset position it means the text is not an address, so<http://ex.org/@alice/g>andmailto:a@bare graph IRIs.A dataset-position string is classified as an address, a graph IRI, or ambiguous (lexically both, like
mydb:main):scheme://…or two or more:before any#/@is a graph IRI (aurn:fluree:address excepted); a pinned address is an address;name:branchis ambiguous; a barenameis an address. An address with a known pin tag and a bad value (mydb:main@t:abc) or with nothing after its#(mydb:main#) is a malformed address (400) in either spelling,urn:fluree:included; an IRI that is no address keeps an empty fragment (http://ex.org/ns#). An empty string is neither, and is a 400 in every dataset position ({"from": ""}included). SPARQL dataset IRIs are expanded against the prologue (prefixed names,BASE) on every route before classification. An IRI written in full is taken as written, and a prefixed name whose prefix the query does not declare (FROM ledger:main) is the address as written. Under aBASE, an address that names its branch or a time (my_db:main,mydb@t:3) is no relative IRI and is taken as written; a bare name (mydb) is one, andBASEresolves it.One resolution table
Where a surface reads one ledger (a ledger route, a view, an update's
WHERE, the CLI with a target), each reference in a dataset position resolves in that ledger, in order:mydb,mydb:main,urn:fluree:mydb:main), with no pin and no graph: the default graph.defaultorurn:default,txn-meta,config): that graph, whatever the registry holds under the text.urn:fluree:mydb:main#configresolves on a branch, and a user graph may itself be namedurn:fluree:….mydb:main#config,mydb#http://ex.org/g): that graph; a reserved one by its slot.err:db/GraphNotFound. Where the surface cannot read the registry (the CLI against a remote server), text that reads both as a graph IRI and as another ledger's address is that ledger.The connection route (
POST /query,query_from()) has no target ledger, so there an address names a ledger (and its graph). A keyword, or an IRI that cannot be a ledger address (http://ex.org/g), is a 400 that says to name the ledger, instead of a nameservice lookup of the IRI as a ledger id. An IRI that can also be read as an address (urn:g1,ex:g) is still looked up as a ledger there, and is a 404 when there is none.A
FROM NAMEDmember is named by its IRI as written, pin included:FROM NAMED <L@t:2>answersGRAPH <L@t:2>,GRAPH ?gbindsL@t:2, and two pins of one ledger are two members. The time-stripped name (GRAPH <L>) still matches while exactly one member claims it; it is not enumerated byGRAPH ?g.Graph positions
Every graph position of a ledger reads the ledger's own address one way, for reads and writes alike:
GRAPH <iri>in a query or in an update'sWHERE, an update template'sGRAPH <iri>, anINSERT DATA/DELETE DATAquad, a TriG block in a transaction or a bulk import,WITH, and the JSON-LD forms (top-levelgraph, a node's@graph,["graph", …]). One table influree-db-core(TargetLedger::graph_position) answers:mydb:main)urn:defaultWITH <urn:default>and a JSON-LD top-level"graph": "urn:default", which write the default graphmydb:main#config,mydb#txn-metaurn:fluree:IRI)#txn-metawrite is refusedmydb:main#http://ex.org/ghttp://ex.org/ghttp://ex.org/gNo write registers a graph under the ledger's own address. The address with a time names no graph in these positions, and the reserved graphs keep the IRIs they are registered under. A
GRAPH ?gtemplate writes the graph its binding names in this table, which is the graph theWHEREread.GRAPH ?glists a graph only under a name that reads it back. Every resolution is one borrowed registry lookup; only an IRI that starts with the ledger's name is parsed as an address.What changes, on ledger
mydb:main:GRAPH <mydb:main>(any spelling)GRAPH ?gdid not listGRAPH <mydb:main#http://ex.org/g>(and the quad, TriG and import forms)mydb:main#http://ex.org/ghttp://ex.org/g, the graphFROM <mydb:main#http://ex.org/g>readsINSERT { GRAPH ?g {…} } USING NAMED <mydb:main> WHERE { GRAPH ?g {…} }?gbound tourn:fluree:mydb:mainby an update's top-levelvalues, thenGRAPH ?gurn:fluree:IRIGRAPH <urn:fluree:mydb:main>GRAPH <mydb:main>in an update'sWHEREwith noUSINGmydb:main, if anyGRAPH <urn:fluree:mydb:main>orGRAPH <mydb>in a query (GRAPH <mydb:main>already read the default graph)GRAPH ?gover a graph registered under the address by an earlier versionmydb:mainin an update'sWHEREmydb:main#mydb:mainby both, a name that reads it backGRAPH <mydb:main@t:1>, or toGRAPH <mydb:main#mydb:main>when no such graph existsCOPY/MOVE/ADD … TO <mydb:main>with no graph registered thereDEFAULTCLEAR/DROP/ADD/COPY/MOVEnamingGRAPH <mydb:main#<g>><g>;DROP GRAPH <mydb:main>still names the graph registered under the address, never the default graphCREATE GRAPH <mydb:main>mydb:mainGRAPH <mydb:main#config>or<mydb#txn-meta>, in any form#txn-meta, as for theurn:fluree:names"graph": "mydb:main"(top-level,["graph", …]or a node's@graph) with nomydbprefix defined"from": "mydb:main"already read; a name that is no address of the ledger being written is still that 400A graph an earlier version registered under the address keeps its data. It is reached as
<mydb:main#mydb:main>(one undermydb:main#configas<mydb:main#mydb:main#config>) in every position above and by the graph-management verbs, which also reach it by the address alone. To move it into the default graph:ADD GRAPH <mydb:main> TO DEFAULT ; DROP GRAPH <mydb:main>. The contract is written once, indocs/concepts/datasets-and-named-graphs.md("The ledger's own address in a graph position"), and the SPARQL and JSON-LD update pages point to it.JSON-LD update templates take no graph variable, so the
GRAPH ?gtemplate shapes have no JSON-LD twin; every fixed-graph shape has one.Status codes
FROMerr:db/GraphNotFound(new@type)#), in either spellingfromon a ledger route ([]or"")FROMmember on a view (one view is one snapshot)query_from()SERVICEto a ledger that is not a dataset memberSILENTSERVICEto a ledger the dataset holds at more than one timeSILENTerr:system/NameServiceErrorL#Lwith no such graph, or a graph-management destination at the addressPer surface
/query/{L},/stream/query/{L},/explain/{L}, /query/{ledger} parses the path ledger once but authorizes, loads and compares its raw spelling #1982): the path is parsed once into the canonical id, and auth, loading and every comparison read that id./query/urn:fluree:L:mainloads, and/query/LwithFROM <L:main>(or the reverse) is no longer a mismatch. EachFROM/FROM NAMEDand JSON-LDfrom/fromNamedresolves through the table with the ledger's graph registry: an IRI containing#or@is a graph, not ledger syntax; the short alias and the URN of the path's own ledger name it; a graph IRI infromNamedis a graph. A single JSON-LDfrom, a string or a source object (by@idorid, as the parser reads it), must name the path's ledger in some spelling (L,urn:fluree:L:main), or it is a 400 "Ledger mismatch"; afromarray andfromNamedmay still name other ledgers, as before. The JSON-LD dataset is read where the engine's parser reads it (optsbefore the top level,frombeforeledger,fromNamedbeforefrom-named), so anopts.fromnaming another ledger is a 400 however the top level reads, and anoptsdataset takes the lane its top-level twin takes (it used to be ignored:{"opts": {"from": "L@t:1"}}answered at head). The read check on the path's ledger runs before the body's dataset is resolved in that ledger, on every ledger route, and so does the wait for the request'sFluree-Min-T, which is the path ledger's. A proxy-storage peer resolves against the registry as well./explain/{L}accepts the within-ledger graph IRIs/query/{L}accepts (partly: see Deviations).POST /query): the ledger a JSON-LD body's view reads, and the ledger its request is labeled and authorized by, are read with the same precedence, so{"from": "a:main", "opts": {"from": "b:main"}}runs onb:main, which the parser reads, and{"opts": {"from": "a:main"}}runs ona:main(it failed with a missing ledger).graph()anddb()(graph() does not accept #graph fragments or urn:fluree: ids that db() accepts #1961):graph()takes every addressdb()takes (L#txn-meta,L#<graph IRI>,urn:fluree:L,L@t:5). A pin in the address is honored by both; one that disagrees withgraph_at's is a 400..transact()through a graph-qualified or pinned handle is a 400, since a transaction applies to the whole ledger at head.query_from(), which reads them. The connection path's one-ledger shortcut and a one-ledger dataset hand the view a dataset it already holds, and are not refused. SPARQLFROM <L#config>,FROM <L#iri>,FROM <L>and keywords resolve on the view (Config Graph query doesn't work with SPARQL #1512).# PRAGMA union-default-graph,f:queryDefaults): the union reads exactly the graphsGRAPH ?glists, as native ledger graphs.SERVICE <fluree:ledger:X>: X must be a dataset member, or, with no dataset, the query's own ledger. Anything else is a 400 that points atFROM NAMED, and contributes no rows underSILENT. An endpoint is never loaded on the spot.urn:fluree:spellings work; a pin or a graph in an endpoint is malformed. X is read at one time: a dataset holding X at two times (two pins are two members) is refused the same way, and with one time the member read is fixed (the default graph, else the first named member by name) instead of whichever a hash map yielded first.USING,USING NAMED,WITHand the JSON-LD update keysfrom,fromNamedandgraphresolve in the transaction's ledger through the same table. The ledger's own address names its default graph, in the single and the multi-USINGbranch alike;L#confignames the config graph; a registered IRI names its graph; a graph the ledger does not have contributes nothing, soDELETE … USING <typo> WHERE …deletes nothing (it used to read the real default graph), and that includes an IRI that also reads as another ledger's address (urn:g1). An address that can only name another ledger, or a pinned address, is a 400. JSON-LD"from": "L:main"is accepted (it was an undefined-prefix error), and so is"graph": "L:main"for the ledger being written. fix: unresolvable graph references fail closed, and TriG directives apply in document order #1997's check for the ledger's own address and resolution step 0 are one predicate now (LedgerRef::is_own_address), soL#defaultreads the same in both. A top-levelvaluesIRI reads in theWHEREas its IRI, whichever namespace it is in. The graph positions are above.L#<g>into<g>, through the same table.R2rmlProvider::has_r2rml_mappingreturns aResult, and a failed lookup fails the query instead of reading as an empty native graph. Graphs loaded as ledger graphs (the primary, native dataset members, and union members) are never probed, so a query over native data does not depend on the graph-source registry being reachable. A failed nameservice lookup at any graph-source site (the probe, and the mapping, table and SQL-source lookups) is a newQueryError::Nameservice, which the API and the server answer with 500err:system/NameServiceError, the typeApiError::NameServicealready has: it is the backend's fault, so clients may retry it and monitoring does not count it as a bad request.fluree query: afromnaming the target ledger's own named graph or#txn-metais silently ignored #1972):fluree querydecides between the target's view and the connection path by resolving the dataset in the target ledger, not by comparing base names. JSON-LD bodies go through the same API function the server uses (see Public Rust API), with the parser's key precedence. A JSON-LDfromnaming one of the ledger's graphs (by keyword, registered IRI or address, in string or object form), its#txn-meta, or another branch now reads what it names, and one naming a missing ledger reports it missing: the body reaches the connection path with each graph of the ledger rewritten as{"@id": <ledger>, "graph": <g>}.fluree query --remote … --atposts the query as written to the pinned path (/query/{L}@t:N, available since v4.2.2): aGRAPHwith no dataset clause reads the ledger's named graph at that time, a JSON-LDfromnaming a graph is kept (it was overwritten), and a SPARQL query with its ownFROMis accepted (it was refused). A server older than v4.2.2 refuses the pinned path; on that reply only, the CLI falls back to the old rewrite (see Deviations). Locally,--atwith a JSON-LDfromnaming a graph of the ledger is now a usage error ("--atis not supported on the connection/federated query path"); it used to read the wrong graph without a word. A local query that stays on the ledger reads the head its route was chosen on. With--remote, the CLI holds no registry, so text that reads both as a graph IRI and as another ledger's address goes to the connection path, as onmain.QueryResult::advisoriesnow carries a typedQueryAdvisory::EmptyDefaultGraphwhen the query reads that default graph, computed once from the lowered query for both languages, including patterns insideEXISTS/NOT EXISTS. The CLI prints it to stderr; rows are unchanged. The HTTPx-fdb-warningheader keeps its route-level walkers for now.Multi-query envelopes
An envelope resolves one
tper ledger at entry. Each sub-query now runs as written, and every ledger it reads is read at the snapshot:t, once it has parsed the dataset as it does for any query. The envelope no longer rewrites a sub-query's text orfromvalue. A member keeps the name the query wrote it by, soGRAPH ?goverFROM NAMED <L>bindsLin an envelope, as it does outside one. Every spelling reads at the snapshot: a prefix the query or the envelope's@contextdeclares,BASEor the envelope's@base,urn:fluree:, a\uescape.asOfrules and the server'smin-t: a SPARQL sub-query is read from the text the dispatcher runs (its own, with the envelope's@contextprefixes and@baseapplied), and a JSON-LD sub-query from the body it runs, itsoptsmerged from the envelope's, the sub-query's and its own, the body's winning (effective_jsonld_body). A ledger named infromNamed/from-namedor inoptsat any layer is counted, resolved at entry, listed insnapshot.ledgersand covered bymin-t, as one named infromwas. A member is keyed by the ledger it names, sourn:fluree:mydbandmydb:mainare one ledger (aurn:fluree:SPARQL member with noasOfused to fail the envelope with a 500). A missing ledger named anywhere fails the envelope with its 404, as a missingfromledger did.optsmay add to a sub-query's dataset, but not change a part the body names. When the body names its default graphs, its named graphs or a history end, and the envelope's or the sub-query'soptswould make it read a different one, the envelope is a 400 (DatasetConflict). Outeroptsthat repeat the body's value (the parts are compared as written, so the same ledger in another spelling counts as a change), add named graphs the body doesn't name, or name no dataset at all (identity, policy, tracking), compose as before. A body must still name its ownfrom.asOf, a member that names its own time, wherever it is named, collides. The parser's reading decides: atthat is not an integer, or anatthat is not a string, names no time, so that member reads at theasOf. Atoanywhere is a history query, refused. A dataset the parser cannot read refuses the envelope with the parser's message. A sub-query that does not parse, in either language, reads nothing and is reported under its alias while its siblings run, as on fix(server): query routes read a request's dataset the way the engine does #2019; that includes a parse error the parser recovers from.Public Rust API
The typed references change a few public shapes, so embedders will notice:
LedgerRef's fields become private typed accessors,GraphSource's parsed fields become accessors (GraphSource::parse/TryFrom<&str>/FromStrreplacenew/from_str),HistoryTimeRangetakes aLedgerId,R2rmlProvider::has_r2rml_mappingreturns aResult,ApiError::GraphNotFound,QueryError::Nameserviceand twoMultiQueryValidationErrorvariants are new on enums that aren't#[non_exhaustive], twopubmulti-query snapshot functions are removed,DataSetDbgains a pub field that a struct literal needs, andTxnloses #1997'stemplate_default_graph.TargetLedger::newtakes a&dyn GraphNameTable, which closures andGraphRegistryimplement. The embedder surface on the hard keep list is pinned by a compile test (the_embedder_surface_on_the_hard_keep_list_still_compiles). The full list:Every public API change, and what's kept source-compatible
Changed:
fluree-db-core: new moduledataset_refwithGraphIri,GraphSel,LedgerRef,DatasetRef,MemberRef,TargetLedger,TargetGraph,TargetError,GraphPosition.LedgerRefreplaces the raw-string struct of the same name (pubid,at: Option<String>,fragment: Option<String>,time_spec()): its fields are private and typed (id(),at(),graph(),is_bare(),is_own_address(),with_at,with_graph,into_parts).TargetLedgerresolves dataset positions (resolve,graph) and graph positions (graph_position,enumeration_name, which returnsNonefor a graph no name reads back,names_this_ledger).GraphSel::keywordreadsurn:defaultasdefault; with fix: JSON-LD graph scoping, config integrity and explicit-only SHACL #2009 merged, that is a change to fix: JSON-LD graph scoping, config integrity and explicit-only SHACL #2009'sGraphSel::keyword, whose table is nowGraphSel::bare_keyword.TimeSpecandACCEPTED_TIME_SPEC_SPELLINGSmove here fromfluree-db-api, re-exported at both old paths,From<LedgerIdTimeSpec>included.LedgerId::parserefuses a branch beginning with/.fluree-db-core, this round:TargetLedger::new(id, &dyn GraphNameTable)(GraphNameTableis new;GraphRegistryand anyFn(&str) -> Option<GraphId>implement it),AddressText(the address lexer),DatasetRef::is_address_with_branch_or_time.fluree-db-binary-index:HeadGraphNames.fluree-db-api:GraphNames::table,Fluree::db_with_default_context_from_handle,Fluree::db_at_with_default_context_from_handle. With the merge:GraphSel::bare_keyword; influree-db-transact,AddressNameand aGraphName::Addressvariant (fix: JSON-LD graph scoping, config integrity and explicit-only SHACL #2009's enum, which no release carried).fluree-db-api::GraphSourcekeepspub identifier: Stringandpub policy_override. The pub fieldstime_spec,source_aliasandgraph_selectorbecome accessors (time_spec(),alias(),reference(),address(),written());GraphSource::new/from_str/with_graphbecomeGraphSource::parse/TryFrom<&str>/FromStr/GraphSource::ledger(LedgerRef).with_time,with_alias,with_policyare unchanged.dataset::GraphSelectoris an alias ofGraphSel(Iri(String)becomesNamed(GraphIri), plusConfig). Its constructorsdefault_graph(),txn_meta(),config(),iri()andfrom_str()are removed: use the variants (GraphSel::Default,TxnMeta,Config,Named(GraphIri::parse(..)?)) orGraphSel::parse.ledger_info::GraphSelectoris a different type and is untouched.DatasetSpec::from_sparql_clause(&SparqlDatasetClause)becomesfrom_sparql(&ResolvedDatasetClause)/from_sparql_ast(&SparqlAst). New:DatasetSpec::sources(),ledgers().HistoryTimeRange { identifier: String, … }becomes{ ledger: LedgerId, … }, and so doesHistoryTimeRange::new.fluree-db-api: moduletarget_dataset, re-exported at the root, the one reader of a JSON-LD dataset in the ledger a surface targets:resolve_jsonld_dataset_in_target(rewrites the body so each source names what the target reads for it, and reports the lane),resolve_in_target,jsonld_lane,jsonld_view_ledger,jsonld_dataset_ledger,jsonld_names_dataset,InTarget,JsonLdLane,JsonLdInTarget,SingleFrom,GraphLookup;LedgerView::graph_id_for_iri(a borrowed lookup into the cached head),LedgerHandle::graph_namesandGraphNames(that lookup alone),Fluree::ledger_handle(a cached handle by a parsed id);sparql_dataset_ledgers(the typed ids the connection path loads),sparql_has_dataset_clause,QueryAdvisory,QueryResult::advisories(additive),execute_formatted_with_advisories,ApiError::GraphNotFound(ApiErroris not#[non_exhaustive], so an exhaustive match needs the arm),DataSetDb::named_aliases(a pub field, so a struct literal ofDataSetDbneeds it) andwith_named_alias. Re-exported:resolve_dataset_clause,ResolvedDatasetClause.fluree-db-api::query::multi:snapshot::apply_snapshot_to_jsonldandsnapshot::apply_snapshot_to_sparql, which arepubonmain. The envelope no longer rewrites sub-queries; nothing in db or solo calls them.MultiQueryValidationError::JsonLdDatasetUnreadableandMultiQueryValidationError::DatasetConflict(the enum is not#[non_exhaustive], so an exhaustive match needs the arms);alias_optsandeffective_jsonld_body, the merge the dispatcher runs, for a host that merges the layers itself before dispatch.EnvelopeLedgers::sparqlbecomesmembers, every alias's members (JSON-LD aliases included), andSubqueryLedgerdescribes a member of either language;DatasetSpec::default_graph_sourcesis removed (the ledger route reads afromobject throughdataset::source_object_id, the parser's own accessor).QueryExecutionOptionsgains a crate-internal field; it already had private fields, so no struct literal changes.Fluree::is_single_ledger_fast_path(test-only callers).fluree-db-query:R2rmlProvider::has_r2rml_mappingreturnsResult<bool>, so implementors must change (the three in-tree ones and the test doubles did). New variantQueryError::Nameservice(String):QueryErroris not#[non_exhaustive], so an exhaustive match needs the arm. NewMemberKindonGraphRef::kind(a pub field) andContextConfig::primary_kind/ExecutionContext::primary_kind, plusExecutionContext::graph_is_native,DataSet::service_memberandDataSet::with_name_resolver(GraphNameResolver).fluree-db-transact:WriteGraph,GraphTableandFlakeGenerator::set_graph_table. fix: unresolvable graph references fail closed, and TriG directives apply in document order #1997'sTxn::template_default_graph,TripleTemplate::graph_from_template_defaultandTripleTemplate::in_template_default_graphare removed: that case is a row of the table. v4.2.4 and v5.0.0-alpha.1 carry them, so a struct literal ofTxnorTripleTemplate, or a caller ofin_template_default_graph, needs the change (in_graphreplaces it). fix: JSON-LD graph scoping, config integrity and explicit-only SHACL #2009'sGraphScope::as_template_defaultgoes with them; no release carried it.fluree-vocab:errors::GRAPH_NOT_FOUND.Kept source-compatible, and pinned by a compile test (
the_embedder_surface_on_the_hard_keep_list_still_compiles):MultiQueryRequest { context, as_of, opts, queries }andMultiQuerySubquery { language, query, opts }as struct literals; theAgentJsonContextfields;fluree_db_api::dataset::GovernanceOptions;fluree_db_core::validate_branch_name;ledger_info::GraphSelector::ByIri;build_stream_dataset,build_stream_dataset_for_sparql,plan_stream_query_dataset,run_stream_query_dataset,OwnedStreamQuery,run_stream_query;fluree_db_sparql::resolve_dataset_clauseandResolvedDatasetClause { default_graphs, named_graphs, to_graph };fluree_db_core::split_time_travel_suffix;TimeSpec::from(LedgerIdTimeSpec);DatasetSpec::from_query_json,GraphSource::identifier/policy_override, andsparql_dataset_ledger_ids.Commits
42 commits on #2019's head,
b061c5fcd; then the merge ofmainc5874d586(85183e83f),079ccf338(the test above), the merges ofmainba694ee79(a0050eb49),58b53238a(1fbb44a4b),ba4a982ec(6ad964919),f3c3b00ec(03e4b43ed) and04e1a6d37(86cd7e2c2), this round's six (43–48), the merge ofmain1d06ae2ef(893521fb1), 49 and 50, the merge ofmaind9a1d2004(06190d23c), 51 and 52, and the merge ofmain4a0d14a1a(d68a3e871):The commit list
d53cad067bench: dataset_http and dataset_buildd589d8cd0core: typed dataset and graph references883df44a6api: typed dataset members, one resolver for a target ledgerd766b7e3bquery/api: graph-source probes fail closed; ledger graphs are never probed7427ebc18api: graph() and db() take any ledger address; a view refuses another ledger's from33e115175query: a SERVICE endpoint names a dataset member or the query's own ledgercbb87f92atransact: an update's WHERE dataset resolves in the transaction's ledgerfe94a9a50server: the ledger routes resolve dataset references in the path's ledger276ddf1aacli: route a query after resolving its dataset in the target ledger62086ae3eapi: keep the dataset parsers' public shape for callers that authorizee6a844148api/cli: typed query advisories on the result975c26648cli:--remote --atpins the ledger pathe5a29b7d7core: one home for the unknown-@-tag rule (an unknown@tag in a dataset position)b2c46ecf6test: the filed reproductions, solo's dataset shapes, and the embedder surface73d2f4f3fdocs: dataset references, SERVICE membership, update datasets, CLI --ate9130e24aapi: resolve a JSON-LD dataset in the ledger a surface targets703517ff0api: a view answers a JSON-LD query only for its own ledger, wholeb2dda77bbquery/api/server: a nameservice lookup that fails inside a query is a 500f1ae4a0daapi: report every dataset address as name[:branch], whatever its spellingb6f6b1a1fcore/query: a malformed URN address is its own error; SERVICE reads one time98be3ab30core/query/transact: every graph position reads the ledger's address one waycc5743ffddocs: the ledger's own address in a graph position2ed4afdcecore/transact: the address with a reserved keyword names that reserved graph2a521d507transact: graph management readsL#<g>as the graph<g>574271e90server/api: resolve a ledger route's dataset with its path id as parsed5ea64f7f0api/server/cli: resolve dataset references against the head's graph names5c43aa3b6api: keep a dataset member's text onceb2d0323cfcore/query/transact: read graph positions and resolve members without copying IRIs41528efe1core/query/transact: read urn:default through the keyword tableab12941aaapi: the union default graph reads the graphs GRAPH ?g lists, as ledger graphs055f2c15dtest: retire the exact-match alias spelling test64f969fe6docs: urn:default in the graph-position table, and the union's graphsb55d4ed5eserver: test the ledger route's JSON-LD dataset shapes on both paths3bb24d276api: read a source object's id as the dataset parser does931873eb5transact: a top-level values cell the WHERE cannot decode carries its IRIa209d96aatest/docs: urn:default in a query dataset, on both surfaces80df644dcserver: ledger routes check read access before resolving the datasetbb4d81ab9api/server: a multi-query envelope runs each sub-query as written, at its snapshote58ac72bfapi/server: an envelope validates a JSON-LD sub-query as the body it runs6da68a115api: an envelope's ledger times come from its snapshot or fail the envelope01b105f46multi-query: test a recovered parse error, andfromNamedin every layer32d0c9ef9docs/test: a ledger route reads afromstring as it reads an objectba06dd75ccore: one graph-name table and one address lexerd6bbda4b5transact: a USING IRI the ledger has no graph for contributes nothinga82e3953bsparql: BASE leaves a ledger address with a branch or time as written42c41706fapi/cli: with no registry, an ambiguous reference names another ledger7adc15fd8server: a ledger route waits for its ledger's min-t, then reads its registry7db0c3aabapi/cli: a local query reads the head its route was chosen onaa60ba924api/cli/transact: graph keywords and addresses through the one tablece0a70771transact: a JSON-LD graph named by this ledger's address is that address1040a04cbtest: another ledger's address in a JSON-LD graph is the parser's undefined-prefix error82e2b054ctest: every JSON-LD graph name the address reading admits or refusesCommits 1–28 are the posted ones, rebased onto
2941d470cand then onto #2019.Tests
New integration tests cover each surface — the API's dataset and graph-handle suites,
SERVICE, the update-dataset matrix, graph positions, graph management and bulk import, the address with a reserved keyword (L#config,L#txn-meta), the graph-source probes against real SQL sources, the server's ledger routes, multi-query envelopes, and the CLI's routing (including #1972 and #1512 reproduced from the issues verbatim) — each with its SPARQL and JSON-LD twin where the surface has both, plus unit tests for the grammar, the classifier and both resolution tables. Existing tests whose expectation changed on purpose (two of #1997's and the server's policy regression test among them) are listed in the fold, each with why.Each new regression test was also run against its fix reverted, and every revert turned its test red, on an assertion (tests that pin behavior
mainalready has are marked; they have nothing to revert). The full mutation log, and every new test by name, are in the comments below: they'd push this description past GitHub's size limit.The existing tests whose expectation changed on purpose, and this round's revert runs
This round's new tests, each red with its fix reverted except
address_text_splits_where_the_parser_does(it pins a refactor), are listed by name in the comment below, with every earlier round's.Existing tests whose expectation changed on purpose this round:
update_where_dataset_references_resolve_in_the_transactions_ledgerrefusedUSING <w-other-ledger:main>; that text is also a graph IRI the ledger lacks, so it now matches nothing, and the refusal rows name<w-other-ledger>, which can only be a ledger.remote_routing_sends_only_another_ledger_to_the_connectionkeptFROM NAMED <urn:x>on the remote ledger route; with no registry it now goes to/query, as onmain, and the test keeps<mydb:main#urn:x>on the route.test_writes_through_the_ledger_address_name_the_default_graphmatched staging's wording for another ledger's address as a JSON-LD graph ("does not define"); that name is now refused at parse with the parser's undefined-prefix error, as onmain.Earlier rounds' (#1997's two among them, the server's policy regression test, the retired alias-spelling test and the multi-query unit tests) are in the comment below, each with why.
This round's revert runs each reverted one fix, restored the file and checked it byte-for-byte: nine at
7db0c3aab(the review's items), and eight at the head on the merges' own code (the address reading of a JSON-LD graph name in four ways, the reifier anchor in two, the top-levelurn:default, and the written-name keyword table). Every one turned its tests red, on an assertion; both logs are in the comment below.The refactors (one parse per source, the shared lookup, the lexer) change no behavior, so there is no fix to revert; the existing suites cover them.
Gates
At the head,
d68a3e871(main4a0d14a1amerged in), run locally with--all-features. fmt is clean.cargo check --workspace --all-targetsis clean after each merge. Clippy-D warnings(--all-targets --no-deps) is clean over 19 crates: core, binary-index, query, sparql, transact, api, server, cli, reasoner, consensus, indexer, novelty, iceberg, r2rml, doc, graph-json-ld, graphql, vocab and shacl.Tests pass: fluree-db-core 1,071; binary-index's lib 428; sparql 696; query's lib 1,736; transact 452; server 781; cli 485; api 5,244 of 5,245, every target, #2109's eight multi-op matrix tests included; and the W3C SPARQL suite, 36 of 36 groups. The one api failure is a span-capture lane stamp (
jsonld_join_takes_batched_subject_probe_like_sparql) that fails under parallel load onmaintoo and passes alone. With the bare-nameBASErule applied instead, the W3C suite's 12dawg-datasettests fail.Not run: fluree-db-query's integration tests and binary-index's beyond its lib; the wasm32 lints and runtime smoke; the no-optional-features server check; and the benchmarks. Per commit, 44, 45, 47, 48 and 51 were not checked on their own.
Performance
The connection path gets faster, and no case regresses. On a shared dev box (
cargo bench --profile dev-fast,dataset_httpanddataset_build, before and after in two passes),dataset_build'squery/*cases are 3.4–9.3× faster, growing with the member count (query/cross/161.315 → 0.157 ms), which matches what commit 4 (d766b7e3b) removed: the executor no longer asks the graph-source registry about native members. Over HTTP the connection-route cases are 18–50% faster, and the ledger-route and single-ledger stream cases sit within that box's noise.Quiet box. On EC2 (c7i.4xlarge, fat LTO, base and head in interleaved rounds; a change counts only when the ranges don't overlap and the median moves past the bench's 5% budget): seven wins, no loss.
dataset_build's 16-memberqueryandquery_r2rmlcases are 91–96% faster (2.2–5.3 ms → about 190 µs), the connection-routea_conn/b_conn45% and 80%, and the 16-member streams543%. The 10,000-graph ledger route (w1) read +11–20% there, which that box's timing can't resolve; by instruction count it's flat, with nothing that grows with the registry.Per request. Commits 25–28 resolve a route's dataset with the path's id as parsed and borrow IRIs: per w1 request, 652 allocations (base 657) and −0.6% instructions; w2 432 (472) and −31%. With the borrowed lookup,
/query/big:main(20,000 graphs) withFROM+FROM NAMEDis 3.56 ms CPU against base's 3.62, and the stream route 3.58 against 3.66.This round, the CLI's route. A local
fluree querythat names a dataset loaded the ledger to choose its route and again to run (the CLI buildsFlureewith no ledger cache); it now runs on the head it routed on.dev-fastbinaries at7adc15fd8and7db0c3aab, interleaved, on a 302-commit unindexed ledger (a shared box at load 13–17, medians of 15 rounds):FROM <bench:main>31.5 → 21.1 ms,FROM NAMED <g>34.4 → 22.1 ms, JSON-LD"from": "bench:main"32.7 → 21.4 ms, against a no-dataset control at 20.8 → 21.6 ms; with--at, 28.8 → 19.1 ms at the head and 39.2 → 29.5 ms att:150. Answers are byte-identical. The ledger routes' new min-t wait is an empty map without a min-t, and the refresh fast path when the head is already there; a JSON-LD source is parsed once instead of three times.Solo
Solo itself was not built against this branch. What reaches solo's call sites:
DatasetSpec::from_query_json(each member'sidentifier, andpolicy_override) andsparql_dataset_ledger_ids; both keep their signatures and fields. An identifier is reported asname[:branch]whatever its spelling: an address'surn:fluree:wrapper and@pin are removed and its#graphkept, a bare name stays bare, and anything that is not an address is reported as written. Aurn:fluree:spelling used to keep its wrapper, so solo's extractor tests that pin a raw URN string need that update.sparql_dataset_ledger_idsreports every member's identifier (without#graph) and the history range's ledger, after expanding a dataset IRI against the prologue.validate_envelope_ledgersreturns each sub-query's ledgers as the envelope reads them: a SPARQL sub-query's from its text with the envelope@contextapplied, a JSON-LD sub-query's from its body with the envelope's and the sub-query'soptsmerged (effective_jsonld_body), asdistinctand asmembersper sub-query. Solo's own envelopes name their dataset in each body'sfrom, with noopts, and are unaffected by the new refusal.asOfcollision now reads "a source names its own time for ''"; a JSON-LDfromobject that names no source is refused with the parser's message (JsonLdDatasetUnreadable) rather thanMissingFrom;{"from": ""}is a parse error, so solo's extractor answers "Could not read the query's dataset" for it before its own "requires a FROM clause" check. Solo builds no such body itself.QueryError::Nameservice: a new variant, so an exhaustivematchonQueryErrordownstream needs an arm. A nameservice failure inside a query is now a 500 where some were a 400. (Solo'sApiErrormatches have wildcard arms, and solo implements noR2rmlProvider.)urn:fluree:…#…, on a real branch, on the view and throughquery_from()(a_branch_reads_config_by_the_main_urn_and_urn_named_graphs_stay_graphs);FROM NAMED <L@t:N>+GRAPH <L>through the compatible alias (pinned_from_named_members_are_named_as_written); "not found" fromledger_cached,ledger_infoandrefresh(a_missing_ledger_reads_as_not_found_at_every_entry_point); a non-memberSERVICEendpoint refused and never loaded (a_service_endpoint_is_never_loaded); and solo's JSON-LD dataset shapes throughquery_from()(solo_jsonld_dataset_shapes_still_answer:{"@id": L, "t": 1, "graph": "txn-meta"}, the same with"at", a user graph,"L","L:main", afrom/torange). Solo's own extractor, run on its test inputs and a 93-case corpus, passes its own tests; againstmain, 16 of the 93 answers differ, each one of the changes above.FROM <L>query answering the same rows with fast paths on and off, the injectedFROM <L>/FROM <L@t:N>/FROM <L:main@iso:…>spellings answering under the whole-ledgerFROMconvention, and the embedder stream path answering the same rows as buffered.main74d5404b6, and again at1f196da7e6, whose two newer commits touch only lockfiles): solo calls none of the changed signatures and runs neither the server's ledger routes nor the CLI. What reaches it is theBASErule, which makes an address with a branch or a time inFROMthat address insparql_dataset_ledger_ids(its cross-ledger extractor) and inresolve_dataset_clause, as the engine reads it, and theurn:defaultorder. Solo writes config only on:mainand issues noUSING. The merge with fix: JSON-LD graph scoping, config integrity and explicit-only SHACL #2009 doesn't reach solo either: solo uses nofluree-db-transacttype, andledger_info::GraphSelector::ByIri, which its profile op uses, is unchanged. Nothing for solo to change.resolve_dataset_clause,ResolvedDatasetClause,split_time_travel_suffixandTimeSpec::from(LedgerIdTimeSpec); all four are unchanged (pinned by the compile test).Overlap with #2009
#2009 fixes the class
931873eb5belongs to at the write boundary: two of its commits, "flake generation stores every IRI under its canonical namespace code" and "an update's where reads top-level values in the ledger's encoding". #2009 landed first, so the merge (893521fb1) drops931873eb5's code and keeps its two tests,an_update_reads_a_graph_variable_bound_to_the_ledger_addressanda_top_level_values_iri_in_a_new_namespace_writes_and_reads_as_itself, which pass on #2009's mechanism. The rest of the overlap, the two graph-name modules, is under "Merged with #2009".Persisted data
Nothing persisted changes format: no commit, index, nameservice-record, graph-registry or content-hash format changes, and stored ledger ids are read by
LedgerId::parse_persisted, unchanged. What changes is where new writes land and how names resolve (a write through the ledger's own address names the default graph instead of registering a graph under the address). The code reads data written by earlier versions without a migration, except for one shape: a branch whose name begins with/(creatable from v4.0.0 through v4.2.1) is not addressable; its data is intact. Export it with v4.2.3 before upgrading (fluree export L:/branch; v4.2.3'sbranch dropdoes not remove such a branch). A graph an earlier version registered under the ledger's address is listed asL#<address>and reached by that name, and a graph named throughL#configlikewise. A graph registered literally asurn:defaultbefore #2005 is not listed, as onmain.Deviations from the design
x-fdb-warningheader is still computed by the two route-level walkers;QueryResult::advisoriesis not yet what renders it, and the MCP envelope does not render advisories./explain/{L}accepts within-ledger graph IRIs through the typed ids and plans on the ledger view; a dataset's explain still plans the single view.ledger_info()andledger_cached()still parse their argument withLedgerId::parse, so aurn:fluree:id is refused there ("branch cannot contain ':'"). The design moves them ontoLedgerRef::parse; that waits for a follow-up PR (part 2). Their "not found" text is unchanged.@. Run against the v4.1.6 and v4.2.1 binaries, both answer a 500, "Invalid ledger ID format '@t:N': expected 'name' or 'name:branch'". The CLI falls back on an "invalid ledger id" reply that names the pinned path, at any of 400/404/500, and on nothing else.--remote --atkeep the old rewrite; they move to pinned paths in the follow-up PR (part 2)./queryrequest still parses its dataset more than once (auth, refresh and min-t collection each read it); the design's one parse per request waits for the walkers below.optsfor authorization, not after: the conflict refusal needs the layers apart. Validation reads each body with its outeroptsmerged (effective_jsonld_body), so the route'smin-twait and refresh, which run on validation's ledgers, cover a ledger the outeroptsadd, and a body whose dataset they would change is refused before either. The merge the route then stores in each body is the same function's output, the body the dispatcher runs.from. A dataset named only in the envelope's or the sub-query'soptsstays refused (MissingFrom), as onmain.BASE, a bare ledger name in a SPARQL dataset clause (FROM <mydb>) isBASE-resolved, as SPARQL specifies and the W3C dataset tests require;mainread it as written. An address with a branch or a time is still read as written.Pre-existing, not changed here
FROM NAMEDmember sometimes fails with a 400 FormatError: every time withAccept: application/json, and about one run in three in other formats, solo's pinnedFROM NAMEDshapes included. It reproduces onmainand on this branch alike, and is to be filed separately.Not in this PR: lane consolidation, in a follow-up PR (part 2)
FROMconvention (docs: the "Ledger-Bound Mode" example (FROM <mydb:main>+GRAPH <g>) returns no rows #1975): a clause that is exactly oneFROMnaming a whole ledger selects the ledger with its named graphs./stream/query/{L}@pin, the CLI's NDJSON--at(local and remote) and TSV/CSV--remote --aton pinned paths.from/fromNamedon the view path resolved as within-ledger datasets (this PR refuses them there).QueryResult::advisories.refreshable_ledger_id,refreshable_ledger_id_and_t,collect_refreshable_jsonld_ledgers,collect_jsonld_min_t_requirements, andcollect_sparql_min_t_requirementswithiri_to_string): they skip any text that starts withurn:or contains://, read JSON-LDfrom/fromNamedat the top level only (notopts, notledger), and do not expand a SPARQL prefixed name. A ledger named in any of those ways is not refreshed before the query, and its@t:pin sets no min-t requirement. (The multi-query route reads its sub-queries' members from validation instead.)needs_default_graph_injectionreads only the top-levelfrom/fromNamed/from-named,jsonld_dataset_semantics_warning_headerslikewise, and the SPARQL twin of the warning does not look insideEXISTS. So thex-fdb-warningheader can differ fromQueryResult::advisories, which reads the lowered query.pin_jsonld_dataset(a pinned ledger path) walks every dataset key, top level andoptsalike, where the parser reads one of each pair.load_addressrenders a parsed address back to text for the loader to parse again. It round-trips; no divergence is known.