Fix compilation
This commit is contained in:
parent
ca099c6132
commit
5bd50081da
|
@ -11,7 +11,7 @@ import chronos
|
||||||
|
|
||||||
template awaitWithTimeout*[T](operation: Future[T],
|
template awaitWithTimeout*[T](operation: Future[T],
|
||||||
deadline: Future[void],
|
deadline: Future[void],
|
||||||
body: untyped): T =
|
body: untyped) =
|
||||||
let f {.inject.} = operation
|
let f {.inject.} = operation
|
||||||
await f or deadline
|
await f or deadline
|
||||||
if not f.finished:
|
if not f.finished:
|
||||||
|
|
|
@ -136,8 +136,8 @@ proc raftNodeHandleAppendEntries*[SmCommandType, SmStateType](node: RaftNode[SmC
|
||||||
raftNodeLogTruncate(node, msg.prevLogIndex)
|
raftNodeLogTruncate(node, msg.prevLogIndex)
|
||||||
return
|
return
|
||||||
|
|
||||||
if msg.entries.len > 0:
|
if msg.logEntries.isSome:
|
||||||
for entry in msg.entries:
|
for entry in msg.logEntries.get:
|
||||||
raftNodeLogAppend(node, entry)
|
raftNodeLogAppend(node, entry)
|
||||||
|
|
||||||
if msg.commitIndex > node.commitIndex:
|
if msg.commitIndex > node.commitIndex:
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
# those terms.
|
# those terms.
|
||||||
|
|
||||||
import types
|
import types
|
||||||
|
import chronicles
|
||||||
|
|
||||||
# Private Log Ops
|
# Private Log Ops
|
||||||
proc raftNodeLogIndexGet*[SmCommandType, SmStateType](node: RaftNode[SmCommandType, SmStateType]): RaftLogIndex =
|
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]) =
|
proc raftNodeLogAppend*[SmCommandType, SmStateType](node: RaftNode[SmCommandType, SmStateType], logEntry: RaftNodeLogEntry[SmCommandType]) =
|
||||||
node.log.logData.add(logEntry)
|
node.log.logData.add(logEntry)
|
||||||
|
|
||||||
proc raftNodeLogTruncate*[SmCommandType, SmStateType](node: RaftNode[SmCommandType, SmStateType], truncateIndex: uint64) =
|
proc raftNodeLogTruncate*[SmCommandType, SmStateType](node: RaftNode[SmCommandType, SmStateType], truncateIndex: RaftLogIndex) =
|
||||||
node.log.logData.truncate(truncateIndex)
|
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]) =
|
proc raftNodeApplyLogEntry*[SmCommandType, SmStateType](node: RaftNode[SmCommandType, SmStateType], logEntry: RaftNodeLogEntry[SmCommandType]) =
|
||||||
mixin raftNodeSmApply
|
mixin raftNodeSmApply
|
||||||
|
|
||||||
raftNodeSmApply(node.stateMachine, logEntry.command)
|
raftNodeSmApply(node.stateMachine, logEntry.data.get)
|
|
@ -23,7 +23,7 @@ export
|
||||||
chronicles
|
chronicles
|
||||||
|
|
||||||
# Forward declarations
|
# Forward declarations
|
||||||
proc raftNodeSmInit[SmCommandType, SmStateType](stateMachine: var RaftNodeStateMachine[SmCommandType, SmStateType])
|
proc raftNodeSmInit*[SmCommandType, SmStateType](stateMachine: var RaftNodeStateMachine[SmCommandType, SmStateType])
|
||||||
|
|
||||||
# Raft Node Public API
|
# Raft Node Public API
|
||||||
proc new*[SmCommandType, SmStateType](T: type RaftNode[SmCommandType, SmStateType];
|
proc new*[SmCommandType, SmStateType](T: type RaftNode[SmCommandType, SmStateType];
|
||||||
|
@ -112,16 +112,14 @@ func raftNodeSmStateGet*[SmCommandType, SmStateType](node: RaftNode[SmCommandTyp
|
||||||
withRLock(node.raftStateMutex):
|
withRLock(node.raftStateMutex):
|
||||||
node.stateMachine.state
|
node.stateMachine.state
|
||||||
|
|
||||||
proc raftNodeSmInit[SmCommandType, SmStateType](stateMachine: var RaftNodeStateMachine[SmCommandType, SmStateType]) =
|
proc raftNodeSmInit*[SmCommandType, SmStateType](stateMachine: var RaftNodeStateMachine[SmCommandType, SmStateType]) =
|
||||||
mixin raftSmInit
|
mixin raftSmInit
|
||||||
|
|
||||||
withRLock(node.raftStateMutex):
|
|
||||||
raftSmInit(stateMachine)
|
raftSmInit(stateMachine)
|
||||||
|
|
||||||
proc raftNodeSmApply[SmCommandType, SmStateType](stateMachine: RaftNodeStateMachine[SmCommandType, SmStateType], command: SmCommandType) =
|
proc raftNodeSmApply*[SmCommandType, SmStateType](stateMachine: RaftNodeStateMachine[SmCommandType, SmStateType], command: SmCommandType) =
|
||||||
mixin raftSmApply
|
mixin raftSmApply
|
||||||
|
|
||||||
withRLock(node.raftStateMutex):
|
|
||||||
raftSmApply(stateMachine, command)
|
raftSmApply(stateMachine, command)
|
||||||
|
|
||||||
# Private Abstract Timer creation
|
# Private Abstract Timer creation
|
||||||
|
|
|
@ -44,7 +44,7 @@ proc basicRaftClusterClientRequest*(cluster: BasicRaftCluster, req: RaftNodeClie
|
||||||
of rncroExecSmCommand:
|
of rncroExecSmCommand:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
proc basicRaftClusterInit*(nodesIds: seq[RaftNodeId], electionTimeout=5, heartBeatTimeout=5): BasicRaftCluster =
|
proc basicRaftClusterInit*(nodesIds: seq[RaftNodeId], electionTimeout=150, heartBeatTimeout=150): BasicRaftCluster =
|
||||||
new(result)
|
new(result)
|
||||||
for nodeId in nodesIds:
|
for nodeId in nodesIds:
|
||||||
var
|
var
|
||||||
|
|
|
@ -20,7 +20,7 @@ proc basicClusterElectionMain*() =
|
||||||
test "Basic Raft Cluster Init (5 nodes)":
|
test "Basic Raft Cluster Init (5 nodes)":
|
||||||
for i in 0..4:
|
for i in 0..4:
|
||||||
nodesIds[i] = genUUID()
|
nodesIds[i] = genUUID()
|
||||||
cluster = basicRaftClusterInit(nodesIds, 3, 3)
|
cluster = basicRaftClusterInit(nodesIds, 150, 150)
|
||||||
check cluster != nil
|
check cluster != nil
|
||||||
|
|
||||||
test "Start Basic Raft Cluster and wait it to converge for a 2 seconds interval (Elect a Leader)":
|
test "Start Basic Raft Cluster and wait it to converge for a 2 seconds interval (Elect a Leader)":
|
||||||
|
|
Loading…
Reference in New Issue