Show / Hide Table of Contents

Class DiskBasedStateMachine

Represents disk-based state machine.

Inheritance
object
Disposable
PersistentState
DiskBasedStateMachine
Implements
IDisposable
IPersistentState
IAuditTrail<IRaftLogEntry>
IAuditTrail
Inherited Members
PersistentState.CreateBackupAsync(Stream, CancellationToken)
PersistentState.RestoreFromBackupAsync(Stream, DirectoryInfo, CancellationToken)
PersistentState.Location
PersistentState.ReadAsync<TResult>(ILogEntryConsumer<IRaftLogEntry, TResult>, long, long, CancellationToken)
PersistentState.ReadAsync<TResult>(ILogEntryConsumer<IRaftLogEntry, TResult>, long, CancellationToken)
PersistentState.AppendAsync<TEntry>(TEntry, long, CancellationToken)
PersistentState.AppendAsync<TEntry>(TEntry, CancellationToken)
PersistentState.AppendAsync<TEntry>(TEntry, bool, CancellationToken)
PersistentState.AppendAsync<TEntry>(ILogEntryProducer<TEntry>, CancellationToken)
PersistentState.DropAsync(long, bool, CancellationToken)
PersistentState.WaitForApplyAsync(CancellationToken)
PersistentState.WaitForApplyAsync(long, CancellationToken)
PersistentState.CommitAsync(long, CancellationToken)
PersistentState.CommitAsync(CancellationToken)
PersistentState.ClearAsync(CancellationToken)
PersistentState.Term
PersistentState.Dispose(bool)
PersistentState.CreateJsonLogEntry<T>(T)
PersistentState.CreateBinaryLogEntry(ReadOnlyMemory<byte>)
PersistentState.CreateBinaryLogEntry<T>(T)
PersistentState.LastCommittedEntryIndex
PersistentState.LastEntryIndex
Disposable.IsDisposed
Disposable.IsDisposing
Disposable.IsDisposingOrDisposed
Disposable.CreateException()
Disposable.DisposedTask
Disposable.GetDisposedTask<T>()
Disposable.TrySetDisposedException<T>(TaskCompletionSource<T>)
Disposable.TrySetDisposedException(TaskCompletionSource)
Disposable.DisposeAsyncCore()
Disposable.DisposeAsync()
Disposable.TryBeginDispose()
Disposable.Dispose()
Disposable.Dispose(IEnumerable<IDisposable>)
Disposable.DisposeAsync(IEnumerable<IAsyncDisposable>)
Disposable.Dispose<T>(ReadOnlySpan<T>)
Disposable.DisposeAsync(params IAsyncDisposable[])
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: DotNext.Net.Cluster.Consensus.Raft
Assembly: DotNext.Net.Cluster.dll
Syntax
public abstract class DiskBasedStateMachine : PersistentState, IDisposable, IPersistentState, IAuditTrail<IRaftLogEntry>, IAuditTrail
Remarks

In contrast to MemoryBasedStateMachine, disk-based state machine keeps recent changes in the memory. The entire state is fully persisted on the disk. The persisted state can be used as a snapshot. The recent changes can be reconstructed from the committed log entries.

Constructors

| Edit this page View Source

DiskBasedStateMachine(DirectoryInfo, int, Options?)

Initializes a new memory-based state machine.

Declaration
protected DiskBasedStateMachine(DirectoryInfo path, int recordsPerPartition, PersistentState.Options? configuration = null)
Parameters
Type Name Description
DirectoryInfo path

The path to the folder to be used by audit trail.

int recordsPerPartition

The maximum number of log entries that can be stored in the single file called partition.

PersistentState.Options configuration

The configuration of the persistent audit trail.

Exceptions
Type Condition
ArgumentOutOfRangeException

recordsPerPartition is less than 2.

| Edit this page View Source

DiskBasedStateMachine(string, int, Options?)

Initializes a new memory-based state machine.

Declaration
protected DiskBasedStateMachine(string path, int recordsPerPartition, PersistentState.Options? configuration = null)
Parameters
Type Name Description
string path

The path to the folder to be used by audit trail.

int recordsPerPartition

The maximum number of log entries that can be stored in the single file called partition.

