Skip to content

Commit

Permalink
refactor: simplify dictionary API
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Sep 2, 2024
1 parent 734fb94 commit 7d6c143
Show file tree
Hide file tree
Showing 23 changed files with 241 additions and 453 deletions.
28 changes: 28 additions & 0 deletions src/meta/api/src/name_id_value_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,34 @@ where
}
}

/// Update the value part of `name -> id -> value`, identified by name.
///
/// Returns the value before update if success, otherwise None.
///
/// This function does not modify the `name -> id` mapping.
async fn update_id_value(
&self,
key: &K,
value: IdRsc::ValueType,
) -> Result<Option<(DataId<IdRsc>, IdRsc::ValueType)>, MetaError> {
let got = self.get_id_value(key).await?;

let Some((seq_id, seq_meta)) = got else {
return Ok(None);
};

let tenant = key.tenant();
let id_ident = seq_id.data.into_t_ident(tenant);
let transition = self.update_by_id(id_ident, value).await?;

if transition.is_changed() {
Ok(Some((seq_id.data, seq_meta.data)))
} else {
// update_by_id always succeed, unless the id->value mapping is removed.
Ok(None)
}
}

/// Update the value part of `id -> value` mapping by id.
///
/// It returns the state transition of the update operation: `(prev, result)`.
Expand Down
12 changes: 6 additions & 6 deletions src/meta/api/src/schema_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
use std::sync::Arc;

use databend_common_meta_app::schema::catalog_id_ident::CatalogId;
use databend_common_meta_app::schema::dictionary_id_ident::DictionaryId;
use databend_common_meta_app::schema::dictionary_name_ident::DictionaryNameIdent;
use databend_common_meta_app::schema::index_id_ident::IndexId;
use databend_common_meta_app::schema::index_id_ident::IndexIdIdent;
use databend_common_meta_app::schema::tenant_dictionary_ident::TenantDictionaryIdent;
use databend_common_meta_app::schema::CatalogInfo;
use databend_common_meta_app::schema::CatalogMeta;
use databend_common_meta_app::schema::CatalogNameIdent;
Expand Down Expand Up @@ -49,7 +50,6 @@ use databend_common_meta_app::schema::DropVirtualColumnReq;
use databend_common_meta_app::schema::ExtendLockRevReq;
use databend_common_meta_app::schema::GcDroppedTableReq;
use databend_common_meta_app::schema::GetDatabaseReq;
use databend_common_meta_app::schema::GetDictionaryReply;
use databend_common_meta_app::schema::GetIndexReply;
use databend_common_meta_app::schema::GetLVTReply;
use databend_common_meta_app::schema::GetLVTReq;
Expand Down Expand Up @@ -327,13 +327,13 @@ pub trait SchemaApi: Send + Sync {

async fn drop_dictionary(
&self,
dict_ident: TenantDictionaryIdent,
) -> Result<Option<SeqV<DictionaryMeta>>, KVAppError>;
dict_ident: DictionaryNameIdent,
) -> Result<Option<SeqV<DictionaryMeta>>, MetaTxnError>;

async fn get_dictionary(
&self,
req: TenantDictionaryIdent,
) -> Result<Option<GetDictionaryReply>, KVAppError>;
req: DictionaryNameIdent,
) -> Result<Option<(SeqV<DictionaryId>, SeqV<DictionaryMeta>)>, MetaError>;

async fn list_dictionaries(
&self,
Expand Down
Loading

0 comments on commit 7d6c143

Please sign in to comment.