Skip to content

Commit ce58d74

Browse files
authored
Merge pull request #7685 from drmingdrmer/8-kv-app-err
refactor(meta): extract KVAppError from MetaError
2 parents 67a7269 + da064ac commit ce58d74

File tree

23 files changed

+521
-417
lines changed

23 files changed

+521
-417
lines changed

src/meta/api/src/kv_api.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ use async_trait::async_trait;
1818
use common_base::base::replace_nth_char;
1919
use common_exception::ErrorCode;
2020
use common_meta_types::GetKVReply;
21+
use common_meta_types::KVAppError;
2122
use common_meta_types::ListKVReply;
2223
use common_meta_types::MGetKVReply;
23-
use common_meta_types::MetaError;
2424
use common_meta_types::TxnReply;
2525
use common_meta_types::TxnRequest;
2626
use common_meta_types::UpsertKVReply;
@@ -71,37 +71,37 @@ pub fn get_start_and_end_of_prefix(prefix: &str) -> common_exception::Result<(St
7171

7272
#[async_trait]
7373
pub trait KVApi: Send + Sync {
74-
async fn upsert_kv(&self, req: UpsertKVReq) -> Result<UpsertKVReply, MetaError>;
74+
async fn upsert_kv(&self, req: UpsertKVReq) -> Result<UpsertKVReply, KVAppError>;
7575

76-
async fn get_kv(&self, key: &str) -> Result<GetKVReply, MetaError>;
76+
async fn get_kv(&self, key: &str) -> Result<GetKVReply, KVAppError>;
7777

7878
// mockall complains about AsRef... so we use String here
79-
async fn mget_kv(&self, keys: &[String]) -> Result<MGetKVReply, MetaError>;
79+
async fn mget_kv(&self, keys: &[String]) -> Result<MGetKVReply, KVAppError>;
8080

81-
async fn prefix_list_kv(&self, prefix: &str) -> Result<ListKVReply, MetaError>;
81+
async fn prefix_list_kv(&self, prefix: &str) -> Result<ListKVReply, KVAppError>;
8282

83-
async fn transaction(&self, txn: TxnRequest) -> Result<TxnReply, MetaError>;
83+
async fn transaction(&self, txn: TxnRequest) -> Result<TxnReply, KVAppError>;
8484
}
8585

8686
#[async_trait]
8787
impl<U: KVApi, T: Deref<Target = U> + Send + Sync> KVApi for T {
88-
async fn upsert_kv(&self, act: UpsertKVReq) -> Result<UpsertKVReply, MetaError> {
88+
async fn upsert_kv(&self, act: UpsertKVReq) -> Result<UpsertKVReply, KVAppError> {
8989
self.deref().upsert_kv(act).await
9090
}
9191

92-
async fn get_kv(&self, key: &str) -> Result<GetKVReply, MetaError> {
92+
async fn get_kv(&self, key: &str) -> Result<GetKVReply, KVAppError> {
9393
self.deref().get_kv(key).await
9494
}
9595

96-
async fn mget_kv(&self, key: &[String]) -> Result<MGetKVReply, MetaError> {
96+
async fn mget_kv(&self, key: &[String]) -> Result<MGetKVReply, KVAppError> {
9797
self.deref().mget_kv(key).await
9898
}
9999

100-
async fn prefix_list_kv(&self, prefix: &str) -> Result<ListKVReply, MetaError> {
100+
async fn prefix_list_kv(&self, prefix: &str) -> Result<ListKVReply, KVAppError> {
101101
self.deref().prefix_list_kv(prefix).await
102102
}
103103

104-
async fn transaction(&self, txn: TxnRequest) -> Result<TxnReply, MetaError> {
104+
async fn transaction(&self, txn: TxnRequest) -> Result<TxnReply, KVAppError> {
105105
self.deref().transaction(txn).await
106106
}
107107
}

src/meta/api/src/schema_api.rs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use common_meta_app::schema::UpsertTableOptionReply;
5252
use common_meta_app::schema::UpsertTableOptionReq;
5353
use common_meta_types::GCDroppedDataReply;
5454
use common_meta_types::GCDroppedDataReq;
55-
use common_meta_types::MetaError;
55+
use common_meta_types::KVAppError;
5656
use common_meta_types::MetaId;
5757

5858
/// SchemaApi defines APIs that provides schema storage, such as database, table.
@@ -63,80 +63,84 @@ pub trait SchemaApi: Send + Sync {
6363
async fn create_database(
6464
&self,
6565
req: CreateDatabaseReq,
66-
) -> Result<CreateDatabaseReply, MetaError>;
66+
) -> Result<CreateDatabaseReply, KVAppError>;
6767

68-
async fn drop_database(&self, req: DropDatabaseReq) -> Result<DropDatabaseReply, MetaError>;
68+
async fn drop_database(&self, req: DropDatabaseReq) -> Result<DropDatabaseReply, KVAppError>;
6969

7070
async fn undrop_database(
7171
&self,
7272
req: UndropDatabaseReq,
73-
) -> Result<UndropDatabaseReply, MetaError>;
73+
) -> Result<UndropDatabaseReply, KVAppError>;
7474

75-
async fn get_database(&self, req: GetDatabaseReq) -> Result<Arc<DatabaseInfo>, MetaError>;
75+
async fn get_database(&self, req: GetDatabaseReq) -> Result<Arc<DatabaseInfo>, KVAppError>;
7676

7777
async fn list_databases(
7878
&self,
7979
req: ListDatabaseReq,
80-
) -> Result<Vec<Arc<DatabaseInfo>>, MetaError>;
80+
) -> Result<Vec<Arc<DatabaseInfo>>, KVAppError>;
8181

8282
async fn rename_database(
8383
&self,
8484
req: RenameDatabaseReq,
85-
) -> Result<RenameDatabaseReply, MetaError>;
85+
) -> Result<RenameDatabaseReply, KVAppError>;
8686

8787
async fn get_database_history(
8888
&self,
8989
req: ListDatabaseReq,
90-
) -> Result<Vec<Arc<DatabaseInfo>>, MetaError>;
90+
) -> Result<Vec<Arc<DatabaseInfo>>, KVAppError>;
9191

9292
// table
9393

94-
async fn create_table(&self, req: CreateTableReq) -> Result<CreateTableReply, MetaError>;
94+
async fn create_table(&self, req: CreateTableReq) -> Result<CreateTableReply, KVAppError>;
9595

96-
async fn drop_table(&self, req: DropTableReq) -> Result<DropTableReply, MetaError>;
96+
async fn drop_table(&self, req: DropTableReq) -> Result<DropTableReply, KVAppError>;
9797

98-
async fn undrop_table(&self, req: UndropTableReq) -> Result<UndropTableReply, MetaError>;
98+
async fn undrop_table(&self, req: UndropTableReq) -> Result<UndropTableReply, KVAppError>;
9999

100-
async fn rename_table(&self, req: RenameTableReq) -> Result<RenameTableReply, MetaError>;
100+
async fn rename_table(&self, req: RenameTableReq) -> Result<RenameTableReply, KVAppError>;
101101

102-
async fn get_table(&self, req: GetTableReq) -> Result<Arc<TableInfo>, MetaError>;
102+
async fn get_table(&self, req: GetTableReq) -> Result<Arc<TableInfo>, KVAppError>;
103103

104-
async fn get_table_history(&self, req: ListTableReq) -> Result<Vec<Arc<TableInfo>>, MetaError>;
104+
async fn get_table_history(&self, req: ListTableReq)
105+
-> Result<Vec<Arc<TableInfo>>, KVAppError>;
105106

106-
async fn list_tables(&self, req: ListTableReq) -> Result<Vec<Arc<TableInfo>>, MetaError>;
107+
async fn list_tables(&self, req: ListTableReq) -> Result<Vec<Arc<TableInfo>>, KVAppError>;
107108

108109
async fn get_table_by_id(
109110
&self,
110111
table_id: MetaId,
111-
) -> Result<(TableIdent, Arc<TableMeta>), MetaError>;
112+
) -> Result<(TableIdent, Arc<TableMeta>), KVAppError>;
112113

113114
async fn get_table_copied_file_info(
114115
&self,
115116
req: GetTableCopiedFileReq,
116-
) -> Result<GetTableCopiedFileReply, MetaError>;
117+
) -> Result<GetTableCopiedFileReply, KVAppError>;
117118

