diff --git a/Cargo.lock b/Cargo.lock index d752c53d7f68f..ad905e9a690b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1371,6 +1371,8 @@ dependencies = [ "bincode 2.0.0-rc.2", "codespan-reporting 0.11.1 (git+https://github.com/brendanzab/codespan?rev=c84116f5)", "common-arrow", + "common-meta-stoerr", + "common-meta-types", "opendal", "paste", "prost", @@ -1750,7 +1752,6 @@ dependencies = [ "anyhow", "byteorder", "common-base", - "common-exception", "common-meta-stoerr", "common-meta-types", "common-tracing", @@ -1770,7 +1771,6 @@ name = "common-meta-stoerr" version = "0.1.0" dependencies = [ "anyerror", - "common-exception", "prost", "serde", "serde_json", @@ -1798,7 +1798,6 @@ dependencies = [ "anyerror", "anyhow", "common-building", - "common-exception", "common-meta-stoerr", "derive_more", "num-derive", @@ -2991,7 +2990,6 @@ dependencies = [ "common-arrow", "common-base", "common-building", - "common-exception", "common-grpc", "common-http", "common-meta-api", diff --git a/src/common/exception/Cargo.toml b/src/common/exception/Cargo.toml index d07617779a0f9..42dcaeb9a9646 100644 --- a/src/common/exception/Cargo.toml +++ b/src/common/exception/Cargo.toml @@ -12,6 +12,8 @@ test = false [dependencies] # In alphabetical order common-arrow = { path = "../arrow" } +common-meta-stoerr = { path = "../../meta/stoerr" } +common-meta-types = { path = "../../meta/types" } # Github dependencies # TODO: Use the version from crates.io once diff --git a/src/common/exception/src/exception_code.rs b/src/common/exception/src/exception_code.rs index a49739fc18fb0..7d5970c1edfd9 100644 --- a/src/common/exception/src/exception_code.rs +++ b/src/common/exception/src/exception_code.rs @@ -158,7 +158,7 @@ build_exceptions! { TableSchemaMismatch(1303), } -// Metasvr errors [2001, 3000]. +// Meta service errors [2001, 3000]. build_exceptions! { // Meta service does not work. MetaServiceError(2001), diff --git a/src/common/exception/src/exception_into.rs b/src/common/exception/src/exception_into.rs index 02e7d7f6906f2..4cccd9c272c27 100644 --- a/src/common/exception/src/exception_into.rs +++ b/src/common/exception/src/exception_into.rs @@ -19,6 +19,10 @@ use std::fmt::Display; use std::fmt::Formatter; use std::sync::Arc; +use common_meta_stoerr::MetaStorageError; +use common_meta_types::MetaAPIError; +use common_meta_types::MetaError; + use crate::exception::ErrorCodeBacktrace; use crate::ErrorCode; @@ -275,6 +279,24 @@ impl From for ErrorCode { } } +impl From for ErrorCode { + fn from(e: MetaError) -> Self { + ErrorCode::MetaServiceError(e.to_string()) + } +} + +impl From for ErrorCode { + fn from(e: MetaAPIError) -> Self { + ErrorCode::MetaServiceError(e.to_string()) + } +} + +impl From for ErrorCode { + fn from(e: MetaStorageError) -> Self { + ErrorCode::MetaServiceError(e.to_string()) + } +} + impl From for tonic::Status { fn from(err: ErrorCode) -> Self { let rst_json = serde_json::to_vec::(&SerializedError { diff --git a/src/meta/api/src/kv_app_error.rs b/src/meta/api/src/kv_app_error.rs index b79eab4dece3a..3ea2bfd561a03 100644 --- a/src/meta/api/src/kv_app_error.rs +++ b/src/meta/api/src/kv_app_error.rs @@ -53,7 +53,7 @@ impl From for ErrorCode { fn from(e: KVAppError) -> Self { match e { KVAppError::AppError(app_err) => app_err.into(), - KVAppError::MetaError(meta_err) => meta_err.into(), + KVAppError::MetaError(meta_err) => ErrorCode::MetaServiceError(meta_err.to_string()), } } } diff --git a/src/meta/client/tests/it/grpc_client.rs b/src/meta/client/tests/it/grpc_client.rs index a669de2450569..9e7a2645a5319 100644 --- a/src/meta/client/tests/it/grpc_client.rs +++ b/src/meta/client/tests/it/grpc_client.rs @@ -22,6 +22,8 @@ use common_meta_app::schema::GetDatabaseReq; use common_meta_client::MetaGrpcClient; use common_meta_client::MIN_METASRV_SEMVER; use common_meta_types::protobuf::meta_service_client::MetaServiceClient; +use common_meta_types::MetaClientError; +use common_meta_types::MetaError; use crate::grpc_server::start_grpc_server; @@ -69,7 +71,8 @@ async fn test_grpc_client_handshake_timeout() { .await; let got = res.unwrap_err(); - let got = ErrorCode::from(got).message(); + let got = + ErrorCode::from(MetaError::ClientError(MetaClientError::HandshakeError(got))).message(); let expect = "failed to handshake with meta-service: when sending handshake rpc, cause: tonic::status::Status: status: Cancelled, message: \"Timeout expired\", details: [], metadata: MetadataMap { headers: {} } source: transport error source: Timeout expired"; assert_eq!(got, expect); } diff --git a/src/meta/raft-store/src/state_machine/sm.rs b/src/meta/raft-store/src/state_machine/sm.rs index 1841c867db058..a3b7cc0940ccd 100644 --- a/src/meta/raft-store/src/state_machine/sm.rs +++ b/src/meta/raft-store/src/state_machine/sm.rs @@ -20,7 +20,6 @@ use std::time::Instant; use std::time::SystemTime; use std::time::UNIX_EPOCH; -use common_exception::WithContext; use common_meta_sled_store::get_sled_db; use common_meta_sled_store::openraft; use common_meta_sled_store::openraft::EffectiveMembership; @@ -147,8 +146,7 @@ impl StateMachine { let db = get_sled_db(); // it blocks and slow - db.drop_tree(tree_name) - .context(|| "drop prev state machine")?; + db.drop_tree(tree_name)?; Ok(()) } @@ -208,7 +206,7 @@ impl StateMachine { let mut kvs = Vec::new(); for rkv in view { - let (k, v) = rkv.context(|| "taking snapshot")?; + let (k, v) = rkv?; kvs.push(vec![k.to_vec(), v.to_vec()]); } let snap = SerializableSnapshot { kvs }; diff --git a/src/meta/service/Cargo.toml b/src/meta/service/Cargo.toml index 0726acf015bc5..5146459d28a08 100644 --- a/src/meta/service/Cargo.toml +++ b/src/meta/service/Cargo.toml @@ -26,7 +26,6 @@ io-uring = [ # Workspace dependencies common-arrow = { path = "../../common/arrow" } common-base = { path = "../../common/base" } -common-exception = { path = "../../common/exception" } common-grpc = { path = "../../common/grpc" } common-http = { path = "../../common/http" } common-meta-api = { path = "../api" } diff --git a/src/meta/service/src/store/store_bare.rs b/src/meta/service/src/store/store_bare.rs index 11272524f5772..ea79a2c041f93 100644 --- a/src/meta/service/src/store/store_bare.rs +++ b/src/meta/service/src/store/store_bare.rs @@ -20,7 +20,6 @@ use std::ops::RangeBounds; use anyerror::AnyError; use common_base::base::tokio::sync::RwLock; use common_base::base::tokio::sync::RwLockWriteGuard; -use common_exception::WithContext; use common_meta_raft_store::applied_state::AppliedState; use common_meta_raft_store::config::RaftConfig; use common_meta_raft_store::log::RaftLog; @@ -262,7 +261,7 @@ impl RaftStoreBare { for x in snap.kvs.into_iter() { let k = &x[0]; let v = &x[1]; - tree.insert(k, v.clone()).context(|| "insert snapshot")?; + tree.insert(k, v.clone())?; } info!( @@ -271,7 +270,7 @@ impl RaftStoreBare { new_sm.get_last_applied()?, ); - tree.flush_async().await.context(|| "flush snapshot")?; + tree.flush_async().await?; info!("flushed tree, no_kvs: {}", nkvs); diff --git a/src/meta/sled-store/Cargo.toml b/src/meta/sled-store/Cargo.toml index 470d827190a6f..d8a36981ec5de 100644 --- a/src/meta/sled-store/Cargo.toml +++ b/src/meta/sled-store/Cargo.toml @@ -15,7 +15,6 @@ test = false io-uring = ["sled/io_uring"] [dependencies] -common-exception = { path = "../../common/exception" } common-meta-stoerr = { path = "../stoerr" } common-meta-types = { path = "../types" } diff --git a/src/meta/sled-store/src/sled_tree.rs b/src/meta/sled-store/src/sled_tree.rs index 950c461bd473a..46d57fe3d7e2b 100644 --- a/src/meta/sled-store/src/sled_tree.rs +++ b/src/meta/sled-store/src/sled_tree.rs @@ -17,7 +17,6 @@ use std::marker::PhantomData; use std::ops::Deref; use std::ops::RangeBounds; -use common_exception::WithContext; use common_meta_stoerr::MetaStorageError; use common_meta_types::anyerror::AnyError; use common_meta_types::Change; @@ -117,9 +116,7 @@ impl SledTree { let x = &x[0..5]; assert_eq!(x, b"test-"); } - let t = db - .open_tree(&tree_name) - .context(|| format!("open tree: {}", tree_name))?; + let t = db.open_tree(&tree_name)?; debug!("SledTree opened tree: {}", tree_name); @@ -208,10 +205,7 @@ impl SledTree { &self, key: &KV::K, ) -> Result, MetaStorageError> { - let got = self - .tree - .get(KV::serialize_key(key)?) - .context(|| format!("get: {}:{}", self.name, key))?; + let got = self.tree.get(KV::serialize_key(key)?)?; let v = match got { None => None, @@ -237,16 +231,12 @@ impl SledTree { // Convert K range into sled::IVec range let sled_range = KV::serialize_range(&range)?; - let range_mes = self.range_message::(&range); - for item in self.tree.range(sled_range) { - let (k, _) = item.context(|| format!("range_remove: {}", range_mes,))?; + let (k, _) = item?; batch.remove(k); } - self.tree - .apply_batch(batch) - .context(|| format!("batch remove: {}", range_mes,))?; + self.tree.apply_batch(batch)?; self.flush_async(flush).await?; @@ -265,14 +255,12 @@ impl SledTree { KV: SledKeySpace, R: RangeBounds, { - let range_mes = self.range_message::(&range); - // Convert K range into sled::IVec range let range = KV::serialize_range(&range)?; let it = self.tree.range(range); let it = it.map(move |item| { - let (k, v) = item.context(|| format!("range_get: {}", range_mes,))?; + let (k, v) = item?; let item = SledItem::new(k, v); Ok(item) @@ -291,11 +279,9 @@ impl SledTree { { let mut res = vec![]; - let mes = || format!("scan_prefix: {}", prefix); - let pref = KV::serialize_key(prefix)?; for item in self.tree.scan_prefix(pref) { - let (k, v) = item.context(mes)?; + let (k, v) = item?; let key = KV::deserialize_key(k)?; let value = KV::deserialize_value(v)?; @@ -323,7 +309,7 @@ impl SledTree { batch.insert(k, v); } - self.tree.apply_batch(batch).context(|| "batch append")?; + self.tree.apply_batch(batch)?; self.flush_async(true).await?; @@ -343,10 +329,7 @@ impl SledTree { let k = KV::serialize_key(key)?; let v = KV::serialize_value(value)?; - let prev = self - .tree - .insert(k, v) - .context(|| format!("insert_value {}", key))?; + let prev = self.tree.insert(k, v)?; let prev = match prev { None => None, @@ -359,6 +342,7 @@ impl SledTree { } /// Build a string describing the range for a range operation. + #[allow(dead_code)] fn range_message(&self, range: &R) -> String where KV: SledKeySpace, @@ -376,10 +360,7 @@ impl SledTree { #[tracing::instrument(level = "debug", skip(self))] async fn flush_async(&self, flush: bool) -> Result<(), MetaStorageError> { if flush && self.sync { - self.tree - .flush_async() - .await - .context(|| "flush sled-tree")?; + self.tree.flush_async().await?; } Ok(()) } diff --git a/src/meta/stoerr/Cargo.toml b/src/meta/stoerr/Cargo.toml index 0bae6b56085db..3f0e3f7a7d400 100644 --- a/src/meta/stoerr/Cargo.toml +++ b/src/meta/stoerr/Cargo.toml @@ -11,7 +11,6 @@ doctest = false test = false [dependencies] -common-exception = { path = "../../common/exception" } anyerror = { workspace = true } prost = { workspace = true } diff --git a/src/meta/stoerr/src/meta_storage_errors.rs b/src/meta/stoerr/src/meta_storage_errors.rs index 2afa4da793b62..04ff2376b4fa9 100644 --- a/src/meta/stoerr/src/meta_storage_errors.rs +++ b/src/meta/stoerr/src/meta_storage_errors.rs @@ -12,12 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::any; -use std::backtrace::Backtrace; - use anyerror::AnyError; -use common_exception::ErrorCode; -use common_exception::ErrorWithContext; use serde::Deserialize; use serde::Serialize; use sled::transaction::UnabortableTransactionError; @@ -43,12 +38,6 @@ pub enum MetaStorageError { TransactionConflict, } -impl From for ErrorCode { - fn from(e: MetaStorageError) -> Self { - ErrorCode::MetaStorageError(e.to_string()).set_backtrace(any::request_ref::(&e)) - } -} - impl From for MetaStorageError { fn from(error: std::string::FromUtf8Error) -> Self { MetaStorageError::BytesError(MetaBytesError::new(&error)) @@ -67,12 +56,6 @@ impl From for MetaStorageError { } } -impl From> for MetaStorageError { - fn from(e: ErrorWithContext) -> MetaStorageError { - MetaStorageError::SledError(AnyError::new(&e.err).add_context(|| e.context)) - } -} - impl From for MetaStorageError { fn from(error: UnabortableTransactionError) -> Self { match error { diff --git a/src/meta/types/Cargo.toml b/src/meta/types/Cargo.toml index 1edb0388790b0..95ff711ce0bb6 100644 --- a/src/meta/types/Cargo.toml +++ b/src/meta/types/Cargo.toml @@ -11,7 +11,6 @@ doctest = false test = false [dependencies] -common-exception = { path = "../../common/exception" } common-meta-stoerr = { path = "../stoerr" } openraft = { workspace = true } diff --git a/src/meta/types/src/cluster.rs b/src/meta/types/src/cluster.rs index e7226d81bc917..f017b4628215f 100644 --- a/src/meta/types/src/cluster.rs +++ b/src/meta/types/src/cluster.rs @@ -13,10 +13,10 @@ // limitations under the License. use std::fmt; +use std::net::AddrParseError; use std::net::SocketAddr; use std::str::FromStr; -use common_exception::exception::Result; use serde::Deserialize; use serde::Serialize; @@ -97,7 +97,7 @@ impl NodeInfo { } } - pub fn ip_port(&self) -> Result<(String, u16)> { + pub fn ip_port(&self) -> Result<(String, u16), AddrParseError> { let addr = SocketAddr::from_str(&self.flight_address)?; Ok((addr.ip().to_string(), addr.port())) diff --git a/src/meta/types/src/errors/meta_api_errors.rs b/src/meta/types/src/errors/meta_api_errors.rs index 0e5c6b075b997..75b833edb7be2 100644 --- a/src/meta/types/src/errors/meta_api_errors.rs +++ b/src/meta/types/src/errors/meta_api_errors.rs @@ -15,7 +15,6 @@ use std::fmt::Display; use anyerror::AnyError; -use common_exception::ErrorCode; use openraft::error::ChangeMembershipError; use openraft::error::Fatal; use openraft::error::ForwardToLeader; @@ -46,20 +45,6 @@ pub enum MetaAPIError { RemoteError(MetaDataError), } -impl From for ErrorCode { - fn from(e: MetaAPIError) -> Self { - match e { - MetaAPIError::ForwardToLeader(to_leader) => { - ErrorCode::MetaServiceError(to_leader.to_string()) - } - MetaAPIError::CanNotForward(e) => ErrorCode::MetaServiceError(e.to_string()), - MetaAPIError::NetworkError(e) => ErrorCode::MetaServiceError(e.to_string()), - MetaAPIError::DataError(e) => ErrorCode::MetaServiceError(e.to_string()), - MetaAPIError::RemoteError(e) => ErrorCode::MetaServiceError(e.to_string()), - } - } -} - /// Errors raised when handling a request by raft node. #[derive(thiserror::Error, serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] pub enum MetaOperationError { diff --git a/src/meta/types/src/errors/meta_client_errors.rs b/src/meta/types/src/errors/meta_client_errors.rs index 9d7b43d43d940..ad3c3ff3f46d5 100644 --- a/src/meta/types/src/errors/meta_client_errors.rs +++ b/src/meta/types/src/errors/meta_client_errors.rs @@ -13,7 +13,6 @@ // limitations under the License. use anyerror::AnyError; -use common_exception::ErrorCode; use crate::MetaHandshakeError; use crate::MetaNetworkError; @@ -33,18 +32,3 @@ pub enum MetaClientError { #[error(transparent)] HandshakeError(MetaHandshakeError), } - -impl From for ErrorCode { - fn from(e: MetaClientError) -> Self { - match e { - MetaClientError::ClientRuntimeError(rt_err) => { - ErrorCode::MetaServiceError(rt_err.to_string()) - } - MetaClientError::ConfigError(conf_err) => { - ErrorCode::MetaServiceError(conf_err.to_string()) - } - MetaClientError::NetworkError(net_err) => net_err.into(), - MetaClientError::HandshakeError(handshake_err) => handshake_err.into(), - } - } -} diff --git a/src/meta/types/src/errors/meta_errors.rs b/src/meta/types/src/errors/meta_errors.rs index 7e2c4361cd6b6..a0e3c3a7aa27f 100644 --- a/src/meta/types/src/errors/meta_errors.rs +++ b/src/meta/types/src/errors/meta_errors.rs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use common_exception::ErrorCode; use common_meta_stoerr::MetaStorageError; use serde::Deserialize; use serde::Serialize; @@ -40,17 +39,6 @@ pub enum MetaError { APIError(#[from] MetaAPIError), } -impl From for ErrorCode { - fn from(e: MetaError) -> Self { - match e { - MetaError::NetworkError(net_err) => net_err.into(), - MetaError::StorageError(sto_err) => sto_err.into(), - MetaError::ClientError(ce) => ce.into(), - MetaError::APIError(e) => e.into(), - } - } -} - impl From for MetaError { fn from(status: tonic::Status) -> Self { let net_err = MetaNetworkError::from(status); diff --git a/src/meta/types/src/errors/meta_handshake_errors.rs b/src/meta/types/src/errors/meta_handshake_errors.rs index 4bdb33b1a5b44..28e269d4f65bf 100644 --- a/src/meta/types/src/errors/meta_handshake_errors.rs +++ b/src/meta/types/src/errors/meta_handshake_errors.rs @@ -15,7 +15,6 @@ use std::fmt::Display; use anyerror::AnyError; -use common_exception::ErrorCode; /// Error raised by meta service client. #[derive(thiserror::Error, serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] @@ -34,9 +33,3 @@ impl MetaHandshakeError { } } } - -impl From for ErrorCode { - fn from(e: MetaHandshakeError) -> Self { - ErrorCode::MetaServiceError(e.to_string()) - } -} diff --git a/src/meta/types/src/errors/meta_management_error.rs b/src/meta/types/src/errors/meta_management_error.rs index 951fff614c0f9..5ff58e9de6524 100644 --- a/src/meta/types/src/errors/meta_management_error.rs +++ b/src/meta/types/src/errors/meta_management_error.rs @@ -13,7 +13,6 @@ // limitations under the License. use anyerror::AnyError; -use common_exception::ErrorCode; use serde::Deserialize; use serde::Serialize; @@ -26,16 +25,3 @@ pub enum MetaManagementError { #[error(transparent)] Leave(AnyError), } - -impl From for ErrorCode { - fn from(e: MetaManagementError) -> Self { - match e { - MetaManagementError::Join(ae) => { - ErrorCode::MetaServiceError(ae.to_string()).set_backtrace(ae.backtrace()) - } - MetaManagementError::Leave(ae) => { - ErrorCode::MetaServiceError(ae.to_string()).set_backtrace(ae.backtrace()) - } - } - } -} diff --git a/src/meta/types/src/errors/meta_network_errors.rs b/src/meta/types/src/errors/meta_network_errors.rs index 799cdcc3fb683..f7b363d83a972 100644 --- a/src/meta/types/src/errors/meta_network_errors.rs +++ b/src/meta/types/src/errors/meta_network_errors.rs @@ -15,7 +15,6 @@ use std::fmt::Display; use anyerror::AnyError; -use common_exception::ErrorCode; use serde::Deserialize; use serde::Serialize; use thiserror::Error; @@ -60,32 +59,6 @@ impl MetaNetworkError { } } -impl From for ErrorCode { - fn from(net_err: MetaNetworkError) -> Self { - match net_err { - MetaNetworkError::BadAddressFormat(any_err) => { - ErrorCode::BadAddressFormat(any_err.to_string()) - } - MetaNetworkError::ConnectionError(any_err) => { - ErrorCode::CannotConnectNode(any_err.to_string()) - } - MetaNetworkError::GetNodeAddrError(_) => { - ErrorCode::MetaServiceError(net_err.to_string()) - } - MetaNetworkError::TLSConfigError(any_err) => { - ErrorCode::TLSConfigurationFailure(any_err.to_string()) - } - MetaNetworkError::DnsParseError(_) => ErrorCode::DnsParseError(net_err.to_string()), - MetaNetworkError::InvalidArgument(inv_arg) => { - ErrorCode::InvalidArgument(inv_arg.to_string()) - } - MetaNetworkError::InvalidReply(inv_reply) => { - ErrorCode::InvalidReply(inv_reply.to_string()) - } - } - } -} - pub type MetaNetworkResult = std::result::Result; #[derive(Error, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] diff --git a/src/meta/types/tests/it/cluster.rs b/src/meta/types/tests/it/cluster.rs index ed4ef0ba2401d..1036909969709 100644 --- a/src/meta/types/tests/it/cluster.rs +++ b/src/meta/types/tests/it/cluster.rs @@ -12,11 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -use common_exception::exception::Result; use common_meta_types::NodeInfo; #[test] -fn test_node_info_ip_port() -> Result<()> { +fn test_node_info_ip_port() -> anyhow::Result<()> { let n = NodeInfo { id: "".to_string(), cpu_nums: 1, diff --git a/src/query/management/src/role/role_mgr.rs b/src/query/management/src/role/role_mgr.rs index 5c93f9688a86b..daf64c4f3d27b 100644 --- a/src/query/management/src/role/role_mgr.rs +++ b/src/query/management/src/role/role_mgr.rs @@ -15,7 +15,6 @@ use std::sync::Arc; use common_exception::ErrorCode; -use common_exception::Result; use common_exception::ToErrorCode; use common_meta_app::principal::RoleInfo; use common_meta_kvapi::kvapi; @@ -37,7 +36,10 @@ pub struct RoleMgr { } impl RoleMgr { - pub fn create(kv_api: Arc>, tenant: &str) -> Result { + pub fn create( + kv_api: Arc>, + tenant: &str, + ) -> Result { if tenant.is_empty() { return Err(ErrorCode::TenantIsEmpty( "Tenant can not empty(while role mgr create)", @@ -54,7 +56,7 @@ impl RoleMgr { &self, role_info: &RoleInfo, seq: MatchSeq, - ) -> common_exception::Result { + ) -> Result { let key = self.make_role_key(role_info.identity()); let value = serde_json::to_vec(&role_info)?; @@ -98,7 +100,7 @@ impl RoleApi for RoleMgr { Ok(res.seq) } - async fn get_role(&self, role: &String, seq: MatchSeq) -> Result> { + async fn get_role(&self, role: &String, seq: MatchSeq) -> Result, ErrorCode> { let key = self.make_role_key(role); let res = self.kv_api.get_kv(&key).await?; let seq_value = @@ -110,7 +112,7 @@ impl RoleApi for RoleMgr { } } - async fn get_roles(&self) -> Result>> { + async fn get_roles(&self) -> Result>, ErrorCode> { let role_prefix = self.role_prefix.clone(); let kv_api = self.kv_api.clone(); let values = kv_api.prefix_list_kv(role_prefix.as_str()).await?; @@ -131,8 +133,15 @@ impl RoleApi for RoleMgr { /// It fetch the role that matches the specified seq number, update it in place, then write it back with the seq it sees. /// /// Seq number ensures there is no other write happens between get and set. - async fn update_role_with(&self, role: &String, seq: MatchSeq, f: F) -> Result> - where F: FnOnce(&mut RoleInfo) + Send { + async fn update_role_with( + &self, + role: &String, + seq: MatchSeq, + f: F, + ) -> Result, ErrorCode> + where + F: FnOnce(&mut RoleInfo) + Send, + { let SeqV { seq, data: mut role_info, @@ -147,7 +156,7 @@ impl RoleApi for RoleMgr { Ok(Some(seq)) } - async fn drop_role(&self, role: String, seq: MatchSeq) -> Result<()> { + async fn drop_role(&self, role: String, seq: MatchSeq) -> Result<(), ErrorCode> { let key = self.make_role_key(&role); let kv_api = self.kv_api.clone(); let res = kv_api