Class SimpleStateMachine
Represents a state machine that keeps the entire state in the memory but periodically creates a persistent snapshot for recovery.
Inherited Members
Namespace: DotNext.Net.Cluster.Consensus.Raft.StateMachine
Assembly: DotNext.Net.Cluster.dll
Syntax
public abstract class SimpleStateMachine : IAsyncDisposable, IStateMachine, ISnapshotManagerConstructors
| Edit this page View SourceSimpleStateMachine(DirectoryInfo)
Initializes a new simple state machine.
Declaration
protected SimpleStateMachine(DirectoryInfo location)Parameters
| Type | Name | Description | 
|---|---|---|
| DirectoryInfo | location | 
Methods
| Edit this page View SourceApplyAsync(LogEntry, CancellationToken)
Applies the log entry to this state machine.
Declaration
protected abstract ValueTask<bool> ApplyAsync(LogEntry entry, CancellationToken token)Parameters
| Type | Name | Description | 
|---|---|---|
| LogEntry | entry | The log entry to apply to the current state machine. | 
| CancellationToken | token | The token that can be used to cancel the operation. | 
Returns
| Type | Description | 
|---|---|
| ValueTask<bool> | true if the current state must be persisted; otherwise, false. | 
Exceptions
| Type | Condition | 
|---|---|
| OperationCanceledException | The operation has been canceled. | 
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
Declaration
public virtual ValueTask DisposeAsync()Returns
| Type | Description | 
|---|---|
| ValueTask | A task that represents the asynchronous dispose operation. | 
PersistAsync(IAsyncBinaryWriter, CancellationToken)
Persists the current state.
Declaration
protected abstract ValueTask PersistAsync(IAsyncBinaryWriter writer, CancellationToken token)Parameters
| Type | Name | Description | 
|---|---|---|
| IAsyncBinaryWriter | writer | The writer that can be used to write the state. | 
| CancellationToken | token | The token that can be used to cancel the operation. | 
Returns
| Type | Description | 
|---|---|
| ValueTask | The task representing asynchronous execution of the method. | 
RestoreAsync(CommandInterpreter, FileInfo, CancellationToken)
Restores the in-memory state from the snapshot.
Declaration
protected static ValueTask RestoreAsync(CommandInterpreter interpreter, FileInfo snapshotFile, CancellationToken token)Parameters
| Type | Name | Description | 
|---|---|---|
| CommandInterpreter | interpreter | The command interpreter. | 
| FileInfo | snapshotFile | The snapshot file. | 
| CancellationToken | token | The token that can be used to cancel the operation. | 
Returns
| Type | Description | 
|---|---|
| ValueTask | The task representing asynchronous execution of the method. | 
Remarks
This method is intended to be called from RestoreAsync(FileInfo, CancellationToken) when the compatibility with CommandInterpreter is required.
Exceptions
| Type | Condition | 
|---|---|
| OperationCanceledException | The operation has been canceled. | 
RestoreAsync(FileInfo, CancellationToken)
Restores the in-memory state from the snapshot.
Declaration
protected abstract ValueTask RestoreAsync(FileInfo snapshotFile, CancellationToken token)Parameters
| Type | Name | Description | 
|---|---|---|
| FileInfo | snapshotFile | The snapshot file. | 
| CancellationToken | token | The token that can be used to cancel the operation. | 
Returns
| Type | Description | 
|---|---|
| ValueTask | The task representing asynchronous execution of the method. | 
Exceptions
| Type | Condition | 
|---|---|
| OperationCanceledException | The operation has been canceled. | 
RestoreAsync(CancellationToken)
Restores the in-memory state from the most recent snapshot stored on the disk.
Declaration
public ValueTask RestoreAsync(CancellationToken token = default)Parameters
| Type | Name | Description | 
|---|---|---|
| CancellationToken | token | The token that can be used to cancel the operation. | 
Returns
| Type | Description | 
|---|---|
| ValueTask | The task representing asynchronous execution of the method. | 
Exceptions
| Type | Condition | 
|---|---|
| OperationCanceledException | The operation has been canceled. |