Fix compilation

This commit is contained in:
Raycho Mukelov 2023-10-13 09:03:42 +03:00
parent ca099c6132
commit 5bd50081da
7 changed files with 19 additions and 19 deletions

View File

@ -11,7 +11,7 @@ import chronos
template awaitWithTimeout*[T](operation: Future[T],
deadline: Future[void],
body: untyped): T =
body: untyped) =
let f {.inject.} = operation
await f or deadline
if not f.finished:

View File

@ -136,8 +136,8 @@ proc raftNodeHandleAppendEntries*[SmCommandType, SmStateType](node: RaftNode[SmC
raftNodeLogTruncate(node, msg.prevLogIndex)
return
if msg.entries.len > 0:
for entry in msg.entries:
if msg.logEntries.isSome:
for entry in msg.logEntries.get:
raftNodeLogAppend(node, entry)
if msg.commitIndex > node.commitIndex:

View File

@ -8,6 +8,7 @@
# those terms.
import types
import chronicles
# Private Log Ops
proc raftNodeLogIndexGet*[SmCommandType, SmStateType](node: RaftNode[SmCommandType, SmStateType]): RaftLogIndex =
@ -20,10 +21,11 @@ proc raftNodeLogEntryGet*[SmCommandType, SmStateType](node: RaftNode[SmCommandTy
proc raftNodeLogAppend*[SmCommandType, SmStateType](node: RaftNode[SmCommandType, SmStateType], logEntry: RaftNodeLogEntry[SmCommandType]) =
node.log.logData.add(logEntry)
proc raftNodeLogTruncate*[SmCommandType, SmStateType](node: RaftNode[SmCommandType, SmStateType], truncateIndex: uint64) =
node.log.logData.truncate(truncateIndex)
proc raftNodeLogTruncate*[SmCommandType, SmStateType](node: RaftNode[SmCommandType, SmStateType], truncateIndex: RaftLogIndex) =
debug "Truncating log to index: ", truncateIndex=truncateIndex, ld=repr(node.log.logData)
# node.log.logData = node.log.logData[:truncateIndex]
proc raftNodeApplyLogEntry*[SmCommandType, SmStateType](node: RaftNode[SmCommandType, SmStateType], logEntry: RaftNodeLogEntry[SmCommandType]) =
mixin raftNodeSmApply
raftNodeSmApply(node.stateMachine, logEntry.command)
raftNodeSmApply(node.stateMachine, logEntry.data.get)

View File

@ -23,7 +23,7 @@ export
chronicles
# Forward declarations
proc raftNodeSmInit[SmCommandType, SmStateType](stateMachine: var RaftNodeStateMachine[SmCommandType, SmStateType])
proc raftNodeSmInit*[SmCommandType, SmStateType](stateMachine: var RaftNodeStateMachine[SmCommandType, SmStateType])
# Raft Node Public API
proc new*[SmCommandType, SmStateType](T: type RaftNode[SmCommandType, SmStateType];
@ -112,16 +112,14 @@ func raftNodeSmStateGet*[SmCommandType, SmStateType](node: RaftNode[SmCommandTyp
withRLock(node.raftStateMutex):
node.stateMachine.state
proc raftNodeSmInit[SmCommandType, SmStateType](stateMachine: var RaftNodeStateMachine[SmCommandType, SmStateType]) =
proc raftNodeSmInit*[SmCommandType, SmStateType](stateMachine: var RaftNodeStateMachine[SmCommandType, SmStateType]) =
mixin raftSmInit
withRLock(node.raftStateMutex):
raftSmInit(stateMachine)
proc raftNodeSmApply[SmCommandType, SmStateType](stateMachine: RaftNodeStateMachine[SmCommandType, SmStateType], command: SmCommandType) =
proc raftNodeSmApply*[SmCommandType, SmStateType](stateMachine: RaftNodeStateMachine[SmCommandType, SmStateType], command: SmCommandType) =
mixin raftSmApply
withRLock(node.raftStateMutex):
raftSmApply(stateMachine, command)
# Private Abstract Timer creation

View File

@ -44,7 +44,7 @@ proc basicRaftClusterClientRequest*(cluster: BasicRaftCluster, req: RaftNodeClie
of rncroExecSmCommand:
discard
proc basicRaftClusterInit*(nodesIds: seq[RaftNodeId], electionTimeout=5, heartBeatTimeout=5): BasicRaftCluster =
proc basicRaftClusterInit*(nodesIds: seq[RaftNodeId], electionTimeout=150, heartBeatTimeout=150): BasicRaftCluster =
new(result)
for nodeId in nodesIds:
var

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, 3, 3)
cluster = basicRaftClusterInit(nodesIds, 150, 150)
check cluster != nil
test "Start Basic Raft Cluster and wait it to converge for a 2 seconds interval (Elect a Leader)":