Skip to content

Commit ae60a18

Browse files
committed
docs(meta/errors): explain relationship between various error types in meta-store
- Refacotr: move meta-related error into `errors` mod. Defines meta-store errors and meta-store application errors. Error relations The overall relations between errors defined in meta-store components are: ```text KVAppError | +- AppError ------> TableNotFound | DbExists | ... `- MetaError | +- MetaStorageError | +- MetaClientError | | | +- MetaNetworkError | +- HandshakeError | +- MetaNetworkError | `- MetaApiError | +- ForwardToLeader -. +- CanNotForward | | | +- MetaNetworkError | | | +- MetaDataError ---|-----------. | | | `- RemoteError ---|-----------+ | | | | | | MetaOperationError | .---------|----------' | | | | .----------' v v v v ForwardToLeader MetaDataError | | .---------------' '---------. v v MetaDataReadError Raft*Error | | +- MetaStorageError +- MetaStorageError ``` Bottom level errors: Bottom level errors are derived from non-meta-store layers. - `MetaStorageError` - `MetaNetworkError` - `MetaBytesError` ```text MetaNetworkError | +- Connection errors +- DNS errors `- Payload codec error MetaStorageError | +- Sled errors +- Txn conflict `- Codec error:--. | v MetaBytesError ``` Application level errors Application level errors(`KVAppError`) are defined for meta-store application, e.g., `SchemaApi`, `ShareApi` etc. An application error has two main sub error: meta-store related or application related: - `KVAppError::MetaError` is error raised from inside meta-store and an application can do nothing about it. It includes all errors that meta-store might return. - `KVAppError::AppError` are application specific errors, such as `TableNotFound`, `DbExists`. These errors should be dealt with by an application correctly. `MetaError` `MetaError` defines every error could occur inside a meta-store implementation(an embedded meta-store or a client-server meta-store service). The sub errors are about both a local implementation and a remote meta-store implementation: For a remote meta-store service: - `MetaClientError`: is only returned with remote meta-store service: when creating a client to meta-store service. Since a client will send a handshake request, `MetaClientError` also includes a network sub error: `MetaNetworkError`. - `MetaNetworkError` is only returned with remote meta-store service: when sending a request to a remote meta-store service. - `MetaApiError` is only returned with remote meta-store service: it is all of the errors that could occur when a meta-store service handling a request. For a local meta-store: - `MetaStorageError`: meta-store is implemented directly upon storage layer. `MetaApiError` `MetaApiError` is defined for meta-store service RPC API handler: It includes Raft related errors and errors that occurs when forwarding a request between meta-store servers: - Errors informing request forwarding state:: `ForwardToLeader` or `CanNotForward`. - Errors occurs when forwarding a request: `MetaNetworkError`. - Errors occurs when reading/writing: `MetaDataError`. Because a request may be dealt with locally or dealt with remotely, via request forwarding, there are two variants for `MetaDataError`: - `MetaApiError::MetaDataError(MetaDataError)` is returned when a request is dealt with locally. - `MetaApiError::RemoteError(MetaDataError)` is returned when a request is dealt with on a remote noMetaDataError. `MetaDataError` It is the error that could occur when dealing with read/write request. In meta-store, data is written through Raft protocol, thus part of its sub errors are Raft related: `RaftWriteError` or `RaftChangeMembershipError`. In meta-store reading data does not depend on Raft protocol, thus read errors is defined as `MetaDataReadError` and is derived directly from MetaStorageError. Other errors: - `MetaOperationError` is a intermediate error and a subset error of `MetaApiError` and is defined for a local request handler without forwarding. It is finally converted to `MetaApiError`. - `ForwardRPCError` is another intermediate error to wrap a result of a forwarded request. - Fix: #7689
1 parent ce58d74 commit ae60a18

22 files changed

+275
-139
lines changed

โ€Žsrc/meta/api/src/schema_api_impl.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,27 @@ use common_meta_app::share::ShareGrantObject;
7777
use common_meta_app::share::ShareGrantObjectPrivilege;
7878
use common_meta_app::share::ShareId;
7979
use common_meta_app::share::ShareNameIdent;
80-
use common_meta_types::app_error::AppError;
81-
use common_meta_types::app_error::CreateDatabaseWithDropTime;
82-
use common_meta_types::app_error::CreateTableWithDropTime;
83-
use common_meta_types::app_error::DatabaseAlreadyExists;
84-
use common_meta_types::app_error::DropDbWithDropTime;
85-
use common_meta_types::app_error::DropTableWithDropTime;
86-
use common_meta_types::app_error::ShareHasNoGrantedDatabase;
87-
use common_meta_types::app_error::ShareHasNoGrantedPrivilege;
88-
use common_meta_types::app_error::TableAlreadyExists;
89-
use common_meta_types::app_error::TableVersionMismatched;
90-
use common_meta_types::app_error::TxnRetryMaxTimes;
91-
use common_meta_types::app_error::UndropDbHasNoHistory;
92-
use common_meta_types::app_error::UndropDbWithNoDropTime;
93-
use common_meta_types::app_error::UndropTableAlreadyExists;
94-
use common_meta_types::app_error::UndropTableHasNoHistory;
95-
use common_meta_types::app_error::UndropTableWithNoDropTime;
96-
use common_meta_types::app_error::UnknownShareAccounts;
97-
use common_meta_types::app_error::UnknownTable;
98-
use common_meta_types::app_error::UnknownTableId;
99-
use common_meta_types::app_error::WrongShare;
100-
use common_meta_types::app_error::WrongShareObject;
80+
use common_meta_types::errors::app_error::AppError;
81+
use common_meta_types::errors::app_error::CreateDatabaseWithDropTime;
82+
use common_meta_types::errors::app_error::CreateTableWithDropTime;
83+
use common_meta_types::errors::app_error::DatabaseAlreadyExists;
84+
use common_meta_types::errors::app_error::DropDbWithDropTime;
85+
use common_meta_types::errors::app_error::DropTableWithDropTime;
86+
use common_meta_types::errors::app_error::ShareHasNoGrantedDatabase;
87+
use common_meta_types::errors::app_error::ShareHasNoGrantedPrivilege;
88+
use common_meta_types::errors::app_error::TableAlreadyExists;
89+
use common_meta_types::errors::app_error::TableVersionMismatched;
90+
use common_meta_types::errors::app_error::TxnRetryMaxTimes;
91+
use common_meta_types::errors::app_error::UndropDbHasNoHistory;
92+
use common_meta_types::errors::app_error::UndropDbWithNoDropTime;
93+
use common_meta_types::errors::app_error::UndropTableAlreadyExists;
94+
use common_meta_types::errors::app_error::UndropTableHasNoHistory;
95+
use common_meta_types::errors::app_error::UndropTableWithNoDropTime;
96+
use common_meta_types::errors::app_error::UnknownShareAccounts;
97+
use common_meta_types::errors::app_error::UnknownTable;
98+
use common_meta_types::errors::app_error::UnknownTableId;
99+
use common_meta_types::errors::app_error::WrongShare;
100+
use common_meta_types::errors::app_error::WrongShareObject;
101101
use common_meta_types::ConditionResult;
102102
use common_meta_types::GCDroppedDataReply;
103103
use common_meta_types::GCDroppedDataReq;

โ€Žsrc/meta/api/src/share_api_impl.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ use common_meta_app::schema::TableIdToName;
2121
use common_meta_app::schema::TableMeta;
2222
use common_meta_app::schema::TableNameIdent;
2323
use common_meta_app::share::*;
24-
use common_meta_types::app_error::AppError;
25-
use common_meta_types::app_error::ShareAccountsAlreadyExists;
26-
use common_meta_types::app_error::ShareAlreadyExists;
27-
use common_meta_types::app_error::TxnRetryMaxTimes;
28-
use common_meta_types::app_error::UnknownShare;
29-
use common_meta_types::app_error::UnknownShareAccounts;
30-
use common_meta_types::app_error::UnknownTable;
31-
use common_meta_types::app_error::WrongShare;
32-
use common_meta_types::app_error::WrongShareObject;
24+
use common_meta_types::errors::app_error::AppError;
25+
use common_meta_types::errors::app_error::ShareAccountsAlreadyExists;
26+
use common_meta_types::errors::app_error::ShareAlreadyExists;
27+
use common_meta_types::errors::app_error::TxnRetryMaxTimes;
28+
use common_meta_types::errors::app_error::UnknownShare;
29+
use common_meta_types::errors::app_error::UnknownShareAccounts;
30+
use common_meta_types::errors::app_error::UnknownTable;
31+
use common_meta_types::errors::app_error::WrongShare;
32+
use common_meta_types::errors::app_error::WrongShareObject;
3333
use common_meta_types::ConditionResult::Eq;
3434
use common_meta_types::KVAppError;
3535
use common_meta_types::TxnCondition;

โ€Žsrc/meta/api/src/util.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ use common_meta_app::schema::DatabaseMeta;
2020
use common_meta_app::schema::DatabaseNameIdent;
2121
use common_meta_app::schema::TableNameIdent;
2222
use common_meta_app::share::*;
23-
use common_meta_types::app_error::AppError;
24-
use common_meta_types::app_error::ShareHasNoGrantedDatabase;
25-
use common_meta_types::app_error::UnknownDatabase;
26-
use common_meta_types::app_error::UnknownShare;
27-
use common_meta_types::app_error::UnknownShareAccounts;
28-
use common_meta_types::app_error::UnknownShareId;
29-
use common_meta_types::app_error::UnknownTable;
23+
use common_meta_types::errors::app_error::AppError;
24+
use common_meta_types::errors::app_error::ShareHasNoGrantedDatabase;
25+
use common_meta_types::errors::app_error::UnknownDatabase;
26+
use common_meta_types::errors::app_error::UnknownShare;
27+
use common_meta_types::errors::app_error::UnknownShareAccounts;
28+
use common_meta_types::errors::app_error::UnknownShareId;
29+
use common_meta_types::errors::app_error::UnknownTable;
3030
use common_meta_types::txn_condition::Target;
3131
use common_meta_types::txn_op::Request;
3232
use common_meta_types::ConditionResult;

โ€Žsrc/meta/app/src/share/share.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use std::fmt::Formatter;
2020

2121
use common_datavalues::chrono::DateTime;
2222
use common_datavalues::chrono::Utc;
23-
use common_meta_types::app_error::AppError;
24-
use common_meta_types::app_error::WrongShareObject;
23+
use common_meta_types::errors::app_error::AppError;
24+
use common_meta_types::errors::app_error::WrongShareObject;
2525
use common_meta_types::KVAppError;
2626
use enumflags2::bitflags;
2727
use enumflags2::BitFlags;

โ€Žsrc/meta/types/src/meta_errors.rs renamed to โ€Žsrc/meta/types/src/errors/meta_errors.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use common_exception::ErrorCode;
1516
use serde::Deserialize;
1617
use serde::Serialize;
1718
use thiserror::Error;
@@ -39,3 +40,21 @@ pub enum MetaError {
3940
}
4041

4142
pub type MetaResult<T> = Result<T, MetaError>;
43+
44+
impl From<MetaError> for ErrorCode {
45+
fn from(e: MetaError) -> Self {
46+
match e {
47+
MetaError::NetworkError(net_err) => net_err.into(),
48+
MetaError::StorageError(sto_err) => sto_err.into(),
49+
MetaError::ClientError(ce) => ce.into(),
50+
MetaError::APIError(e) => e.into(),
51+
}
52+
}
53+
}
54+
55+
impl From<tonic::Status> for MetaError {
56+
fn from(status: tonic::Status) -> Self {
57+
let net_err = MetaNetworkError::from(status);
58+
MetaError::NetworkError(net_err)
59+
}
60+
}

0 commit comments

Comments
ย (0)