PersistentState.Options configuration

The configuration of the persistent audit trail.

Exceptions
Type Condition
ArgumentOutOfRangeException

recordsPerPartition is less than 2.

Methods

| Edit this page View Source

ApplyAsync(LogEntry)

Applies the committed log entry to the state machine.

Declaration
protected abstract ValueTask<long?> ApplyAsync(PersistentState.LogEntry entry)
Parameters
Type Name Description
PersistentState.LogEntry entry

The entry to be applied to the state machine.

Returns
Type Description
ValueTask<long?>

The size of the snapshot, in bytes; null to keep the committed log entry in the log.

See Also
CommandInterpreter
| Edit this page View Source

BeginReadSnapshotAsync(SnapshotAccessToken, MemoryAllocator<byte>, CancellationToken)

Starts the reading of a snapshot.

Declaration
protected abstract ValueTask<IAsyncBinaryReader> BeginReadSnapshotAsync(DiskBasedStateMachine.SnapshotAccessToken session, MemoryAllocator<byte> allocator, CancellationToken token)
Parameters
Type Name Description
DiskBasedStateMachine.SnapshotAccessToken session

The internal identifier of the read session. Multiple reads can happen in the same time (in parallel), thus it is possible to use this identifier to distinguish them.

MemoryAllocator<byte> allocator

The memory allocator that can be used to rent the buffer for the reader.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask<IAsyncBinaryReader>

The snapshot reader.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Edit this page View Source

EndReadSnapshot(SnapshotAccessToken)

Ends the reading of a snapshot.

Declaration
protected abstract void EndReadSnapshot(DiskBasedStateMachine.SnapshotAccessToken session)
Parameters
Type Name Description
DiskBasedStateMachine.SnapshotAccessToken session

A token that uniquely identifies the concurrent read of the snapshot.

| Edit this page View Source

InitializeAsync(CancellationToken)

Initializes internal state of the state machine and replays committed log entries that were not moved to the snapshot.

Declaration
public override Task InitializeAsync(CancellationToken token = default)
Parameters
Type Name Description
CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
Task

The task representing asynchronous result of the method.

Overrides
PersistentState.InitializeAsync(CancellationToken)
Remarks

The method calls ApplyAsync(LogEntry) to replay the committed log entries in the head of the log.

Exceptions
Type Condition
OperationCanceledException

The operation has been cancelled.

| Edit this page View Source

InstallSnapshotAsync<TSnapshot>(TSnapshot)

Rewrites local snapshot with the snapshot supplied by remote cluster member.

Declaration
protected abstract ValueTask<long> InstallSnapshotAsync<TSnapshot>(TSnapshot snapshot) where TSnapshot : IRaftLogEntry
Parameters
Type Name Description
TSnapshot snapshot

The log entry containing snapshot.

Returns
Type Description
ValueTask<long>

The size of the snapshot, in bytes.

Type Parameters
Name Description
TSnapshot

The type of the log entry containing snapshot.

Implements

IDisposable
IPersistentState
IAuditTrail<TEntry>
IAuditTrail

Extension Methods

BasicExtensions.As<T>(T)
BasicExtensions.GetUserData<T>(T)
BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, ReadOnlySpan<T>)
ExpressionBuilder.Const<T>(T)
AsyncLockAcquisition.AcquireLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireLockAsync<T>(T, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, bool, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, bool, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, TimeSpan, CancellationToken)
LockAcquisition.AcquireReadLock<T>(T)
LockAcquisition.AcquireReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireUpgradeableReadLock<T>(T)
LockAcquisition.AcquireUpgradeableReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireWriteLock<T>(T)
LockAcquisition.AcquireWriteLock<T>(T, TimeSpan)
Command.AppendAsync<TCommand>(IPersistentState, TCommand, object?, CancellationToken)
PersistentStateExtensions.AppendAsync(IPersistentState, ReadOnlyMemory<byte>, object?, CancellationToken)
PersistentStateExtensions.AppendAsync<T>(IPersistentState, T, object?, CancellationToken)
PersistentStateExtensions.AppendJsonAsync<T>(IPersistentState, T, object?, CancellationToken)
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