forked from databendlabs/databend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use type
Tenant
for BackgroundJobIdent.tenant
Define BackgroundJobIdent with `TIdent`, make `BackgroundJobIdent.tenant` a `Tenant` instead of a plain `String`. - Part of databendlabs#14719
- Loading branch information
1 parent
171ada8
commit 346e340
Showing
12 changed files
with
157 additions
and
105 deletions.
There are no files selected for viewing
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,75 @@ | ||
// 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::TIdent; | ||
|
||
/// Defines the meta-service key for background job. | ||
pub type BackgroundJobIdent = TIdent<Resource>; | ||
|
||
pub use kvapi_impl::Resource; | ||
|
||
mod kvapi_impl { | ||
|
||
use databend_common_meta_kvapi::kvapi; | ||
use databend_common_meta_kvapi::kvapi::Key; | ||
|
||
use crate::background::BackgroundJobId; | ||
use crate::tenant_key::TenantResource; | ||
|
||
pub struct Resource; | ||
impl TenantResource for Resource { | ||
const PREFIX: &'static str = "__fd_background_job"; | ||
type ValueType = BackgroundJobId; | ||
} | ||
|
||
impl kvapi::Value for BackgroundJobId { | ||
fn dependency_keys(&self) -> impl IntoIterator<Item = String> { | ||
[self.to_string_key()] | ||
} | ||
} | ||
|
||
// impl From<ExistError<Resource>> for ErrorCode { | ||
// fn from(err: ExistError<Resource>) -> Self { | ||
// ErrorCode::ConnectionAlreadyExists(err.to_string()) | ||
// } | ||
// } | ||
// | ||
// impl From<UnknownError<Resource>> for ErrorCode { | ||
// fn from(err: UnknownError<Resource>) -> Self { | ||
// // Special case: use customized message to keep backward compatibility. | ||
// // TODO: consider using the default message in the future(`err.to_string()`) | ||
// ErrorCode::UnknownConnection(format!("Connection '{}' does not exist.", err.name())) | ||
// .add_message_back(err.ctx()) | ||
// } | ||
// } | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use databend_common_meta_kvapi::kvapi::Key; | ||
|
||
use super::BackgroundJobIdent; | ||
use crate::tenant::Tenant; | ||
|
||
#[test] | ||
fn test_connection_ident() { | ||
let tenant = Tenant::new_literal("test"); | ||
let ident = BackgroundJobIdent::new(tenant, "test1"); | ||
|
||
let key = ident.to_string_key(); | ||
assert_eq!(key, "__fd_background_job/test/test1"); | ||
|
||
assert_eq!(ident, BackgroundJobIdent::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
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.