Skip to content

Commit

Permalink
fix review commend
Browse files Browse the repository at this point in the history
  • Loading branch information
zhyass committed Apr 17, 2024
1 parent a95bfd4 commit 1a64a7f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
3 changes: 1 addition & 2 deletions src/meta/api/src/schema_api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3638,8 +3638,7 @@ impl<KV: kvapi::KVApi<Error = MetaError> + ?Sized> SchemaApi for KV {
#[minitrace::trace]
async fn list_locks(&self, req: ListLocksReq) -> Result<Vec<LockInfo>, KVAppError> {
let mut reply = vec![];
let prefixes = req.gen_prefixes();
for prefix in &prefixes {
for prefix in &req.prefixes {
let mut stream = self.list_kv(prefix).await?;
while let Some(list) = stream.try_next().await? {
let k = list.key;
Expand Down
28 changes: 11 additions & 17 deletions src/meta/app/src/schema/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,32 +130,26 @@ pub struct LockInfo {

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ListLocksReq {
pub tenant: Tenant,
pub table_ids: Vec<u64>,
pub prefixes: Vec<String>,
}

impl ListLocksReq {
pub fn create(tenant: impl ToTenant, table_ids: Vec<u64>) -> Self {
pub fn create(tenant: &Tenant) -> Self {
let lock = TableLockKey::new(tenant, 0, 0);
let prefix = DirName::new_with_level(lock, 2).dir_name_with_slash();
Self {
tenant: tenant.to_tenant(),
table_ids,
prefixes: vec![prefix],
}
}

pub fn gen_prefixes(&self) -> Vec<String> {
pub fn create_with_table_ids(tenant: &Tenant, table_ids: Vec<u64>) -> Self {
let mut prefixes = Vec::new();
if self.table_ids.is_empty() {
let lock = TableLockKey::new(self.tenant.clone(), 0, 0);
let prefix = DirName::new_with_level(lock, 2).dir_name_with_slash();
for table_id in table_ids {
let lock = TableLockKey::new(tenant, table_id, 0);
let prefix = DirName::new(lock).dir_name_with_slash();
prefixes.push(prefix);
} else {
for table_id in &self.table_ids {
let lock = TableLockKey::new(self.tenant.clone(), *table_id, 0);
let prefix = DirName::new(lock).dir_name_with_slash();
prefixes.push(prefix);
}
}
prefixes
Self { prefixes }
}
}

Expand Down Expand Up @@ -203,7 +197,7 @@ impl TableLockKey {
pub fn new(tenant: impl ToTenant, table_id: u64, revision: u64) -> Self {
Self {
tenant: tenant.to_tenant(),
table_id: table_id.into(),
table_id,
revision,
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/query/storages/system/src/locks_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ impl AsyncSystemTable for LocksTable {
}
}

let req = ListLocksReq::create(&tenant, table_ids);
let req = if table_ids.is_empty() {
ListLocksReq::create(&tenant)
} else {
ListLocksReq::create_with_table_ids(&tenant, table_ids)
};
let lock_infos = ctl.list_locks(req).await?;
for info in lock_infos {
lock_table_id.push(info.table_id);
Expand Down

0 comments on commit 1a64a7f

Please sign in to comment.