mirror of
https://github.com/status-im/nim-raft.git
synced 2025-01-27 05:14:45 +00:00
Delegate timers creation/execution/cancelation to a 3-rd party user supplied library
This commit is contained in:
parent
236e5f32ea
commit
4e333f32b4
@ -67,4 +67,13 @@ proc RaftNodeSmInit[LogEntryDataType, SmStateType](stateMachine: var RaftNodeSta
|
||||
|
||||
proc RaftNodeSmApply[LogEntryDataType, SmStateType](stateMachine: RaftNodeStateMachine[LogEntryDataType, SmStateType], logEntry: LogEntryDataType) =
|
||||
mixin RaftSmApply
|
||||
RaftSmApply(stateMachine, logEntry)
|
||||
RaftSmApply(stateMachine, logEntry)
|
||||
|
||||
# Timer manipulation
|
||||
proc RaftCreateTimer*[TimerDurationType](d: TimerDurationType, repeat: bool, timer_callback: RaftTimerCallback): TimerId = # I guess Duration should be monotonic
|
||||
mixin RaftCreateTimerCustomImpl
|
||||
RaftCreateTimerCustomImpl(d, repeat, timer_callback)
|
||||
|
||||
template RaftCancelTimer*(TimerId) =
|
||||
mixin RaftCancelTimerCustomImpl
|
||||
RaftCancelTimerCustomImpl(TimerId)
|
||||
|
@ -13,6 +13,7 @@
|
||||
import std/locks
|
||||
import stew/results
|
||||
import eth/keyfile
|
||||
import std/sets
|
||||
|
||||
export results
|
||||
|
||||
@ -76,12 +77,14 @@ type
|
||||
senderTerm*: RaftNodeTerm # Sender Raft Node Term
|
||||
peers*: RaftNodePeers # List of Raft Node IDs, which should receive this message
|
||||
|
||||
# Timer types
|
||||
TimerId* = UUID
|
||||
RaftTimerCallback* = proc (timerId: TimerId) {.nimcall, gcsafe.} # Pass any function wrapped in a closure
|
||||
|
||||
# Raft Node Object type
|
||||
RaftNode*[LogEntryDataType, SmStateType] = ref object
|
||||
# Timers
|
||||
votingTimout: uint64
|
||||
heartBeatTimeout: uint64
|
||||
# etc. timers
|
||||
activeTimers: HashSet[TimerId]
|
||||
|
||||
# Mtx definitions go here
|
||||
raftStateMutex: Lock
|
||||
@ -117,4 +120,4 @@ type
|
||||
nextIndex: seq[RaftLogIndex] # For each peer Raft Node, index of the next log entry to send to that Node
|
||||
# (initialized to leader last log index + 1)
|
||||
matchIndex: seq[RaftLogIndex] # For each peer Raft Node, index of highest log entry known to be replicated on Node
|
||||
# (initialized to 0, increases monotonically)
|
||||
# (initialized to 0, increases monotonically)
|
||||
|
Loading…
x
Reference in New Issue
Block a user