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 appended to the log before the write they describe is reported as committed, and FileTransitionLog fsyncs each append by default, so a crash can lose at most the transition that was in flight. The data store itself is made durable by GenericTransactionsDecorator::save, which calls LinksStorage::flush — for a memory-mapped store that is the fsync of the mapping; for the CLI’s in-memory store it is the rewrite of the database file. Recovery, run by GenericTransactionsDecorator::new, replays committed-but-unapplied transitions and rolls back transitions that were never committed, so a store that lost unflushed writes is brought back in line with the log.

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.
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.
TransitionKind
The kind of write operation recorded by a Transition.

Traits§

TransitionLogStore
Append-only store of serialized transitions and recovery markers.

Type Aliases§

DoubletLink
The u32-addressed doublet used by the clink CLI.
TransactionsDecorator
The u32 + NamedTypesDecorator specialisation used by clink.
Transition
The u32-addressed transition used by the clink CLI.