chore: rm client

This commit is contained in:
Aravinth Manivannan 2023-05-27 13:21:32 +05:30
parent 6ba293d287
commit efeb6f3945
Signed by: realaravinth
GPG Key ID: F8F50389936984FF
1 changed files with 0 additions and 49 deletions

View File

@ -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<Mutex<(DcacheNodeId, String)>>,
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<String, typ::RPCError> {
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<typ::InitializeError>> {
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<DcacheNodeId>,
@ -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<RaftMetrics<DcacheNodeId, BasicNode>, 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<T, E>`.
/// An `Err` happened on remote will be wrapped in an [`RPCError::RemoteError`].
async fn do_send_rpc_to_leader<Req, Resp, Err>(
&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<Req, Resp, Err>(
&self,
uri: &str,