fix
This commit is contained in:
parent
14d49d5737
commit
dfaf67f9ef
|
@ -172,3 +172,7 @@ proc raftNodeReplicateSmCommand*[SmCommandType, SmStateType](node: RaftNode[SmCo
|
|||
)
|
||||
|
||||
node.replicateFuts.add(node.msgSendCallback(msg))
|
||||
|
||||
node.commitIndex.inc
|
||||
raftNodeApplyLogEntry(node, raftNodeLogEntryGet(node, node.commitIndex)) # Apply to state machine
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ type
|
|||
|
||||
BasicRaftCluster* = ref object
|
||||
nodes*: Table[RaftNodeId, BasicRaftNode]
|
||||
nodesLock*: RLock
|
||||
|
||||
proc basicRaftClusterRaftMessageSendCallbackCreate[SmCommandType, SmStateType](cluster: BasicRaftCluster): RaftMessageSendCallback[SmCommandType, SmStateType] =
|
||||
proc (msg: RaftMessageBase[SmCommandType, SmStateType]): Future[RaftMessageResponseBase[SmCommandType, SmStateType]] {.async, gcsafe.} =
|
||||
|
@ -29,6 +30,7 @@ proc basicRaftClusterStart*(cluster: BasicRaftCluster) =
|
|||
|
||||
proc basicRaftClusterGetLeaderId*(cluster: BasicRaftCluster): UUID =
|
||||
result = DefaultUUID
|
||||
withRLock(cluster.nodesLock):
|
||||
for id, node in cluster.nodes:
|
||||
if raftNodeIsLeader(node):
|
||||
return raftNodeIdGet(node)
|
||||
|
|
|
@ -20,7 +20,7 @@ proc basicClusterElectionMain*() =
|
|||
test "Basic Raft Cluster Init (5 nodes)":
|
||||
for i in 0..4:
|
||||
nodesIds[i] = genUUID()
|
||||
cluster = basicRaftClusterInit(nodesIds, 5, 5, 20, 1)
|
||||
cluster = basicRaftClusterInit(nodesIds, 150, 150, 20, 20)
|
||||
check cluster != nil
|
||||
|
||||
test "Start Basic Raft Cluster and wait it to converge for a 2 seconds interval (Elect a Leader)":
|
||||
|
|
Loading…
Reference in New Issue