diff --git a/crates/metadata-store/src/grpc/handler.rs b/crates/metadata-store/src/grpc/handler.rs index 938e09d8e0..54a40224fb 100644 --- a/crates/metadata-store/src/grpc/handler.rs +++ b/crates/metadata-store/src/grpc/handler.rs @@ -132,7 +132,8 @@ impl MetadataStoreSvc for MetadataStoreHandler { impl From for Status { fn from(err: RequestError) -> Self { match err { - RequestError::FailedPrecondition(msg) => Status::failed_precondition(msg.to_string()), + RequestError::FailedPrecondition(err) => Status::failed_precondition(err.to_string()), + RequestError::Unavailable(err) => Status::unavailable(err.to_string()), err => Status::internal(err.to_string()), } } diff --git a/crates/metadata-store/src/lib.rs b/crates/metadata-store/src/lib.rs index 3ab0838837..be7c139681 100644 --- a/crates/metadata-store/src/lib.rs +++ b/crates/metadata-store/src/lib.rs @@ -32,7 +32,9 @@ pub type RequestReceiver = mpsc::Receiver; #[derive(Debug, thiserror::Error)] pub enum RequestError { #[error("internal error: {0}")] - Internal(#[from] GenericError), + Internal(GenericError), + #[error("service currently unavailable: {0}")] + Unavailable(GenericError), #[error("failed precondition: {0}")] FailedPrecondition(#[from] PreconditionViolation), #[error("invalid argument: {0}")] diff --git a/crates/metadata-store/src/raft/store.rs b/crates/metadata-store/src/raft/store.rs index b03c734648..f6db971824 100644 --- a/crates/metadata-store/src/raft/store.rs +++ b/crates/metadata-store/src/raft/store.rs @@ -112,7 +112,7 @@ impl RaftMetadataStore { .map_err(Into::into) .and_then(|request| self.raw_node .propose(vec![], request) - .map_err(|err| RequestError::Internal(err.into()))) { + .map_err(|err| RequestError::from(err))) { info!("Failed processing request: {err}"); callback.fail(err); continue; @@ -527,3 +527,12 @@ enum RequestKind { precondition: Precondition, }, } + +impl From for RequestError { + fn from(value: raft::Error) -> Self { + match value { + err @ raft::Error::ProposalDropped => RequestError::Unavailable(err.into()), + err => RequestError::Internal(err.into()), + } + } +}