From e4033a3f15a8cd7c37fe365dfb9af44703c8cfec Mon Sep 17 00:00:00 2001 From: Raycho Mukelov Date: Sat, 29 Jul 2023 15:54:41 +0300 Subject: [PATCH] Various fixes etc. --- raft_consensus/protocol.nim | 13 +--------- raft_consensus/raft_consensus_api.nim | 17 +++++++++++-- raft_consensus/types.nim | 35 ++++++++++++++++++--------- tests/all_tests.nim | 1 - 4 files changed, 40 insertions(+), 26 deletions(-) diff --git a/raft_consensus/protocol.nim b/raft_consensus/protocol.nim index 8723cd8..30185ee 100644 --- a/raft_consensus/protocol.nim +++ b/raft_consensus/protocol.nim @@ -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, diff --git a/raft_consensus/raft_consensus_api.nim b/raft_consensus/raft_consensus_api.nim index 6ede476..6769039 100644 --- a/raft_consensus/raft_consensus_api.nim +++ b/raft_consensus/raft_consensus_api.nim @@ -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 @@ -45,4 +48,14 @@ proc RAFTNodeMessageDeliver*(node: RAFTNode, raft_message: RAFTMessageBase): RAF discard proc RAFTNodeRequest*(node: RAFTNode, req: RAFTNodeClientRequest): RAFTNodeClientResponse = # Process RAFTNodeClientRequest - discard \ No newline at end of file + discard + +proc RAFTNodeLogLenGet*(node: RAFTNode): RAFTLogIndex = + discard + +proc RAFTNodeLogentryGet*(node: RAFTLogIndex): Result[RAFTNodeLogEntry, string] = + discard + +proc RAFTNodeStateMachineStateGet*(node: RAFTNode): RAFTNodeStateMachineState = + discard + diff --git a/raft_consensus/types.nim b/raft_consensus/types.nim index be2b494..9753db0 100644 --- a/raft_consensus/types.nim +++ b/raft_consensus/types.nim @@ -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 diff --git a/tests/all_tests.nim b/tests/all_tests.nim index 92b84b9..c4e0a10 100644 --- a/tests/all_tests.nim +++ b/tests/all_tests.nim @@ -6,4 +6,3 @@ # at your option. # This file may not be copied, modified, or distributed except according to # those terms. -