118119
async fn upsert_table_copied_file_info(
119120
&self,
120121
req: UpsertTableCopiedFileReq,
121-
) -> Result<UpsertTableCopiedFileReply, MetaError>;
122+
) -> Result<UpsertTableCopiedFileReply, KVAppError>;
122123

123-
async fn truncate_table(&self, req: TruncateTableReq) -> Result<TruncateTableReply, MetaError>;
124+
async fn truncate_table(&self, req: TruncateTableReq)
125+
-> Result<TruncateTableReply, KVAppError>;
124126

125127
async fn upsert_table_option(
126128
&self,
127129
req: UpsertTableOptionReq,
128-
) -> Result<UpsertTableOptionReply, MetaError>;
130+
) -> Result<UpsertTableOptionReply, KVAppError>;
129131

130132
async fn update_table_meta(
131133
&self,
132134
req: UpdateTableMetaReq,
133-
) -> Result<UpdateTableMetaReply, MetaError>;
135+
) -> Result<UpdateTableMetaReply, KVAppError>;
134136

135137
// gc dropped {table|db} which out of retention time.
136-
async fn gc_dropped_data(&self, req: GCDroppedDataReq)
137-
-> Result<GCDroppedDataReply, MetaError>;
138+
async fn gc_dropped_data(
139+
&self,
140+
req: GCDroppedDataReq,
141+
) -> Result<GCDroppedDataReply, KVAppError>;
138142

139-
async fn count_tables(&self, req: CountTablesReq) -> Result<CountTablesReply, MetaError>;
143+
async fn count_tables(&self, req: CountTablesReq) -> Result<CountTablesReply, KVAppError>;
140144

141145
fn name(&self) -> String;
142146
}

0 commit comments

Comments
 (0)