Skip to main content

Crate datumesh_store

Crate datumesh_store 

Source
Expand description

A store for Datumesh: function descriptors, receipts, blobs, versions of cells over transaction time, lineage, namespaces and function names, on PostgreSQL or (since 0.4.0) in one SQLite file. PgStore and SqliteStore implement Store, and through it datumesh_core’s Resolver, so datumesh_core::verify can recompute receipts of stored cells from either; the two behave the same (one conformance suite runs against both).

The API is synchronous (the postgres driver and a small connection pool; rusqlite with SQLite compiled in, feature sqlite, on by default). Async callers run it on a blocking thread, e.g. tokio::task::spawn_blocking.

SqliteStore::open takes a file path (SqliteStore::connect a sqlite: URL); the file is in WAL mode, every write is one BEGIN IMMEDIATE transaction, and the append-only rules are triggers in the file, so they hold for writers in several threads and processes on one machine. Its schema comes from migrate::sqlite::apply.

PgStore::connect / PgStore::connect_with take a URL and PoolOptions; TLS (rustls) is used as the URL’s sslmode says and always verifies the server’s certificate and host name, against the Mozilla roots plus those added with PoolOptions::tls_root_certificates_pem. No type of the driver or of a TLS crate is part of the API, except in pg_unstable (any connection function, the driver itself), which is outside semver until 1.0.

What is stored, and how:

  • Descriptors are checked by the core (FunctionDescriptor::from_json: since 0.3.1, spec-0.4.0’s, with signature.order and argument extent) and stored in canonical form (JCS) under their hash. Receipts are verified (datumesh_core::verify, SPEC 10.1 steps 1-6) against the key document stored for their signer host, so nothing unverified enters the store, and are stored canonical under their hash. Storing the same thing twice stores it once. A second, different valid signature over the same payload (possible only with a randomised signer: the payload names the key, so a rotated key gives a new hash) is refused (Error::Conflict) and the stored receipt kept.
  • Blobs are stored in the database, under the SHA-256 of their content.
  • Versions: from transaction time tx on, cell cell_id has the value of a receipt. Append-only and in tx order per cell, enforced by the database (triggers) as well as by Store::put_version, which also checks that the receipt is stored and is of that cell at that tx.
  • Computed versions: from transaction time tx on, cell cell_id has the value a receipt computed, as of the receipt’s asof. Derived rather than facts, so they are added in any order, keyed on (cell, tx, asof), insert-only (Store::put_computed, Store::computed_asof).
  • Answering as of A: a receipt answers as of A only when its tx and its asof are both at or before A (Store::stored_asof, and the Resolver’s evaluate of a stored function; Store::version_asof looks at tx only).
  • Lineage: put_receipt records an edge to each of the receipt’s inputs, held or not: receipt hashes (Store::inputs, Store::dependents) and, since 0.3.1, slice entries (Store::slice_entries, Store::slice_dependents); Store::cell_dependents lifts both to cells.
  • Slices (0.3.1, SPEC 15.13): every stored receipt’s cell is indexed by its typed arguments, so that Store::slice_members finds the members of a slice as of A with a range scan, in key order; Store::versions_between gives a version slice. Store::slice_values gives the members’ values without receipts (0.3.2) and Store::slice_changed_after whether they may answer differently later. Manifests (Store::put_manifest, served by Resolver::manifest) are kept by entry and found from each member (Store::member_manifests). A receipt citing a slice can be stored before its manifest, and a manifest before its members.
  • Namespaces: a host’s key document (checked as SPEC 9.2 requires), with when it was validated. Store it before the host’s receipts. Replacing it later (a key revoked or dropped) does not touch receipts already stored: they verified when they were stored, and putting one of them again is still idempotent.
  • Names: which function hash a fully qualified function name meant from a transaction time on. Append-only, like versions. Store::resolve_binding gives the binding answering as of A with when it began; Store::resolve_name its hash.
  • Classes (0.4.1, SPEC 16.1 to 16.3): a flattened class descriptor, checked by the core and stored canonical under its class hash (Store::put_class, Store::class). A class name is bound over transaction time to a class hash, and binding it binds each method <class name>/<m> to the method’s function hash in the same transaction (Store::bind_class, Store::resolve_class, Store::resolve_class_binding). Class names and function names are one namespace: a name bound as one kind cannot be bound as the other (Error::NameTaken).
  • Owner: a class’s owner is the definer’s check (SPEC 16.2 step 1), made when the class is defined, not the store’s. The store records what it is given; the HTTP service and the engine enforce the owner rule. Store::put_class and Store::bind_class do not take a key document or check the name against the steward.
  • Namespace suspension (since 0.4.1): new writes under a suspended namespace are refused with Error::NamespaceSuspended (put_class: the steward’s namespace; bind_class: the host of the class name); reads are never refused.

