11/* *
2- * @file raft_node .hpp
3- * @brief Raft consensus node implementation
2+ * @file raft_group .hpp
3+ * @brief Raft consensus group implementation
44 */
55
6- #ifndef SQL_ENGINE_DISTRIBUTED_RAFT_NODE_HPP
7- #define SQL_ENGINE_DISTRIBUTED_RAFT_NODE_HPP
6+ #ifndef SQL_ENGINE_DISTRIBUTED_RAFT_GROUP_HPP
7+ #define SQL_ENGINE_DISTRIBUTED_RAFT_GROUP_HPP
88
99#include < atomic>
1010#include < chrono>
2222namespace cloudsql ::raft {
2323
2424/* *
25- * @brief Implementation of a Raft consensus node
25+ * @brief Implementation of a Raft consensus group
2626 */
27- class RaftNode {
27+ class RaftGroup {
2828 public:
29- RaftNode ( std::string node_id, cluster::ClusterManager& cluster_manager,
30- network::RpcServer& rpc_server);
31- ~RaftNode ();
29+ RaftGroup ( uint16_t group_id, std::string node_id, cluster::ClusterManager& cluster_manager,
30+ network::RpcServer& rpc_server);
31+ ~RaftGroup ();
3232
3333 // Prevent copying and moving
34- RaftNode (const RaftNode &) = delete ;
35- RaftNode & operator =(const RaftNode &) = delete ;
36- RaftNode (RaftNode &&) = delete ;
37- RaftNode & operator =(RaftNode &&) = delete ;
34+ RaftGroup (const RaftGroup &) = delete ;
35+ RaftGroup & operator =(const RaftGroup &) = delete ;
36+ RaftGroup (RaftGroup &&) = delete ;
37+ RaftGroup & operator =(RaftGroup &&) = delete ;
3838
3939 void start ();
4040 void stop ();
4141
42- // Raft RPC Handlers
42+ // Raft RPC Handlers (called by RaftManager)
4343 void handle_request_vote (const network::RpcHeader& header, const std::vector<uint8_t >& payload,
4444 int client_fd);
4545 void handle_append_entries (const network::RpcHeader& header,
@@ -48,6 +48,7 @@ class RaftNode {
4848 // Client interface
4949 bool replicate (const std::string& command);
5050 [[nodiscard]] bool is_leader () const { return state_.load () == NodeState::Leader; }
51+ [[nodiscard]] uint16_t group_id () const { return group_id_; }
5152
5253 private:
5354 void run_loop ();
@@ -62,6 +63,7 @@ class RaftNode {
6263 // Helpers
6364 [[nodiscard]] std::chrono::milliseconds get_random_timeout () const ;
6465
66+ uint16_t group_id_;
6567 std::string node_id_;
6668 cluster::ClusterManager& cluster_manager_;
6769 network::RpcServer& rpc_server_;
@@ -83,4 +85,4 @@ class RaftNode {
8385
8486} // namespace cloudsql::raft
8587
86- #endif // SQL_ENGINE_DISTRIBUTED_RAFT_NODE_HPP
88+ #endif // SQL_ENGINE_DISTRIBUTED_RAFT_GROUP_HPP
0 commit comments