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>._constantsLinksDecoratorBase<TLinkAddress>._facadeLinksDecoratorBase<TLinkAddress>.FacadeLinksDecoratorBase<TLinkAddress>.ConstantsLinksOperatorBase<TLinkAddress>._linksLinksOperatorBase<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
TransactionsDecorator(INamedTypesLinks<TLinkAddress>, INamedTypesLinks<TLinkAddress>, LogRetentionPolicy?, CommitMode, bool, Action?, Action?)
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
innerINamedTypesLinks<TLinkAddress>logStoreINamedTypesLinks<TLinkAddress>retentionPolicyLogRetentionPolicycommitModeCommitModetraceboolflushDataActionflushLogAction
TransactionsDecorator(INamedTypesLinks<TLinkAddress>, INamedTypesLinks<TLinkAddress>, RowUndoPolicy, LogRetentionPolicy?, CommitMode, bool, Action?, 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
innerINamedTypesLinks<TLinkAddress>logStoreINamedTypesLinks<TLinkAddress>rowUndoPolicyRowUndoPolicyretentionPolicyLogRetentionPolicycommitModeCommitModetraceboolflushDataActionflushLogAction
TransactionsDecorator(INamedTypesLinks<TLinkAddress>, ITransitionLogStore, LogRetentionPolicy?, CommitMode, bool, 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
innerINamedTypesLinks<TLinkAddress>logITransitionLogStoreretentionPolicyLogRetentionPolicycommitModeCommitModetraceboolflushDataAction
TransactionsDecorator(INamedTypesLinks<TLinkAddress>, ITransitionLogStore, RowUndoPolicy, LogRetentionPolicy?, CommitMode, bool, 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
innerINamedTypesLinks<TLinkAddress>logITransitionLogStorerowUndoPolicyRowUndoPolicyretentionPolicyLogRetentionPolicycommitModeCommitModetraceboolflushDataAction
Properties
AppliedSequence
public long AppliedSequence { get; }
Property Value
CommitMode
public CommitMode CommitMode { get; set; }
Property Value
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
LastLoggedSequence
public long LastLoggedSequence { get; }
Property Value
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
RetentionPolicy
public LogRetentionPolicy RetentionPolicy { get; set; }
Property Value
RowUndoPolicy
public RowUndoPolicy RowUndoPolicy { get; }
Property Value
SupportsDurableCommit
True when both data and journal have explicit stable-storage flushes.
public bool SupportsDurableCommit { get; }
Property Value
Methods
ApplyRecord(JournalRecord<TLinkAddress>)
public void ApplyRecord(JournalRecord<TLinkAddress> record)
Parameters
recordJournalRecord<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
transitionTransition<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
cancellationTokenCancellationToken
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
substitutionIList<TLinkAddress>The restriction.
handlerWriteHandler<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
restrictionIList<TLinkAddress>The restriction.
handlerWriteHandler<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
disposingbool
GetByName(string)
public virtual TLinkAddress GetByName(string name)
Parameters
namestring
Returns
- TLinkAddress
GetName(TLinkAddress)
public virtual string? GetName(TLinkAddress link)
Parameters
linkTLinkAddress
Returns
MakeTransitionsDatabaseFilename(string)
Conventional sidecar filename for the transitions log.
public static string MakeTransitionsDatabaseFilename(string databaseFilename)
Parameters
databaseFilenamestring
Returns
Recover()
public virtual void Recover()
RemoveName(TLinkAddress)
public virtual void RemoveName(TLinkAddress link)
Parameters
linkTLinkAddress
ReserveQueryAllocations(Action<INamedTypesLinks<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
previewAction<INamedTypesLinks<TLinkAddress>>
Returns
- IReadOnlySet<TLinkAddress>
RevertRecord(JournalRecord<TLinkAddress>)
public void RevertRecord(JournalRecord<TLinkAddress> record)
Parameters
recordJournalRecord<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
transitionTransition<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
linkTLinkAddressnamestring
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
restrictionIList<TLinkAddress>The restriction.
substitutionIList<TLinkAddress>The substitution.
handlerWriteHandler<TLinkAddress>Optional callback; null continues without invoking a callback.
Returns
- TLinkAddress
The link