Skip to main content

Creating A Node

RaftManager is the main implementation of IRaft. A node combines configuration, discovery, storage, communication, a hybrid logical clock, partition executors, and fair WAL schedulers.

IRaft raft = new RaftManager(
configuration,
discovery,
walAdapter,
communication,
new HybridLogicalClock(),
logger
);

Use a unique NodeId when possible. If NodeId is 0, Kommander derives one from NodeName.

Core Components

ComponentPurpose
RaftConfigurationLocal node identity, advertised endpoint, timing, and I/O settings.
IDiscoveryProvides the other visible nodes in the cluster.
IWALPersists proposed, committed, rolled-back, and checkpoint log entries.
ICommunicationSends Raft protocol messages to remote nodes.
HybridLogicalClockProduces proposal ticket timestamps.
Partition executorsRun each partition state machine serially so Raft state has one owner.
ReadScheduler / WalSchedulerRun synchronous WAL reads and writes on fair, partition-aware worker queues.

Lifecycle

Call JoinCluster after subscribing to restore and replication callbacks:

raft.OnLogRestored += RestoreLog;
raft.OnReplicationReceived += ApplyCommittedLog;

using CancellationTokenSource joinTimeout = new(TimeSpan.FromSeconds(30));
await raft.JoinCluster(joinTimeout.Token);

If you do not pass your own cancellation token, JoinCluster still uses an internal 60-second timeout while waiting for the system partition to initialize user partitions.

Call LeaveCluster when shutting down:

await raft.LeaveCluster(dispose: true);

Cluster Visibility

Use GetNodes, GetLocalEndpoint, GetLocalNodeId, and GetLocalNodeName to inspect the local view:

IList<RaftNode> visibleNodes = raft.GetNodes();
string endpoint = raft.GetLocalEndpoint();
int nodeId = raft.GetLocalNodeId();