Instants are compared as text (fixed width, COLLATE "C"; SQLite’s default collation is the same byte order), which is exact; on PostgreSQL each is also stored as timestamptz, which round-trips every instant of the specification exactly. Numbers in the typed-argument index compare as exact decimals (PostgreSQL numeric; on SQLite a text encoding that sorts as the decimal does).

Every Store method returns a Result: a malformed argument is Error::Invalid with the core’s code, a database failure Error::Database. The Resolver methods keep the core’s Option signatures; there a failure is logged with tracing (target datumesh_store) and answered None, which verify reports as unavailable.

Store is sealed: only this crate implements it. The store is the trust boundary: everything in it was checked on the way in (every receipt verified against its host’s key document), and its callers rely on that rather than checking again. A dyn Store is still a trait object as before.

The schema comes from migrate::apply (PostgreSQL) or migrate::sqlite::apply (SQLite) (the datumesh-store migrate command, for either), through a store on the (possibly empty) database.

Modules§

migrate
Schema migrations: plain SQL files (migrations/*.sql, embedded), applied in order with a tracking table, and a schema check that compares the live database’s catalog with the catalog the migrations produce in a scratch database.
pg_unstable
Outside semver until 1.0: this module exposes the postgres driver’s types, and any release may change it, including a patch release.

Structs§

Binding
A name binding: from transaction time tx on, a fully qualified function name means the function fn_hash (Store::bind_name). Since 0.3.0.
CatalogEntry
A catalogue entry, keyed by (kind, name).
CatalogEntryExt
A catalogue entry with its facets and its extends (CONTRACT-classes-round C2 and K9).
CellWrite
One cell write of Store::put_cells: a receipt and, optionally, the version it becomes. Since 0.4.3.
ClassBinding
A class-name binding: from transaction time tx on, a class name means the class class_hash (Store::bind_class). The class counterpart of Binding; the bindings answer of SPEC 9.7 gives class_hash in place of fn_hash for such a name. Since 0.4.1.
DatabaseError
A database failure, Error::Database: what the database said (PostgreSQL: the server’s message and SQLSTATE; SQLite: its message and result code), or the driver’s description of a failure that is not the database’s.
Dictionary
A dictionary of a Summary: the values of one key of one owner.
DictionaryValue
A value of a Dictionary.
Embedding
An embedding of an entry or a value, for one model.
FacetedEntry
A catalogue entry that has facets, as Store::catalog_entries_with_facets lists it.
FunctionTest
A function test: a canonical test line of a function, stored once per (function hash, case) (Store::put_function_test). The run fields are set by Store::record_function_test; the branch counts by Store::set_function_branches, which keeps them equal on every test of the function. Since 0.5.1.
KeyValue
One value of a dictionary: its label and aliases (the publisher’s dictionary only).
ListedHost
The state of one listed host.
Listing
One listed function: a name of another mesh, its descriptor and the subjects that mesh’s own catalogue puts it in.
MemberSet
A member-set row (CONTRACT-guard-patch G2, since 0.6.5): what a slice read saw, without its members. The entry is slice:<slice_id>:<members_hash>, as a manifest’s; slice is the slice object’s canonical bytes, members the count, tx the latest member or withdrawal tx the read saw (None: none, an empty slice) and asof the read’s as-of. Written once per entry (Store::put_member_set).
Namespace
A namespace’s host and its key document.
PendingEmbedding
An entry or value with no embedding for a model, and the text to embed.
PgStore
The store on PostgreSQL, with a connection pool. Send + Sync: share one per process (behind an Arc); each call checks a connection out for its duration.
PoolOptions
How the pool behaves, and the roots TLS connections are verified against.
SliceMember
A member of a slice (Store::slice_members, Store::versions_between): a stored version and the bytes of its receipt (as receipt returns them). Since 0.3.1.
SliceValue
A member of a slice with its value and without its receipt’s bytes (Store::slice_values). Since 0.3.2.
SqliteOptions
How a SqliteStore opens and uses its connections.
SqliteStore
The store in one SQLite file (bundled SQLite, no server), with the same behaviour as PgStore: every method, error and rule of Store and Resolver. Send + Sync: share one per process (behind an Arc); each call takes a connection for its duration. Since 0.4.0.
SubjectKeys
The four keys of a catalogue subject (<host>/catalog/subject): domain, thing, measure, region. Ordered by the keys in that order.
Summary
The catalogue as an operator sees it (Store::catalog_summary).
SummaryEntry
An entry of a Summary.
TestSummary
The results of a function’s tests (Store::function_test_summary): how many there are, how many passed, failed, errored or have not run, the latest run and the branch counts. Default is the summary of no tests (all zero, no run). Since 0.5.2.
Version
A version of a cell: from transaction time tx on, the cell’s value is that of the receipt receipt_hash, which states it as of asof.

Enums§

CatalogKind
The kind of a catalogue entry.
CatalogSource
Who published an entry: the publisher (its signed document) or the operator (a local file). An operator’s entry never replaces a publisher’s.
EmbedRef
What an embedding is of: a catalogue entry or a dictionary value.
Error
What a Store method or a migration can fail with.
Hit
A text-search hit: an entry, or a dictionary value.
ListingWrite
What Store::put_listing did.

Constants§

FIND_MISSES_CAP
The most rows find_misses keeps; the oldest are pruned.
LISTING_SUBJECTS_MAX
The most subjects one listing names (as the catalogue job keeps at most 256 subjects of one entry).

Traits§

Resolver
What step 7 of SPEC 10.1 obtains: the descriptor, the input receipts (slice members included), the manifests of slice entries, and the evaluation. This crate evaluates no functions and fetches nothing; the caller supplies a resolver, and verify asks it only for what step 7 reaches for the receipt at hand:
Store
A Datumesh store: a Resolver that can also be written to.

Functions§

sort_key
The sort key of a cell (CONTRACT-0.5.1 S1; SPEC 5.6 and 15.13): its arguments as (name, type, lexical form), in ascending name order, encoded as cells.sort_key is stored (the same bytes on PostgreSQL and SQLite) and as SliceValue::sort_key returns them. Keys compare as bytes. An empty args gives the empty key of a cell with no arguments. Since 0.6.4.

Type Aliases§

Facets
The facets of a catalogue entry: a facet key (domain, thing, measure, region or frequency) to its names, ascending and unique, at most 8 of them (CONTRACT-classes-round C2).
RecordingClock
The clock a store records its versions at (CONTRACT-guard-patch G9): an instant, read at each insert. The store sets recorded = max(signed tx, clock()); with no clock it is the signed tx. Set once, when the store is opened (PoolOptions::recording_clock, SqliteOptions::recording_clock). Since 0.6.5.
Result
Result with the store’s Error.