Skip to content

Commit

Permalink
refactor: Remove Compatible error (#14198)
Browse files Browse the repository at this point in the history
`Compatible` error is added in 0.9.41 to accept two types of error
returned from meta-service: `KVAppError` and `MetaAPIError`.

Such compatible layer can be removed since meta-client's min compatible
meta-service version has already increased to a newer version which does
not send `KVAppError` any more.
  • Loading branch information
drmingdrmer committed Jan 2, 2024
1 parent 98935c1 commit 638686a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 133 deletions.
98 changes: 0 additions & 98 deletions src/meta/api/src/compat_errors.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/meta/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ mod background_api;
mod background_api_impl;
mod background_api_keys;
mod background_api_test_suite;
pub mod compat_errors;
mod data_mask_api;
mod data_mask_api_impl;
mod data_mask_api_keys;
Expand Down
37 changes: 4 additions & 33 deletions src/meta/api/src/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,63 +15,34 @@
use databend_common_meta_types::protobuf::RaftReply;
use databend_common_meta_types::InvalidReply;
use databend_common_meta_types::MetaAPIError;
use databend_common_meta_types::MetaError;
use databend_common_meta_types::MetaNetworkError;
use databend_common_meta_types::TxnOpResponse;
use databend_common_meta_types::TxnReply;
use serde::de::DeserializeOwned;

use crate::compat_errors::Compatible;
use crate::kv_app_error::KVAppError;

/// Compatible layer:
/// Convert either KVAppError or MetaAPIError to MetaAPIError
pub fn reply_to_api_result<T>(msg: RaftReply) -> Result<T, MetaAPIError>
where T: DeserializeOwned {
if !msg.data.is_empty() {
let res: T = serde_json::from_str(&msg.data)
.map_err(|e| InvalidReply::new("can not decode RaftReply.data", &e))?;
Ok(res)
} else {
let err: Compatible<KVAppError, MetaAPIError> = serde_json::from_str(&msg.error)
let err: MetaAPIError = serde_json::from_str(&msg.error)
.map_err(|e| InvalidReply::new("can not decode RaftReply.error", &e))?;

let err = err.into_inner();
Err(err)
}
}

/// Compatible layer:
/// Convert either KVAppError or MetaError to MetaError
pub fn reply_to_meta_result<T>(raft_reply: RaftReply) -> Result<T, MetaError>
where T: DeserializeOwned {
if !raft_reply.data.is_empty() {
let res: T = serde_json::from_str(&raft_reply.data)
.map_err(|e| InvalidReply::new("can not decode RaftReply.data", &e))?;
Ok(res)
} else {
let err: Compatible<KVAppError, MetaError> = serde_json::from_str(&raft_reply.error)
.map_err(|e| InvalidReply::new("can not decode RaftReply.error", &e))?;

let err = err.into_inner();

Err(err)
}
}

/// Compatible layer:
/// Convert txn response to `success` and a series of `TxnOpResponse`.
pub fn txn_reply_to_api_result(
txn_reply: TxnReply,
) -> Result<(bool, Vec<TxnOpResponse>), MetaAPIError> {
if txn_reply.error.is_empty() {
Ok((txn_reply.success, txn_reply.responses))
} else {
let err: Compatible<KVAppError, MetaAPIError> = serde_json::from_str(&txn_reply.error)
.map_err(|e| {
MetaNetworkError::InvalidReply(InvalidReply::new("invalid TxnReply.error", &e))
})?;
let err = err.into_inner();
let err: MetaAPIError = serde_json::from_str(&txn_reply.error)
.map_err(|e| InvalidReply::new("invalid TxnReply.error", &e))?;

Err(err)
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/meta/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ mod message;
use std::sync::LazyLock;

pub use databend_common_meta_api::reply::reply_to_api_result;
pub use databend_common_meta_api::reply::reply_to_meta_result;
pub use grpc_action::MetaGrpcReadReq;
pub use grpc_action::MetaGrpcReq;
pub use grpc_action::RequestFor;
Expand Down Expand Up @@ -83,6 +82,9 @@ pub static METACLI_COMMIT_SEMVER: LazyLock<Version> = LazyLock::new(|| {
/// - 2023-12-16: since 1.2.258:
/// Meta service: add: ttl to TxnPutRequest and Upsert
///
/// - 2024-01-02: since TODO: fill version when merged.
/// Meta client: remove `Compatible` for KVAppError and MetaAPIError, added in `2023-02-16: since 0.9.41`
///
/// Server feature set:
/// ```yaml
/// server_features:
Expand Down

0 comments on commit 638686a

Please sign in to comment.