A transaction groups reads and writes across collections and modalities, and commits all of them or none.
Writes take the transaction itself, while reads take a view of it, which also chooses whether the read registers its keys so the commit fails if another writer changed them since:
ustore_transaction_init begins a new transaction into a NULL handle, left NULL on failure, and resets a transaction of the same database in place, keeping its handle whatever the outcome, so a reset that fails leaves it fit only to be freed or initialized again.
A failed commit keeps the contents of the transaction for a retry. ustore_transaction_rollback withdraws a stage, releasing whatever it claimed, while keeping the reads and writes, so the transaction can stage again or be reset through ustore_transaction_init. ustore_transaction_stage stages the transaction for a two-phase commit and can export its read_stamp, the ustore_stamp_t the transaction reads at and its commit validates against.
A commit can export its commit_stamp, its position in commit order, which every snapshot at or above it sees, and is never below the stage’s read_stamp.
API
Types
ustore_transaction_tAn opaque handle to an optimistic transaction that groups operations across collections and modalities.
NULL is the head. Others come from ustore_transaction_view and ustore_snapshot_view, which tag the parent's pointer and allocate nothing, so a view needs no free and dies with its parent, which a cursor reading through it holds until the cursor is freed. A view names its parent, not a moment: after a commit, a transaction's view reads the transaction's next generation. Writes take a transaction instead, so nothing can write through a snapshot.
ustore_stamp_tA position in the order commits apply in, which grows with every commit: where a commit landed, or the newest commit a transaction or a snapshot reads.
In and out: a NULL handle here begins a new transaction, which the caller frees with ustore_transaction_free, written on success and left NULL on failure; a transaction of database is reset in place onto a fresh snapshot, dropping its reads and writes, and keeps its handle whatever the outcome, so after a failed reset it can only be freed or initialized again.
Whether the call returns final, the default, or once submitted.
Statuses
ustore_status_contended_k The transaction reset serves another call, the executor's deferred table is full, or a callback blocks on the executor running it.
ustore_status_write_conflict_k Another commit changed a key this transaction wrote, or, on the NVMe engine, any key, range or prefix it watched or a collection it touched.
ustore_status_write_conflict_k Another commit changed a key this transaction wrote, or, on the NVMe engine, any key, range or prefix it watched or a collection it touched.
ustore_transaction_rollbackWithdraws a stage, releasing whatever it claimed, while keeping the reads and writes, so the transaction can stage again or be reset through ustore_transaction_init.
ustore_transaction_freeWaits until every deferred call naming the transaction finishes, then resets it and frees its memory with every view of it once no cursor reads through it.