-
Notifications
You must be signed in to change notification settings - Fork 752
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Define DatabaseIdToNameIdent with TIdent
- Loading branch information
1 parent
c221094
commit 28b0574
Showing
15 changed files
with
160 additions
and
92 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright 2021 Datafuse Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use crate::tenant_key::ident::TIdent; | ||
use crate::tenant_key::raw::TIdentRaw; | ||
|
||
pub type DatabaseIdToNameIdent = TIdent<Resource, u64>; | ||
pub type DatabaseIdToNameIdentRaw = TIdentRaw<Resource, u64>; | ||
|
||
pub use kvapi_impl::Resource; | ||
|
||
impl DatabaseIdToNameIdent { | ||
pub fn database_id(&self) -> u64 { | ||
*self.name() | ||
} | ||
} | ||
|
||
impl DatabaseIdToNameIdentRaw { | ||
pub fn database_id(&self) -> u64 { | ||
*self.name() | ||
} | ||
} | ||
|
||
mod kvapi_impl { | ||
|
||
use databend_common_meta_kvapi::kvapi; | ||
|
||
use crate::schema::database_name_ident::DatabaseNameIdentRaw; | ||
use crate::tenant_key::resource::TenantResource; | ||
|
||
pub struct Resource; | ||
impl TenantResource for Resource { | ||
const PREFIX: &'static str = "__fd_database_id_to_name"; | ||
const TYPE: &'static str = "DatabaseIdToNameIdent"; | ||
const HAS_TENANT: bool = false; | ||
type ValueType = DatabaseNameIdentRaw; | ||
} | ||
|
||
// TODO(TIdent): parent: DatabaseIdIdent | ||
impl kvapi::Value for DatabaseNameIdentRaw { | ||
fn dependency_keys(&self) -> impl IntoIterator<Item = String> { | ||
[] | ||
} | ||
} | ||
|
||
// // Use these error types to replace usage of ErrorCode if possible. | ||
// impl From<ExistError<Resource>> for ErrorCode { | ||
// impl From<UnknownError<Resource>> for ErrorCode { | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use databend_common_meta_kvapi::kvapi::Key; | ||
|
||
use super::DatabaseIdToNameIdent; | ||
use crate::tenant::Tenant; | ||
|
||
#[test] | ||
fn test_background_job_id_ident() { | ||
let tenant = Tenant::new_literal("dummy"); | ||
let ident = DatabaseIdToNameIdent::new(tenant, 3); | ||
|
||
let key = ident.to_string_key(); | ||
assert_eq!(key, "__fd_database_id_to_name/3"); | ||
|
||
assert_eq!(ident, DatabaseIdToNameIdent::from_str_key(&key).unwrap()); | ||
} | ||
|
||
#[test] | ||
fn test_background_job_id_ident_with_key_space() { | ||
// TODO(xp): implement this test | ||
// let tenant = Tenant::new_literal("test"); | ||
// let ident = DatabaseIdToNameIdent::new(tenant, 3); | ||
// | ||
// let key = ident.to_string_key(); | ||
// assert_eq!(key, "__fd_database_id_to_name/3"); | ||
// | ||
// assert_eq!(ident, DatabaseIdToNameIdent::from_str_key(&key).unwrap()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.