Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
38fd064
build(deps): pin spiral-sdk 0.16.78, which reads and writes table met…
eywalker Dec 1, 2026
10ac3d0
feat(spiraldb): store table identity record and codec, provisional an…
eywalker Dec 1, 2026
cdfa2e6
fix(spiraldb): keep plain-field extension metadata; one store path do…
eywalker Dec 1, 2026
384426d
feat(spiraldb): internal store mode under ConnectorArrowDatabase (ITL…
eywalker Dec 1, 2026
5574a4c
Merge remote-tracking branch 'origin/eywalker/itl-1837-spiraldb-store…
eywalker Dec 1, 2026
36ba2a9
refactor(spiraldb): store mode uses the shared store path domain; sta…
eywalker Dec 1, 2026
216f198
docs(spiraldb): the store path rule is SpiralDB's component syntax; p…
eywalker Dec 1, 2026
2f10d99
Merge remote-tracking branch 'origin/eywalker/itl-1837-spiraldb-store…
eywalker Dec 1, 2026
c8e15d0
fix(spiraldb): store mode review round 1: order-free key check, name …
eywalker Dec 1, 2026
ba14378
fix(spiraldb): store mode review round 2: one identifier-preserving d…
eywalker Dec 1, 2026
1e2964c
fix(spiraldb): keep the flush key read until the lease; schema test s…
eywalker Dec 1, 2026
6fb1b6e
fix(spiraldb): open the table afresh at every write; run the schema c…
eywalker Dec 1, 2026
ed788d9
fix(spiraldb): refuse stored values the codec cannot restore; record …
eywalker Dec 1, 2026
1e35702
Merge remote-tracking branch 'origin/main' into eywalker/itl-1837-spi…
eywalker Dec 1, 2026
fb61329
fix(spiraldb): store mode review round 3: per-operation judgments, ad…
eywalker Dec 1, 2026
537d66f
build(deps): pin spiral-sdk 0.16.80; ignore its keyed-table deprecati…
eywalker Dec 1, 2026
4a8947a
Merge branch 'eywalker/itl-1837-spiraldb-store-stage-a-on-current-mai…
eywalker Dec 1, 2026
57f1b66
fix(spiraldb): open and create every store table through the connecto…
eywalker Dec 1, 2026
1e9b900
fix(spiraldb): keep the keyed-table deprecation filter first; route t…
eywalker Dec 2, 2026
bba26c1
Merge #691 head 1e9b9009a into stage B (ITL-1840)
eywalker Dec 2, 2026
b761f72
Merge origin/main (#691 squashed as ea0138de7) into stage B (ITL-1840)
eywalker Dec 2, 2026
19e49f3
fix(spiraldb): list a table of another store format as a marked path,…
eywalker Dec 2, 2026
29abfe8
fix(databases): a stored table a lookup cannot read fails the run; li…
eywalker Dec 2, 2026
edc3071
fix(spiraldb): finding a stored table is a read; a changed identity r…
eywalker Dec 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog.d/ITL-1840.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Known limitations

- Orcapod still cannot use SpiralDB as a job's database: a `SpiralDBConnector` refuses
every write. An internal store mode now writes and reads every stored table kind
through `ConnectorArrowDatabase` (one table per path, its identity and manifest in the
table's metadata), but nothing opens it publicly, it is not saved with a job, and its
format stays provisional, outside the 0.4.0 freeze. (ITL-1840)
168 changes: 168 additions & 0 deletions docs/dev/plans/2026-12-01-itl-1840-spiral-store-stage-b.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# ITL-1840: SpiralDB store, stage B (store mode under ConnectorArrowDatabase)

Stage B of using SpiralDB as a job's pipeline and result database (ITL-1446), on top of
stage A (ITL-1837: the spiral-sdk pin, the identity record, the codec). It carries PR 595's
store mode (ITL-1498) onto current `main`. PR 595 is not merged: its refactor of the
connector protocol (`table_name`, `has_table`, `table_paths`, `validate_records(table_name=)`)
collides with `main`'s SQL store catalog (`_sql_store.py`, ITL-1552) and is not carried.
Its `spiraldb_store_tables.py` and its tests are.

Nothing is public. The store mode is a private constructor argument,
`SpiralDBConnector(project, dataset, _store=True)`, read and written only through
`ConnectorArrowDatabase`. A plain `SpiralDBConnector` behaves as on `main`: it reads and
refuses every write (`SpiralDBWriteNotSupportedError`).

## Structure

- `databases/spiraldb_store_tables.py` (`StoreTables`): the tables of one dataset in store
mode. Names come from the full path (`spiral_store_identity.spiral_store_table_name`, after
`store_table_names.require_store_path_domain`, the one path domain the identity record and
the manifest apply). Each table's metadata holds its identity record and manifest, written
in one upsert before its first rows. Rows go through the codec (`spiral_store`).
- `SpiralDBConnector` builds a `StoreTables` when `_store=True`, hands it out through the
private `_store_tables()`, and in store mode refuses raw access (`lookup_table`,
`iter_batches`, `get_table_names` and every read built on them) with a `ValueError`. Its
protocol write methods still raise `SpiralDBWriteNotSupportedError`. `to_config` refuses
a store-mode connector, so a job on one is not saved. `close` releases the store's tables.
- `ConnectorArrowDatabase` gets an internal store branch beside `_sql_store`: naming,
finding, reading, the stored-id check, listing, column info, the stored schema, the
storable-column check, validation and the write go to `StoreTables` when the connector
is a store-mode `SpiralDBConnector`. `DBConnectorProtocol` is unchanged.

The branch is taken only for a store-mode connector. For every other connector, the
plain `SpiralDBConnector` included, the code paths are `main`'s, with one exception: a
lookup of committed rows (`get_record_by_id`, `get_all_records` and the reads built on
them) now raises `OrcapodDatabaseReadError` on every connector when finding or reading
the stored table fails, as `get_table_schema` already did. For example, a SQLite
`iter_batches` failure, or a failing catalog query, reaches the caller as
`OrcapodDatabaseReadError` (its cause the driver's error), no longer as
`sqlite3.OperationalError`; a table refused as another path's keeps its own error.

## Rules carried over

- A table under the computed name that is not this path's store table is refused
(`SpiralStoreTableCollisionError`): another path or format in its record, a key other
than `__record_id` binary, or rows without a manifest. A table with no rows is new to any
first writer (a creation that stopped before its first rows).
- A first write re-reads the table just before recording it and never records over what
that read shows: an equivalent manifest (compared by name and decoded, never by bytes or
order) is appended beside; anything else is refused. Without a compare-and-set and a lease
(ITL-1452) two writers can still race in between.
- Rows hold one `__data_context`, a key this Orcapod resolves, and the one the table records.
Checked when rows are added (before they are buffered) and again at flush (the table may
have been made since).
- A logical type given in storage form is made live before it is compared and buffered
(store mode only), so one column has one form in the manifest.
- Listing (`list_table_paths`, hence the stale-layout check of ITL-954): one listing of the
dataset narrowed by the name prefix, then each candidate's recorded path, cached by table
id; a listed table whose record is of a path with another name is refused, and so is a
partial or unreadable record. A table whose complete record names another store format
is listed under its recorded path with the last component `<recorded layout>/<format>`,
which no path can hold (a component never contains `/`): the stale-layout check reports
it (a side-effect node refuses, any other node reports and runs), and opening that path
raises a `ValueError` saying what it is. No protocol method is added (D4).

## The write rules of ITL-1386

- A stored or pending id raises unless `skip_duplicates`, as for every connector
(`ConnectorArrowDatabase.add_records`).
- `existing_record_ids` is answered by one scan of the key column alone, with no filter,
intersected here with the ids asked. No other column is read. It never reads a range of
ids: how the service orders binary values is not measured, and a range taken in another
order than the service's would hide a stored id (review round 1). spiral-sdk 0.16.78 has
no membership expression; one equality per id would be a request per id, or an `or_`
chain as long as the ids, whose cost on the service is not measured either. The key
column alone is the cheapest order-independent read available.
- The stage E candidate for a keyed lookup (review round 2, not adopted here): spiral-sdk
0.16.78's `KeyedTable.scan(key_ranges=...)` takes several `KeyRange`s with inclusive
`KeyBound`s, so a range whose start and end are both the same key, one per id, would be
a batched point lookup with no ordering assumed in Python. The fake does not model key
ranges and nothing here ran against a live SpiralDB: binary key literals, correctness
(every stored id found, under the service's own order) and the work on the service are
to be validated live before it replaces the key-column read.
- A flush reads the keys again, also for ids its add found absent (review round 2
considered skipping it): until the one-writer lease (ITL-1838, wired into every job run
by stage D, ITL-1844), another writer, in this process or another, may store one of
those ids between the add and the flush, and an append would then replace its row. Once the lease makes this writer the only
one, the flush can rely on the add's check (ITL-1841).
- A flush never overwrites a row its key scan sees. A SpiralDB append replaces a row of the
same key, so the store writes only the keys the table does not hold in the snapshot the
flush reads its keys from (the same key-column read): a key another writer stored after
this one's add, and before that scan, keeps its first commit, as with every other
connector. A key another writer commits between that scan and the append is not seen,
and the pending row then replaces it: SpiralDB has no insert-if-absent. Nothing in this
stage closes that window; the one-writer lease (ITL-1838) and stage D, which takes it in
every job run and refuses store writes outside one (ITL-1844), do.
- Storage metadata must match on append: the stored schema (the manifest's, logical types
live) is held as for any connector that keeps field metadata (`_refuse_changed_columns`),
and the store compares the rows with the manifest again when it writes.
- An append is refused when the table's manifest records other stored names than the
codec's rule gives the rows (at any depth): the reader reads the names the manifest
records, so columns written under other names could not be read back. Only a manifest
this writer did not make (another writer, or a later naming rule) records other names.
- Rows of another data context than those pending for the same table are refused when
they are added, never buffered, as the write refuses a batch of two contexts.

## Finding a table, and what is kept

- Every keyed table the store opens (by name or by id) or creates is opened or created by
`spiraldb_connector` (`_open_keyed_table`, `_open_keyed_table_by_id`,
`_create_keyed_table`), handed to `StoreTables` as callables: spiral-sdk 0.16.79 and later
warn on every keyed-table call, attributed to the calling module, and Orcapod ignores that
warning for that module's own calls only (stage A, `_ignore_keyed_table_deprecation`).

- A table's name is opened once per public operation of `ConnectorArrowDatabase` (an add,
a flush, a read, a schema or listing call; `StoreTables.operation`), and that handle
reused within it until the store writes to the table (review round 2). A flush of a table
that holds rows opens the name twice: the caller's schema check reads through the
operation's handle, and the write then looks the name up again and reads the keys from
that new snapshot. The second lookup is needed because the check is the caller's code
(run outside the operation): it, or another writer meanwhile, can rename or replace the
table or commit a key, and a write through the earlier handle would then append to the
wrong table or replace that key's row. The next
operation opens it again: a table can be renamed and another made under its name, so
nothing is read or written through an earlier operation's answer. What a table that
holds rows records (key, identity record, manifest) is kept by its table id.
- What a name was judged (no table; a table with no rows, with what it recorded; a table
with rows) is kept in the thread's operation only. No other call can change it: a table
judged empty reads as no rows for the rest of the operation, and a first write compares
the table with what its own judgment saw.
- What a first write records is kept only once its append succeeded. A failed append
(also one the service stored before the error reached the client) forgets it, and the
next call judges the table again.
- A logical type's identifier bytes are compared as given, before a storage-form column is
made live, against the pending batch and the manifest as recorded (ITL-1371).
- One declaration rule, `spiraldb_store_tables.declared_keeping_identifier`, gives the
rows buffered and flushed, the schema a table reports and the schema its rows are
decoded under: a column is made live, under the data context of the rows or of the
table, only when the live type states exactly the identifier bytes recorded; one the
type reads under other bytes (an older identifier) stays in its storage form (review
round 2). A table first written with an older identifier reads back, reports its
schema and appends with those bytes.
- `get_table_schema` of a stored table is the manifest's schema, field and schema metadata
included, as a read gives it.

## Tests

`tests/test_databases/test_spiraldb_store_mode.py`, on the fake only:

- each table kind (`pdb_v2`, `rdb_v1`, `odb_v3`, `sdb_v2`, `tdb_v2`) written by a job (a
function node, a logged operator node, a sink) and a `CachedSource`, listed and read back
by a fresh connector, and a second run that calls and delivers nothing; sync and async;
- a new input adds rows to every table and leaves the stored rows unchanged, sync and
async; `job.run()` and `job.run_async()` with an observer, and a rerun that holds rows;
- the ITL-1386 rules, the key-column read (several ids, in both orders, under a service
that orders binary values otherwise), failed appends, renamed and replaced tables,
identifier bytes on both sides, refusals of
foreign tables, the data-context checks, the path domain, listing, concurrent first
writers, and that a plain connector still writes nothing.

## What is left (later stages of ITL-1446)

The one-writer lease (ITL-1452), the public switch-on with save and load, the live run,
and fewer service calls per run (keyed reads, one existence answer per run).

Known limit (stage E, ITL-1841): each strict existence check, and each flush, reads the
table's whole key column, so its cost grows with the table's history;
successive batches into a growing table cost quadratically many keys in all. Reads of
stored rows read the whole table the same way.
Loading
Loading