Skip to main content

Module transactions

Module transactions 

Source
Expand description

Optional transactions layer for the Rust link-cli.

Mirrors the C# TransactionsDecorator in csharp/Foundation.Data.Doublets.Cli.Library/TransactionsDecorator.cs.

The decorator records every create / update / delete as a reversible GenericTransition in a sidecar log. It supports explicit transactions, sync commits, three retention policies, and crash recovery (R1-R7, R10).

Optional — when not opted in, the bare NamedTypesDecorator behaves identically (R8, R9, R17).

§Reuse outside the CLI

GenericTransactionsDecorator is generic over three things:

  • T — the doublets address type (u32, u64, usize, …);
  • S — the wrapped store, any LinksStorage<T> implementation, including DoubletsStorage over a file-mapped or caller-owned doublets::unit::Store;
  • L — the transitions log, any TransitionLogStore.

TransactionsDecorator is the u32 + NamedTypesDecorator specialisation used by clink itself.

use link_cli::transactions::{
    CommitMode, FileTransitionLog, GenericTransactionsDecorator, LogRetentionPolicy,
};
use link_cli::DoubletsStorage;

let store = DoubletsStorage::<usize, _>::open_exclusive("db.links")?;
let log = FileTransitionLog::open("db.transitions.log")?;
let mut tx = GenericTransactionsDecorator::new(
    store,
    log,
    LogRetentionPolicy::default(),
    CommitMode::default(),
    false,
)?;

tx.begin_transaction()?;
let link = tx.create(0, 0)?;
tx.commit()?;
tx.save()?;

§Durability

Transitions are durably logged before commit is acknowledged. Commit then flushes the wrapped data before persisting its applied markers. Recovery replays committed-but-unapplied transitions and undoes logged uncommitted changes, reporting replay and flush failures.

The default RowUndoPolicy::Observed mutates the store before recording callbacks and leaves a crash window for unlogged changes. Select RowUndoPolicy::WriteAheadImage to flush a complete logical undo image before the first effect and reconcile complete history after each write. It requires exclusive ownership and an adapter supporting logical replay; it does not repair torn physical storage. The optional crate::engine::Engine stages private changes until durable publication.

Structs§

FileTransitionLog
Append-only, line-oriented transitions log backed by a single file.
GenericDoubletLink
A single doublet link state captured by a transition (mirror of the C# Platform.Data.Doublets.Link<TLinkAddress>).
GenericTransactionsDecorator
The transactions decorator wraps any LinksStorage and records every write as a reversible GenericTransition in log_store.
GenericTransition
Reversible write captured by the transactions layer. Holds both before and after link states so the operation can be undone or replayed.
JournalRecord
A row transition plus optional name state, or an independent name write. Use this complete value for recovery, archives and version movement.
NameChange
Logical name state for one address, including names of absent rows.
TransactionHandle
Snapshot of an open transaction (returned by GenericTransactionsDecorator::begin_transaction).

Enums§

CommitMode
Sync flushes data-store side-effects before commit returns.
LogRetentionPolicy
Retention policy for the transitions log.
RowUndoPolicy
Undo source for the ordinary, immediately mutating storage adapter.
TransitionKind
The kind of write operation recorded by a Transition.

Traits§

ReplaceableTransitionLogStore
Optional replacement of a complete ordered journal under the same exclusive owner. Success publishes all records atomically and durably when advertised. An uncertain failure fences the implementation until actual reopening.
TransitionLogStore
Append-only store of serialized transitions and recovery markers.

Functions§

import_links_journal
Copies every entry of the links-backed journal at legacy into the text journal at target, then removes the legacy store. Returns whether anything was imported.
is_links_journal
Whether path holds something other than a text journal: a non-empty file whose first bytes are not (a prefix of) the journal entry prefix.
make_legacy_transitions_filename
Path of the links-backed journal older versions kept: <stem>.transitions.links.
make_transitions_log_filename
Conventional journal path: <stem>.transitions.log next to database.
open_transitions_journal
Opens the journal of database: explicit when given, the conventional <stem>.transitions.log otherwise, importing a legacy links-backed journal first (see the module documentation).

Type Aliases§

DoubletLink
The u32-addressed doublet used by the clink CLI.
FileTransactionsDecorator
The specialisation clink uses: an append-only FileTransitionLog journal, whose cost per write does not grow with history (issue #195).
TransactionsDecorator
The u32 + NamedTypesDecorator specialisation with the original links-backed sidecar log.
Transition
The u32-addressed transition used by the clink CLI.