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, anyLinksStorage<T>implementation, includingDoubletsStorageover a file-mapped or caller-owneddoublets::unit::Store;L— the transitions log, anyTransitionLogStore.
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§
- File
Transition Log - Append-only, line-oriented transitions log backed by a single file.
- Generic
Doublet Link - A single doublet link state captured by a transition (mirror of the
C#
Platform.Data.Doublets.Link<TLinkAddress>). - Generic
Transactions Decorator - The transactions decorator wraps any
LinksStorageand records every write as a reversibleGenericTransitioninlog_store. - Generic
Transition - Reversible write captured by the transactions layer. Holds both
beforeandafterlink states so the operation can be undone or replayed. - Transaction
Handle - Snapshot of an open transaction (returned by
GenericTransactionsDecorator::begin_transaction).
Enums§
- Commit
Mode - Sync flushes data-store side-effects before
commitreturns. - LogRetention
Policy - Retention policy for the transitions log.
- Transition
Kind - The kind of write operation recorded by a
Transition.
Traits§
- Transition
LogStore - Append-only store of serialized transitions and recovery markers.
Type Aliases§
- Doublet
Link - The
u32-addressed doublet used by theclinkCLI. - Transactions
Decorator - The
u32+NamedTypesDecoratorspecialisation used byclink. - Transition
- The
u32-addressed transition used by theclinkCLI.