Skip to content

Commit

Permalink
chore: fix curp test
Browse files Browse the repository at this point in the history
Signed-off-by: iGxnon <[email protected]>
  • Loading branch information
iGxnon committed Dec 13, 2023
1 parent b93fc95 commit a304db2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions curp/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ impl CurpError {
}

/// `ExpiredClientId` error
#[allow(unused)] // TODO: used in dedup
pub(crate) fn expired_client_id() -> Self {
Self::ExpiredClientId(())
}
Expand All @@ -658,7 +659,7 @@ impl CurpError {
}

/// `ShuttingDown` error
pub(crate) fn shuting_down() -> Self {
pub(crate) fn shutting_down() -> Self {
Self::ShuttingDown(())
}

Expand All @@ -683,6 +684,8 @@ impl<E: std::error::Error + 'static> From<E> for CurpError {
fn from(value: E) -> Self {
let err: &dyn std::error::Error = &value;
if let Some(status) = err.downcast_ref::<tonic::Status>() {
// Unavailable code often occurs in rpc connection errors,
// Please DO NOT use this code in CurpError to tonic::Status.
if status.code() == tonic::Code::Unavailable {
return Self::RpcTransport(());
}
Expand Down Expand Up @@ -734,7 +737,7 @@ impl From<CurpError> for tonic::Status {
"Learner not caught up error: The learner has not caught up.",
),
CurpError::ShuttingDown(_) => (
tonic::Code::Unavailable,
tonic::Code::FailedPrecondition,
"Shutting down error: The service is currently shutting down.",
),
CurpError::WrongClusterVersion(_) => (
Expand Down
4 changes: 2 additions & 2 deletions curp/src/server/curp_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<C: 'static + Command, RC: RoleChange + 'static> CurpNode<C, RC> {
/// Handle `Propose` requests
pub(super) async fn propose(&self, req: ProposeRequest) -> Result<ProposeResponse, CurpError> {
if self.curp.is_shutdown() {
return Err(CurpError::shuting_down());
return Err(CurpError::shutting_down());
}
self.check_cluster_version(req.cluster_version)?;
let cmd: Arc<C> = Arc::new(req.cmd()?);
Expand Down Expand Up @@ -112,7 +112,7 @@ impl<C: 'static + Command, RC: RoleChange + 'static> CurpNode<C, RC> {
req: WaitSyncedRequest,
) -> Result<WaitSyncedResponse, CurpError> {
if self.curp.is_shutdown() {
return Err(CurpError::shuting_down());
return Err(CurpError::shutting_down());
}
self.check_cluster_version(req.cluster_version)?;
let id = req.propose_id();
Expand Down
4 changes: 2 additions & 2 deletions simulation/src/curp_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use curp::{
error::ClientError,
members::{ClusterInfo, ServerId},
server::Rpc,
ConfChange, ConfChangeError, FetchClusterRequest, FetchClusterResponse, LogIndex, Member,
ConfChange, CurpError, FetchClusterRequest, FetchClusterResponse, LogIndex, Member,
ProposeConfChangeRequest, ProposeConfChangeResponse,
};
pub use curp::{protocol_client::ProtocolClient, ProposeRequest, ProposeResponse};
Expand Down Expand Up @@ -462,7 +462,7 @@ impl<C: Command + 'static> SimClient<C> {
&self,
propose_id: ProposeId,
changes: Vec<ConfChange>,
) -> Result<Result<Vec<Member>, ConfChangeError>, ClientError<C>> {
) -> Result<Result<Vec<Member>, CurpError>, ClientError<C>> {
let inner = self.inner.clone();
self.handle
.spawn(async move { inner.propose_conf_change(propose_id, changes).await })
Expand Down

0 comments on commit a304db2

Please sign in to comment.