Show / Hide Table of Contents

Class RaftCluster<TMember>

Represents transport-independent implementation of Raft protocol.

Inheritance
Object
Disposable
RaftCluster<TMember>
RaftCluster
Implements
IDisposable
IRaftCluster
IReplicationCluster<IRaftLogEntry>
IReplicationCluster
ICluster
Inherited Members
Disposable.IsDisposed
Disposable.ThrowIfDisposed()
Disposable.DisposedTask
Disposable.GetDisposedTask<T>()
Disposable.TrySetDisposedException<T>(TaskCompletionSource<T>)
Disposable.Dispose()
Disposable.QueueDispose(IDisposable)
Disposable.Dispose(IEnumerable<IDisposable>)
Disposable.DisposeAsync(IEnumerable<IAsyncDisposable>)
Disposable.Dispose(IDisposable[])
Disposable.DisposeAsync(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 RaftCluster<TMember> : Disposable, IDisposable, IRaftCluster, IReplicationCluster<IRaftLogEntry>, IReplicationCluster, ICluster, IRaftStateMachine where TMember : class, IRaftClusterMember, IDisposable
Type Parameters
Name Description
TMember

The type implementing communication details with remote nodes.

Constructors

| Improve this Doc View Source

RaftCluster(IClusterMemberConfiguration, out RaftCluster<TMember>.MemberCollectionBuilder)

Initializes a new cluster manager for the local node.

Declaration
protected RaftCluster(IClusterMemberConfiguration config, out RaftCluster<TMember>.MemberCollectionBuilder members)
Parameters
Type Name Description
IClusterMemberConfiguration config

The configuration of the local node.

RaftCluster.MemberCollectionBuilder<> members

The collection of members that can be modified at construction stage.

Properties

| Improve this Doc View Source

AuditTrail

Associates audit trail with the current instance.

Declaration
public IPersistentState AuditTrail { get; set; }
Property Value
Type Description
IPersistentState
Exceptions
Type Condition
ArgumentNullException

value is null.

| Improve this Doc View Source

IsLeaderLocal

Indicates that local member is a leader.

Declaration
protected bool IsLeaderLocal { get; }
Property Value
Type Description
Boolean
| Improve this Doc View Source

Leader

Gets leader of the cluster.

Declaration
public TMember Leader { get; }
Property Value
Type Description
TMember
| Improve this Doc View Source

Logger

Gets logger used by this object.

Declaration
[CLSCompliant(false)]
protected virtual ILogger Logger { get; }
Property Value
Type Description
ILogger
| Improve this Doc View Source

Members

Gets members of Raft-based cluster.

Declaration
public IReadOnlyCollection<TMember> Members { get; }
Property Value
Type Description
IReadOnlyCollection<TMember>

A collection of cluster member.

| Improve this Doc View Source

Metrics

Establishes metrics collector.

Declaration
public MetricsCollector Metrics { protected get; set; }
Property Value
Type Description
MetricsCollector
| Improve this Doc View Source

Term

Gets Term value maintained by local member.

Declaration
public long Term { get; }
Property Value
Type Description
Int64
| Improve this Doc View Source

Token

Gets token that can be used for all internal asynchronous operations.

Declaration
protected CancellationToken Token { get; }
Property Value
Type Description
CancellationToken

Methods

| Improve this Doc View Source

ChangeMembersAsync(RaftCluster<TMember>.MemberCollectionMutator)

Modifies collection of cluster members.

Declaration
protected Task ChangeMembersAsync(RaftCluster<TMember>.MemberCollectionMutator mutator)
Parameters
Type Name Description
RaftCluster.MemberCollectionMutator<> mutator

The action that can be used to change set of cluster members.

Returns
Type Description
Task

The task representing asynchronous execution of this method.

| Improve this Doc View Source

ChangeMembersAsync(RaftCluster<TMember>.MemberCollectionMutator, CancellationToken)

Modifies collection of cluster members.

Declaration
protected Task ChangeMembersAsync(RaftCluster<TMember>.MemberCollectionMutator mutator, CancellationToken token)
Parameters
Type Name Description
RaftCluster.MemberCollectionMutator<> mutator

The action that can be used to change set of cluster members.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
Task

The task representing asynchronous execution of this method.

| Improve this Doc View Source

Dispose(Boolean)

Releases managed and unmanaged resources associated with this object.

Declaration
protected override void Dispose(bool disposing)
Parameters
Type Name Description
Boolean disposing

true if called from Dispose(); false if called from finalizer Finalize().

Overrides
Disposable.Dispose(Boolean)
| Improve this Doc View Source

FindMember(Predicate<TMember>)

Finds cluster member using predicate.

Declaration
protected TMember FindMember(Predicate<TMember> criteria)
Parameters
Type Name Description
Predicate<TMember> criteria

The predicate used to find appropriate member.

Returns
Type Description
TMember

The cluster member; or null if there is not member matching to the specified criteria.

| Improve this Doc View Source

FindMember<TArg>(Func<TMember, TArg, Boolean>, TArg)

Finds cluster member using predicate.

Declaration
protected TMember FindMember<TArg>(Func<TMember, TArg, bool> criteria, TArg arg)
Parameters
Type Name Description
Func<TMember, TArg, Boolean> criteria

The predicate used to find appropriate member.

TArg arg

The argument to be passed to the matching function.

Returns
Type Description
TMember

The cluster member; or null if member doesn't exist.

Type Parameters
Name Description
TArg

The type of the predicate parameter.

| Improve this Doc View Source

ForceReplicationAsync(TimeSpan, CancellationToken)

Forces replication.

Declaration
public Task<bool> ForceReplicationAsync(TimeSpan timeout, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
TimeSpan timeout

The time to wait until replication ends.

CancellationToken token

The token that can be used to cancel waiting.

Returns
Type Description
Task<Boolean>

true if replication is completed; false.

Exceptions
Type Condition
InvalidOperationException

The local cluster member is not a leader.

OperationCanceledException

The operation has been canceled.

| Improve this Doc View Source

ReceiveEntries<TEntry>(TMember, Int64, ILogEntryProducer<TEntry>, Int64, Int64, Int64)

Handles AppendEntries message received from remote cluster member.

Declaration
[Obsolete("Use ReceiveEntriesAsync method instead")]
protected Task<Result<bool>> ReceiveEntries<TEntry>(TMember sender, long senderTerm, ILogEntryProducer<TEntry> entries, long prevLogIndex, long prevLogTerm, long commitIndex)

    where TEntry : IRaftLogEntry
Parameters
Type Name Description
TMember sender

The sender of the replica message.

Int64 senderTerm

Term value provided by Heartbeat message sender.

ILogEntryProducer<TEntry> entries

The stateful function that provides entries to be committed locally.

Int64 prevLogIndex

Index of log entry immediately preceding new ones.

Int64 prevLogTerm

Term of prevLogIndex entry.

Int64 commitIndex

The last entry known to be committed on the sender side.

Returns
Type Description
Task<Result<Boolean>>

true if log entry is committed successfully; false if preceding is not present in local audit trail.

Type Parameters
Name Description
TEntry

The actual type of the log entry returned by the supplier.

| Improve this Doc View Source

ReceiveEntriesAsync<TEntry>(TMember, Int64, ILogEntryProducer<TEntry>, Int64, Int64, Int64, CancellationToken)

Handles AppendEntries message received from remote cluster member.

Declaration
protected Task<Result<bool>> ReceiveEntriesAsync<TEntry>(TMember sender, long senderTerm, ILogEntryProducer<TEntry> entries, long prevLogIndex, long prevLogTerm, long commitIndex, CancellationToken token)

    where TEntry : IRaftLogEntry
Parameters
Type Name Description
TMember sender

The sender of the replica message.

Int64 senderTerm

Term value provided by Heartbeat message sender.

ILogEntryProducer<TEntry> entries

The stateful function that provides entries to be committed locally.

Int64 prevLogIndex

Index of log entry immediately preceding new ones.

Int64 prevLogTerm

Term of prevLogIndex entry.

Int64 commitIndex

The last entry known to be committed on the sender side.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
Task<Result<Boolean>>

true if log entry is committed successfully; false if preceding is not present in local audit trail.

Type Parameters
Name Description
TEntry

The actual type of the log entry returned by the supplier.

| Improve this Doc View Source

ReceiveResign()

Revokes leadership of the local node.

Declaration
[Obsolete("Use ReceiveResignAsync method instead")]
protected Task<bool> ReceiveResign()
Returns
Type Description
Task<Boolean>

true, if leadership is revoked successfully; otherwise, false.

| Improve this Doc View Source

ReceiveResignAsync(CancellationToken)

Revokes leadership of the local node.

Declaration
protected Task<bool> ReceiveResignAsync(CancellationToken token)
Parameters
Type Name Description
CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
Task<Boolean>

true, if leadership is revoked successfully; otherwise, false.

| Improve this Doc View Source

ReceiveSnapshot(TMember, Int64, IRaftLogEntry, Int64)

Handles InstallSnapshot message received from remote cluster member.

Declaration
[Obsolete("Use ReceiveSnapshotAsync method instead")]
protected Task<Result<bool>> ReceiveSnapshot(TMember sender, long senderTerm, IRaftLogEntry snapshot, long snapshotIndex)
Parameters
Type Name Description
TMember sender

The sender of the snapshot message.

Int64 senderTerm

Term value provided by InstallSnapshot message sender.

IRaftLogEntry snapshot

The snapshot to be installed into local audit trail.

Int64 snapshotIndex

The index of the last log entry included in the snapshot.

Returns
Type Description
Task<Result<Boolean>>

true if snapshot is installed successfully; false if snapshot is outdated.

| Improve this Doc View Source

ReceiveSnapshotAsync<TSnapshot>(TMember, Int64, TSnapshot, Int64, CancellationToken)

Handles InstallSnapshot message received from remote cluster member.

Declaration
protected Task<Result<bool>> ReceiveSnapshotAsync<TSnapshot>(TMember sender, long senderTerm, TSnapshot snapshot, long snapshotIndex, CancellationToken token)

    where TSnapshot : IRaftLogEntry
Parameters
Type Name Description
TMember sender

The sender of the snapshot message.

Int64 senderTerm

Term value provided by InstallSnapshot message sender.

TSnapshot snapshot

The snapshot to be installed into local audit trail.

Int64 snapshotIndex

The index of the last log entry included in the snapshot.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
Task<Result<Boolean>>

true if snapshot is installed successfully; false if snapshot is outdated.

Type Parameters
Name Description
TSnapshot

The type of snapshot record.

| Improve this Doc View Source

ReceiveVote(TMember, Int64, Int64, Int64)

Votes for the new candidate.

Declaration
[Obsolete("Use ReceiveVoteAsync method instead")]
protected Task<Result<bool>> ReceiveVote(TMember sender, long senderTerm, long lastLogIndex, long lastLogTerm)
Parameters
Type Name Description
TMember sender

The vote sender.

Int64 senderTerm

Term value provided by sender of the request.

Int64 lastLogIndex

Index of candidate's last log entry.

Int64 lastLogTerm

Term of candidate's last log entry.

Returns
Type Description
Task<Result<Boolean>>

true if local node accepts new leader in the cluster; otherwise, false.

| Improve this Doc View Source

ReceiveVoteAsync(TMember, Int64, Int64, Int64, CancellationToken)

Votes for the new candidate.

Declaration
protected Task<Result<bool>> ReceiveVoteAsync(TMember sender, long senderTerm, long lastLogIndex, long lastLogTerm, CancellationToken token)
Parameters
Type Name Description
TMember sender

The vote sender.

Int64 senderTerm

Term value provided by sender of the request.

Int64 lastLogIndex

Index of candidate's last log entry.

Int64 lastLogTerm

Term of candidate's last log entry.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
Task<Result<Boolean>>

true if local node accepts new leader in the cluster; otherwise, false.

| Improve this Doc View Source

StartAsync(CancellationToken)

Starts serving local member.

Declaration
public virtual Task StartAsync(CancellationToken token)
Parameters
Type Name Description
CancellationToken token

The token that can be used to cancel initialization process.

Returns
Type Description
Task

The task representing asynchronous execution of the method.

| Improve this Doc View Source

StopAsync(CancellationToken)

Stops serving local member.

Declaration
public virtual Task StopAsync(CancellationToken token)
Parameters
Type Name Description
CancellationToken token

The token that can be used to cancel shutdown process.

Returns
Type Description
Task

The task representing asynchronous execution of the method.

Events

| Improve this Doc View Source

LeaderChanged

An event raised when leader has been changed.

Declaration
public event ClusterLeaderChangedEventHandler LeaderChanged
Event Type
Type Description
ClusterLeaderChangedEventHandler

Explicit Interface Implementations

| Improve this Doc View Source

IRaftCluster.ElectionTimeout

Declaration
TimeSpan IRaftCluster.ElectionTimeout { get; }
Returns
Type Description
TimeSpan
| Improve this Doc View Source

ICluster.Leader

Declaration
IClusterMember ICluster.Leader { get; }
Returns
Type Description
IClusterMember
| Improve this Doc View Source

ICluster.Members

Declaration
IReadOnlyCollection<IClusterMember> ICluster.Members { get; }
Returns
Type Description
IReadOnlyCollection<IClusterMember>
| Improve this Doc View Source

ICluster.ResignAsync(CancellationToken)

Declaration
Task<bool> ICluster.ResignAsync(CancellationToken token)
Parameters
Type Name Description
CancellationToken token
Returns
Type Description
Task<Boolean>

Implements

System.IDisposable
IRaftCluster
IReplicationCluster<TEntry>
IReplicationCluster
ICluster

Extension Methods

AsyncLockAcquisition.AcquireLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireUpgradeableReadLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireUpgradeableReadLockAsync<T>(T, CancellationToken)
ObjectExtensions.GetUserData<T>(T)
ObjectExtensions.IsOneOf<T>(T, IEnumerable<T>)
ObjectExtensions.IsOneOf<T>(T, T[])
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, Func<T, TResult1>, Func<T, TResult2>, out TResult1, out TResult2)
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, ValueFunc<T, TResult1>, ValueFunc<T, TResult2>, out TResult1, out TResult2)
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, Func<T, TResult1>, Func<T, TResult2>)
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, ValueFunc<T, TResult1>, ValueFunc<T, TResult2>)
ObjectExtensions.As<T>(T)
LockAcquisition.AcquireReadLock<T>(T)
LockAcquisition.AcquireReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireWriteLock<T>(T)
LockAcquisition.AcquireWriteLock<T>(T, TimeSpan)
LockAcquisition.AcquireUpgradeableReadLock<T>(T)
LockAcquisition.AcquireUpgradeableReadLock<T>(T, TimeSpan)
ExpressionBuilder.Const<T>(T)
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX