From 3990c09e1f1e03a182c60bea120cbaf87e318d4d Mon Sep 17 00:00:00 2001 From: Georgy Moshkin <gmoshkin@picodata.io> Date: Wed, 21 Sep 2022 18:33:12 +0300 Subject: [PATCH] feat(rpc): traft::rpc::Request trait --- src/tarantool.rs | 2 +- src/traft/mod.rs | 1 + src/traft/rpc.rs | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/traft/rpc.rs diff --git a/src/tarantool.rs b/src/tarantool.rs index c5a2228135..a16377451b 100644 --- a/src/tarantool.rs +++ b/src/tarantool.rs @@ -26,7 +26,7 @@ macro_rules! stringify_cfunc { use ::tarantool::tuple::FunctionCtx; use libc::c_int; - let _: unsafe extern "C" fn(FunctionCtx, FunctionArgs) -> c_int = $($func_name)+; + const _: unsafe extern "C" fn(FunctionCtx, FunctionArgs) -> c_int = $($func_name)+; concat!(".", $crate::stringify_last_token!($($func_name)+)) }}; } diff --git a/src/traft/mod.rs b/src/traft/mod.rs index 87f2d8e4e4..00713a0f4b 100644 --- a/src/traft/mod.rs +++ b/src/traft/mod.rs @@ -7,6 +7,7 @@ mod network; pub mod node; pub mod notify; mod raft_storage; +pub mod rpc; pub mod storage; pub mod topology; diff --git a/src/traft/rpc.rs b/src/traft/rpc.rs new file mode 100644 index 0000000000..daff729485 --- /dev/null +++ b/src/traft/rpc.rs @@ -0,0 +1,33 @@ +use ::tarantool::tuple::{DecodeOwned, Encode}; + +use std::fmt::Debug; + +/// Types implementing this trait represent an RPC's (remote procedure call) +/// arguments. This trait contains information about the request. +pub trait Request: Encode + DecodeOwned { + /// Remote procedure name. + const PROC_NAME: &'static str; + + /// Describes data returned from a successful RPC request. + type Response: Encode + DecodeOwned + Debug + 'static; +} + +impl Request for super::JoinRequest { + const PROC_NAME: &'static str = crate::stringify_cfunc!(super::node::raft_join); + type Response = super::JoinResponse; +} + +impl Request for super::UpdatePeerRequest { + const PROC_NAME: &'static str = crate::stringify_cfunc!(super::failover::raft_update_peer); + type Response = super::UpdatePeerResponse; +} + +impl Request for super::ExpelRequest { + const PROC_NAME: &'static str = crate::stringify_cfunc!(super::node::raft_expel); + type Response = super::ExpelResponse; +} + +impl Request for super::SyncRaftRequest { + const PROC_NAME: &'static str = crate::stringify_cfunc!(super::node::raft_sync_raft); + type Response = (); +} -- GitLab