Voting timeout fixes

This commit is contained in:
Raycho Mukelov 2023-10-15 22:33:03 +03:00
parent be86b1d185
commit 14d49d5737
3 changed files with 9 additions and 4 deletions

View File

@ -87,7 +87,10 @@ proc raftNodeStartElection*[SmCommandType, SmStateType](node: RaftNode[SmCommand
withRLock(node.raftStateMutex):
# Wait for votes or voting timeout
await allFutures(node.votesFuts) or raftTimerCreate(node.votingTimeout, proc()=discard)
let all = allFutures(node.votesFuts)
await all or raftTimerCreate(node.votingTimeout, proc()=discard)
if not all.finished:
debug "Raft Node Voting timeout", node_id=node.id
# Process votes (if any)
for voteFut in node.votesFuts:

View File

@ -44,12 +44,14 @@ proc basicRaftClusterClientRequest*(cluster: BasicRaftCluster, req: RaftNodeClie
of rncroExecSmCommand:
discard
proc basicRaftClusterInit*(nodesIds: seq[RaftNodeId], electionTimeout=150, heartBeatTimeout=150): BasicRaftCluster =
proc basicRaftClusterInit*(nodesIds: seq[RaftNodeId], electionTimeout=150, heartBeatTimeout=150, appendEntriesTimeout=20, votingTimeout=20): BasicRaftCluster =
new(result)
for nodeId in nodesIds:
var
peersIds = nodesIds
peersIds.del(peersIds.find(nodeId))
result.nodes[nodeId] = BasicRaftNode.new(nodeId, peersIds, basicRaftClusterRaftMessageSendCallbackCreate[SmCommand, SmState](result), electionTimeout, heartBeatTimeout)
result.nodes[nodeId] = BasicRaftNode.new(nodeId, peersIds,
basicRaftClusterRaftMessageSendCallbackCreate[SmCommand, SmState](result),
electionTimeout, heartBeatTimeout, appendEntriesTimeout, votingTimeout)

View File

@ -20,7 +20,7 @@ proc basicClusterElectionMain*() =
test "Basic Raft Cluster Init (5 nodes)":
for i in 0..4:
nodesIds[i] = genUUID()
cluster = basicRaftClusterInit(nodesIds, 150, 150)
cluster = basicRaftClusterInit(nodesIds, 5, 5, 20, 1)
check cluster != nil
test "Start Basic Raft Cluster and wait it to converge for a 2 seconds interval (Elect a Leader)":