diff --git a/src/main.rs b/src/main.rs index 2c8033ef85e071ccaefbd6145ad5f0c8ecc764df..57cd484c0e64b5afa14c995179378c88be48ee9d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -454,7 +454,7 @@ fn start_boot(args: &args::Run) { fn start_join(args: &args::Run, leader_address: String) { tlog!(Info, ">>>>> start_join({leader_address})"); - let req = traft::node::JoinRequest { + let req = traft::JoinRequest { instance_id: args.instance_id.clone(), replicaset_id: args.replicaset_id.clone(), voter: false, @@ -463,8 +463,7 @@ fn start_join(args: &args::Run, leader_address: String) { use traft::node::raft_join; let fn_name = stringify_cfunc!(raft_join); - let resp: traft::node::JoinResponse = - tarantool::net_box_call_retry(&leader_address, fn_name, &req); + let resp: traft::JoinResponse = tarantool::net_box_call_retry(&leader_address, fn_name, &req); picolib_setup(args); assert!(tarantool::cfg().is_none()); @@ -564,7 +563,7 @@ fn postjoin(args: &args::Run) { } tlog!(Warning, "initiating self-promotion of {me:?}"); - let req = traft::node::JoinRequest { + let req = traft::JoinRequest { instance_id: me.instance_id.clone(), replicaset_id: None, // TODO voter: true, @@ -583,7 +582,7 @@ fn postjoin(args: &args::Run) { fiber::sleep(timeout.saturating_sub(now.elapsed())); continue; } - Ok(traft::node::JoinResponse { .. }) => { + Ok(traft::JoinResponse { .. }) => { break; } }; diff --git a/src/traft/mod.rs b/src/traft/mod.rs index 04cedc3230663b2a188a6419a547c77ea5403ca5..0a246a6a5f5865413cb63e387d5b7bfd9a8e39c9 100644 --- a/src/traft/mod.rs +++ b/src/traft/mod.rs @@ -269,3 +269,27 @@ pub trait ContextCoercion: Serialize + DeserializeOwned { ContextCoercion::write_to_bytes(Some(self)) } } + +/////////////////////////////////////////////////////////////////////////////// +/// Request to join the cluster. +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct JoinRequest { + pub instance_id: String, + pub replicaset_id: Option<String>, + pub advertise_address: String, + pub voter: bool, +} +impl AsTuple for JoinRequest {} + +/////////////////////////////////////////////////////////////////////////////// +/// Response to a JoinRequest +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct JoinResponse { + pub peer: Peer, + pub raft_group: Vec<Peer>, + pub box_replication: Vec<String>, + // TODO add later: + // Other parameters necessary for box.cfg() + // pub read_only: bool, +} +impl AsTuple for JoinResponse {} diff --git a/src/traft/node.rs b/src/traft/node.rs index d61d71b9452b7b37e053a62a0eee0f7770c7f7d7..d3ce78b2a9daf84e86c7813ac262ef4907806db0 100644 --- a/src/traft/node.rs +++ b/src/traft/node.rs @@ -13,8 +13,6 @@ use ::tarantool::fiber; use ::tarantool::proc; use ::tarantool::tlua; use ::tarantool::transaction::start_transaction; -use ::tarantool::tuple::AsTuple; -use serde::{Deserialize, Serialize}; use std::cell::RefCell; use std::collections::HashMap; use std::convert::TryFrom; @@ -35,6 +33,7 @@ use crate::traft; use crate::traft::ConnectionPool; use crate::traft::LogicalClock; use crate::traft::Storage; +use crate::traft::{JoinRequest, JoinResponse}; type RawNode = raft::RawNode<Storage>; type Notify = fiber::Channel<Result<u64, RaftError>>; @@ -616,26 +615,6 @@ fn raft_main_loop( } } -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct JoinRequest { - pub instance_id: String, - pub replicaset_id: Option<String>, - pub advertise_address: String, - pub voter: bool, -} -impl AsTuple for JoinRequest {} - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct JoinResponse { - pub peer: traft::Peer, - pub raft_group: Vec<traft::Peer>, - pub box_replication: Vec<String>, - // TODO add later: - // Other parameters necessary for box.cfg() - // pub read_only: bool, -} -impl AsTuple for JoinResponse {} - fn raft_join_loop(inbox: Mailbox<(JoinRequest, Notify)>, main_inbox: Mailbox<NormalRequest>) { loop { let batch = inbox.receive_all(Duration::MAX);