Class DiskBasedStateMachine
Represents disk-based state machine.
Inherited Members
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 SourceDiskBasedStateMachine(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 |
|
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 |
|
Methods
| Edit this page View SourceApplyAsync(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
| Edit this page View SourceBeginReadSnapshotAsync(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. |
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. |
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
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. |
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 : notnull, 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. |