Table of Contents

Class TransactionsDecorator<TLinkAddress>

Namespace
Foundation.Data.Doublets.Cli
Assembly
Foundation.Data.Doublets.Cli.dll

Bounds the durable journal by the retention policy (issue #195): rust/src/transactions/compaction.rs.

public class TransactionsDecorator<TLinkAddress> : LinksDecoratorBase<TLinkAddress>, ITransactionsLinks<TLinkAddress>, INamedTypesLinks<TLinkAddress>, ILinks<TLinkAddress>, ILinks<TLinkAddress, LinksConstants<TLinkAddress>>, INamedTypes<TLinkAddress>, IDisposable where TLinkAddress : IUnsignedNumber<TLinkAddress>

Type Parameters

TLinkAddress
Inheritance
LinksOperatorBase<TLinkAddress>
LinksDecoratorBase<TLinkAddress>
TransactionsDecorator<TLinkAddress>
Implements
ITransactionsLinks<TLinkAddress>
INamedTypesLinks<TLinkAddress>
ILinks<TLinkAddress>
ILinks<TLinkAddress, LinksConstants<TLinkAddress>>
INamedTypes<TLinkAddress>
Derived
Inherited Members
LinksDecoratorBase<TLinkAddress>._constants
LinksDecoratorBase<TLinkAddress>._facade
LinksDecoratorBase<TLinkAddress>.Facade
LinksDecoratorBase<TLinkAddress>.Constants
LinksOperatorBase<TLinkAddress>._links
LinksOperatorBase<TLinkAddress>.Links
Extension Methods

Remarks

Retention trims the in-memory history after each commit or rollback. Without compaction the journal on disk kept every entry ever written, so each process start re-read the complete history and every write grew a file that no policy could shrink. When the log supports it, the journal is rewritten to the entries that still matter once it has grown to about twice that size, so the rewrite is amortized over many appends.

A compacted journal keeps, in order: a __transactions:sequence:<n> watermark, so sequence numbers (which version-control tags and branches reference) are never reused; an applied marker for the highest applied sequence; every retained record, unchanged; the commit or rollback decision of every retained record's owner and the newest decision, which version-control publication recovery reads; and the applied markers of retained records.

Undo images belong to undecided owners only while a transaction is open or recovery is pending; compaction never runs then, so decided images are dropped. A journal with any undecided record is left untouched.

Constructors

public TransactionsDecorator(INamedTypesLinks<TLinkAddress> inner, INamedTypesLinks<TLinkAddress> logStore, LogRetentionPolicy? retentionPolicy = null, CommitMode commitMode = CommitMode.Sync, bool trace = false, Action? flushData = null, Action? flushLog = null)

Parameters

inner INamedTypesLinks<TLinkAddress>
logStore INamedTypesLinks<TLinkAddress>
retentionPolicy LogRetentionPolicy
commitMode CommitMode
trace bool
flushData Action
flushLog Action
public TransactionsDecorator(INamedTypesLinks<TLinkAddress> inner, INamedTypesLinks<TLinkAddress> logStore, RowUndoPolicy rowUndoPolicy, LogRetentionPolicy? retentionPolicy = null, CommitMode commitMode = CommitMode.Sync, bool trace = false, Action? flushData = null, Action? flushLog = null)

Parameters

inner INamedTypesLinks<TLinkAddress>
logStore INamedTypesLinks<TLinkAddress>
rowUndoPolicy RowUndoPolicy
retentionPolicy LogRetentionPolicy
commitMode CommitMode
trace bool
flushData Action
flushLog Action

Journals into log, such as a FileTransitionLog whose size the retention policy bounds (issue #195).

public TransactionsDecorator(INamedTypesLinks<TLinkAddress> inner, ITransitionLogStore log, LogRetentionPolicy? retentionPolicy = null, CommitMode commitMode = CommitMode.Sync, bool trace = false, Action? flushData = null)

Parameters

inner INamedTypesLinks<TLinkAddress>
log ITransitionLogStore
retentionPolicy LogRetentionPolicy
commitMode CommitMode
trace bool
flushData Action

Journals into log with the given row undo policy.

public TransactionsDecorator(INamedTypesLinks<TLinkAddress> inner, ITransitionLogStore log, RowUndoPolicy rowUndoPolicy, LogRetentionPolicy? retentionPolicy = null, CommitMode commitMode = CommitMode.Sync, bool trace = false, Action? flushData = null)

Parameters

inner INamedTypesLinks<TLinkAddress>
log ITransitionLogStore
rowUndoPolicy RowUndoPolicy
retentionPolicy LogRetentionPolicy
commitMode CommitMode
trace bool
flushData Action

Properties

AppliedSequence

public long AppliedSequence { get; }

Property Value

long

CommitMode

public CommitMode CommitMode { get; set; }

Property Value

CommitMode

Journal

public IReadOnlyList<JournalRecord<TLinkAddress>> Journal { get; }

Property Value

IReadOnlyList<JournalRecord<TLinkAddress>>

JournalEntryCount

Number of entries the durable journal currently holds.

public long JournalEntryCount { get; }

Property Value

long

LastLoggedSequence

public long LastLoggedSequence { get; }

Property Value

long

Log

public IReadOnlyList<Transition<TLinkAddress>> Log { get; }

Property Value

IReadOnlyList<Transition<TLinkAddress>>

ReassignsNames

Whether assigning a name removes its previous owner.

public virtual bool ReassignsNames { get; }

Property Value

bool

RetentionPolicy

public LogRetentionPolicy RetentionPolicy { get; set; }

Property Value

LogRetentionPolicy

RowUndoPolicy

public RowUndoPolicy RowUndoPolicy { get; }

Property Value

RowUndoPolicy

SupportsDurableCommit

True when both data and journal have explicit stable-storage flushes.

public bool SupportsDurableCommit { get; }

Property Value

bool

Methods

ApplyRecord(JournalRecord<TLinkAddress>)

public void ApplyRecord(JournalRecord<TLinkAddress> record)

Parameters

record JournalRecord<TLinkAddress>

ApplyTransition(Transition<TLinkAddress>)

Apply a single transition's side-effect against the data store without writing a new log entry. Intended for use by higher-level decorators (e.g. version control) that need to drive replay/rewind without producing additional transitions.

public virtual void ApplyTransition(Transition<TLinkAddress> transition)

Parameters

transition Transition<TLinkAddress>

Exceptions

InvalidOperationException

A transaction or its cleanup still owns the data store.

BeginTransaction()

public virtual ITransaction<TLinkAddress> BeginTransaction()

Returns

ITransaction<TLinkAddress>

BeginTransactionAsync(CancellationToken)

public virtual Task<ITransaction<TLinkAddress>> BeginTransactionAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task<ITransaction<TLinkAddress>>

CaptureNames()

A detached logical name snapshot for undo. Stores supporting names of absent rows override this default row-based enumeration to include them.

public virtual IReadOnlyDictionary<TLinkAddress, string> CaptureNames()

Returns

IReadOnlyDictionary<TLinkAddress, string>

Create(IList<TLinkAddress>?, WriteHandler<TLinkAddress>?)

Creates the restriction.

public override TLinkAddress Create(IList<TLinkAddress>? substitution, WriteHandler<TLinkAddress>? handler)

Parameters

substitution IList<TLinkAddress>

The restriction.

handler WriteHandler<TLinkAddress>

Optional callback; null continues without invoking a callback.

Returns

TLinkAddress

The link

Delete(IList<TLinkAddress>?, WriteHandler<TLinkAddress>?)

Deletes the restriction.

public override TLinkAddress Delete(IList<TLinkAddress>? restriction, WriteHandler<TLinkAddress>? handler)

Parameters

restriction IList<TLinkAddress>

The restriction.

handler WriteHandler<TLinkAddress>

Optional callback; null continues without invoking a callback.

Returns

TLinkAddress

Dispose()

Stops the background worker. The wrapped data store and log store are not disposed here; callers are expected to own those.

public void Dispose()

Dispose(bool)

Stops the background worker. Derived decorators that own extra resources override this and call base.Dispose(disposing).

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

GetByName(string)

public virtual TLinkAddress GetByName(string name)

Parameters

name string

Returns

TLinkAddress

GetName(TLinkAddress)

public virtual string? GetName(TLinkAddress link)

Parameters

link TLinkAddress

Returns

string

MakeTransitionsDatabaseFilename(string)

Conventional sidecar filename for the transitions log.

public static string MakeTransitionsDatabaseFilename(string databaseFilename)

Parameters

databaseFilename string

Returns

string

Recover()

public virtual void Recover()

RemoveName(TLinkAddress)

public virtual void RemoveName(TLinkAddress link)

Parameters

link TLinkAddress

Preview a query over owned rows and reserve its allocation order. Returns final identities, or null when the store uses legacy prediction.

public virtual IReadOnlySet<TLinkAddress>? ReserveQueryAllocations(Action<INamedTypesLinks<TLinkAddress>> preview)

Parameters

preview Action<INamedTypesLinks<TLinkAddress>>

Returns

IReadOnlySet<TLinkAddress>

RevertRecord(JournalRecord<TLinkAddress>)

public void RevertRecord(JournalRecord<TLinkAddress> record)

Parameters

record JournalRecord<TLinkAddress>

RevertTransition(Transition<TLinkAddress>)

Revert a single transition's side-effect against the data store without writing a new log entry. Intended for use by higher-level decorators (e.g. version control) that need to drive replay/rewind without producing additional transitions.

public virtual void RevertTransition(Transition<TLinkAddress> transition)

Parameters

transition Transition<TLinkAddress>

Exceptions

InvalidOperationException

A transaction or its cleanup still owns the data store.

Rollback()

Rolls back the current transaction, including retrying cleanup after an automatic write's rollback failed. A known durable commit instead finishes its checkpoint. A failure keeps either outcome pending.

public virtual void Rollback()

SetName(TLinkAddress, string)

public virtual TLinkAddress SetName(TLinkAddress link, string name)

Parameters

link TLinkAddress
name string

Returns

TLinkAddress

Shutdown()

Stops and joins the background worker before borrowed stores may close. Concurrent callers all wait for completion. Queued checkpoint work may be cancelled; committed journal records remain recoverable on reopen. Callers must finish foreground operations first and callbacks must return.

public virtual void Shutdown()

Exceptions

InvalidOperationException

Called from active background work or while holding the storage lock. Such a caller cannot wait for worker completion without risking deadlock.

Update(IList<TLinkAddress>?, IList<TLinkAddress>?, WriteHandler<TLinkAddress>?)

Updates the restriction.

public override TLinkAddress Update(IList<TLinkAddress>? restriction, IList<TLinkAddress>? substitution, WriteHandler<TLinkAddress>? handler)

Parameters

restriction IList<TLinkAddress>

The restriction.

substitution IList<TLinkAddress>

The substitution.

handler WriteHandler<TLinkAddress>

Optional callback; null continues without invoking a callback.

Returns

TLinkAddress

The link