Various fixes etc.

This commit is contained in:
Raycho Mukelov 2023-07-29 15:54:41 +03:00
parent e040b84722
commit e4033a3f15
4 changed files with 40 additions and 26 deletions

View File

@ -10,12 +10,10 @@
# #
# RAFT Messages Protocol definition #
# #
import types
type
# RAFT Node Messages definitions
RAFTMessageId* = object # Some Kind of UUID assigned to every RAFT Node Message,
# so it can be matched with it's coresponding response etc.
RAFTMessageOps* = enum
REQUEST_VOTE = 0,
APPEND_LOG_ENTRY = 1,
@ -26,12 +24,6 @@ type
data*: RAFTNodeLogEntry
checksum*: RAFTMessagePayloadChecksum
RAFTMessageBase* = ref object of RootObj # Base Type for RAFT Node Messages
msg_id*: RAFTMessageId # Message UUID
sender_id*: RAFTNodeId # Sender RAFT Node ID
sender_term*: RAFTNodeTerm # Sender RAFT Node Term
peers*: RAFTNodePeers # List of RAFT Node IDs, which should receive this message
RAFTMessage* = ref object of RAFTMessageBase
op*: RAFTMessageOps # Message Op - Ask For Votes, Append Entry(ies) or Install Snapshot
payload*: seq[RAFTMessagePayload] # Message Payload(s) - e.g. log entry(ies) etc. Will be empty for a Heart-Beat # Heart-Beat will be a message with Append Entry(ies) Op and empty payload
@ -39,9 +31,6 @@ type
RAFTMessageResponse* = ref object of RAFTMessageBase
success*: bool # Indicates success/failure
RAFTMessageSendCallback* = proc (raft_message: RAFTMessageBase) {.nimcall, gcsafe.} # Callback for Sending RAFT Node Messages
# out of this RAFT Node. Can be used for broadcasting
# (a Heart-Beat for example)
# RAFT Node Client Request/Response definitions
RAFTNodeClientRequestOps = enum
REQUEST_STATE = 0,

View File

@ -7,7 +7,10 @@
# This file may not be copied, modified, or distributed except according to
# those terms.
import types, protocol
import types
import protocol
import stew
export types, protocol
# RAFT Node Public API procedures / functions
@ -46,3 +49,13 @@ proc RAFTNodeMessageDeliver*(node: RAFTNode, raft_message: RAFTMessageBase): RAF
proc RAFTNodeRequest*(node: RAFTNode, req: RAFTNodeClientRequest): RAFTNodeClientResponse = # Process RAFTNodeClientRequest
discard
proc RAFTNodeLogLenGet*(node: RAFTNode): RAFTLogIndex =
discard
proc RAFTNodeLogentryGet*(node: RAFTLogIndex): Result[RAFTNodeLogEntry, string] =
discard
proc RAFTNodeStateMachineStateGet*(node: RAFTNode): RAFTNodeStateMachineState =
discard

View File

@ -26,14 +26,6 @@ type
RAFTNodeTerm* = uint64 # RAFT Node Term Type
RAFTLogIndex* = uint64 # RAFT Node Log Index Type
# RAFT Node basic Log definitions
RAFTNodeLogEntry* = ref object # Abstarct RAFT Node Log entry containing opaque binary data (Blob)
term*: RAFTNodeTerm
data*: Blob
RAFTNodeLog* = ref object # Needs more elaborate definition. Probably this will be a RocksDB/MDBX/SQLite Store Wrapper etc.
log_data*: seq[RAFTNodeLogEntry] # RAFT Node Log Data
# RAFT Node State Machine basic definitions
RAFTNodeStateMachineState* = object # State Machine State
RAFTNodeStateMachine* = ref object # Some probably opaque State Machine Impelementation to be used by the RAFT Node
@ -56,11 +48,32 @@ type
RAFTMembershipChangeModule* = object of RootObj
raft_node_access_callback: RAFTNodeAccessCallback
# Callback for sending messages out of this RAFT Node
RAFTMessageId* = object # Some Kind of UUID assigned to every RAFT Node Message,
# so it can be matched with it's coresponding response etc.
RAFTMessageSendCallback* = proc (raft_message: RAFTMessageBase) {.nimcall, gcsafe.} # Callback for Sending RAFT Node Messages
# out of this RAFT Node. Can be used for broadcasting
# (a Heart-Beat for example)
RAFTNodeLog* = ref object # Needs more elaborate definition. Probably this will be a RocksDB/MDBX/SQLite Store Wrapper etc.
log_data*: seq[RAFTNodeLogEntry] # RAFT Node Log Data
# RAFT Node basic Log definitions
RAFTNodeLogEntry* = ref object # Abstarct RAFT Node Log entry containing opaque binary data (Blob)
term*: RAFTNodeTerm
data*: Blob
RAFTMessageBase* = ref object of RootObj # Base Type for RAFT Node Messages
msg_id*: RAFTMessageId # Message UUID
sender_id*: RAFTNodeId # Sender RAFT Node ID
sender_term*: RAFTNodeTerm # Sender RAFT Node Term
peers*: RAFTNodePeers # List of RAFT Node IDs, which should receive this message
# RAFT Node Object definitions
RAFTNode* = object
# Timers
voting_timout: nil
heart_beat_timeout: nil
voting_timout: uint64
heart_beat_timeout: uint64
# etc. timers
# Mtx definitions go here
@ -69,7 +82,7 @@ type
raft_comm_mutex_receive_msg: Lock
raft_comm_mutex_client_response: Lock
# Modules
# Modules (Algos)
consensus_module: RAFTConsensusModule
log_compaction_module: RAFTLogCompactionModule
membership_change_module: RAFTMembershipChangeModule

View File

@ -6,4 +6,3 @@
# at your option.
# This file may not be copied, modified, or distributed except according to
# those terms.