From efeb6f3945abed1d5ea3294ede2898c5247133a2 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Sat, 27 May 2023 13:21:32 +0530 Subject: [PATCH] chore: rm client --- src/client.rs | 49 ------------------------------------------------- 1 file changed, 49 deletions(-) diff --git a/src/client.rs b/src/client.rs index a28d130..d18ca10 100644 --- a/src/client.rs +++ b/src/client.rs @@ -41,16 +41,12 @@ use crate::DcacheRequest; pub struct Empty {} pub struct DcacheClient { - /// The leader node to send request to. - /// - /// All traffic should be sent to the leader in a cluster. pub leader: Arc>, pub inner: Client, } impl DcacheClient { - /// Create a client with a leader node id and a node manager to get node address by node id. pub fn new(leader_id: DcacheNodeId, leader_addr: String) -> Self { Self { leader: Arc::new(Mutex::new((leader_id, leader_addr))), @@ -58,14 +54,6 @@ impl DcacheClient { } } - // --- Application API - - /// Submit a write request to the raft cluster. - /// - /// The request will be processed by raft protocol: it will be replicated to a quorum and then - /// will be applied to state machine. - /// - /// The result of applying the request will be returned. pub async fn write( &self, req: &DcacheRequest, @@ -73,16 +61,10 @@ impl DcacheClient { self.send_rpc_to_leader("write", Some(req)).await } - /// Read value by key, in an inconsistent mode. - /// - /// This method may return stale value because it does not force to read on a legal leader. pub async fn read(&self, req: &String) -> Result { self.do_send_rpc_to_leader("read", Some(req)).await } - /// Consistent Read value by key, in an inconsistent mode. - /// - /// This method MUST return consistent value or CheckIsLeaderError. pub async fn consistent_read( &self, req: &String, @@ -91,21 +73,10 @@ impl DcacheClient { .await } - // --- Cluster management API - - /// Initialize a cluster of only the node that receives this request. - /// - /// This is the first step to initialize a cluster. - /// With a initialized cluster, new node can be added with [`write`]. - /// Then setup replication with [`add_learner`]. - /// Then make the new node a member with [`change_membership`]. pub async fn init(&self) -> Result<(), typ::RPCError> { self.do_send_rpc_to_leader("init", Some(&Empty {})).await } - /// Add a node as learner. - /// - /// The node to add has to exist, i.e., being added with `write(DcacheRequest::AddNode{})` pub async fn add_learner( &self, req: (DcacheNodeId, String), @@ -113,10 +84,6 @@ impl DcacheClient { self.send_rpc_to_leader("add-learner", Some(&req)).await } - /// Change membership to the specified set of nodes. - /// - /// All nodes in `req` have to be already added as learner with [`add_learner`], - /// or an error [`LearnerNotFound`] will be returned. pub async fn change_membership( &self, req: &BTreeSet, @@ -125,22 +92,10 @@ impl DcacheClient { .await } - /// Get the metrics about the cluster. - /// - /// Metrics contains various information about the cluster, such as current leader, - /// membership config, replication status etc. - /// See [`RaftMetrics`]. pub async fn metrics(&self) -> Result, typ::RPCError> { self.do_send_rpc_to_leader("metrics", None::<&()>).await } - // --- Internal methods - - /// Send RPC to specified node. - /// - /// It sends out a POST request if `req` is Some. Otherwise a GET request. - /// The remote endpoint must respond a reply in form of `Result`. - /// An `Err` happened on remote will be wrapped in an [`RPCError::RemoteError`]. async fn do_send_rpc_to_leader( &self, uri: &str, @@ -192,10 +147,6 @@ impl DcacheClient { res.map_err(|e| RPCError::RemoteError(RemoteError::new(leader_id, e))) } - /// Try the best to send a request to the leader. - /// - /// If the target node is not a leader, a `ForwardToLeader` error will be - /// returned and this client will retry at most 3 times to contact the updated leader. async fn send_rpc_to_leader( &self, uri: &str,