Skip to content

Commit 87b9558

Browse files
committed
refactor the by comment
1 parent aadc442 commit 87b9558

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

src/meta/api/src/schema_api_impl.rs

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,25 +1884,13 @@ impl<KV: KVApi> SchemaApi for KV {
18841884
)));
18851885
}
18861886

1887-
let lock_key = TableCopiedFileLockKey { table_id };
1888-
let (lock_key_seq, lock_op): (_, Option<TableCopiedFileLock>) =
1889-
get_struct_value(self, &lock_key).await?;
1890-
1891-
let lock = match lock_op {
1892-
Some(lock) => lock,
1893-
None => TableCopiedFileLock {},
1894-
};
1895-
18961887
debug!(
18971888
ident = display(&tbid),
18981889
table_meta = debug(&tb_meta),
18991890
"truncate_table"
19001891
);
19011892

1902-
let mut condition = vec![
1903-
txn_cond_seq(&tbid, Eq, tb_meta_seq),
1904-
txn_cond_seq(&lock_key, Eq, lock_key_seq),
1905-
];
1893+
let mut condition = vec![txn_cond_seq(&tbid, Eq, tb_meta_seq)];
19061894
let mut if_then = vec![];
19071895
remove_table_copied_files(self, table_id, &mut condition, &mut if_then).await?;
19081896

@@ -1913,7 +1901,6 @@ impl<KV: KVApi> SchemaApi for KV {
19131901

19141902
// update table meta to make sequence update.
19151903
if_then.push(txn_op_put(&tbid, serialize_struct(&tb_meta.unwrap())?)); // tb_id -> tb_meta
1916-
if_then.push(txn_op_put(&lock_key, serialize_struct(&lock)?)); // copied file lock key
19171904

19181905
let txn_req = TxnRequest {
19191906
condition,
@@ -2154,20 +2141,29 @@ async fn remove_table_copied_files(
21542141
condition: &mut Vec<TxnCondition>,
21552142
if_then: &mut Vec<TxnOp>,
21562143
) -> Result<(), MetaError> {
2157-
// List files by tenant, db_name, table_name
2158-
let dbid_tbname_idlist = TableCopiedFileNameIdent {
2159-
table_id,
2160-
// Using a empty file to to list all
2161-
file: "".to_string(),
2162-
};
2144+
let lock_key = TableCopiedFileLockKey { table_id };
2145+
let (lock_key_seq, lock_op): (_, Option<TableCopiedFileLock>) =
2146+
get_struct_value(kv_api, &lock_key).await?;
2147+
2148+
if let Some(lock) = lock_op {
2149+
condition.push(txn_cond_seq(&lock_key, Eq, lock_key_seq));
2150+
if_then.push(txn_op_put(&lock_key, serialize_struct(&lock)?)); // copied file lock key
2151+
2152+
// List files by tenant, db_name, table_name
2153+
let dbid_tbname_idlist = TableCopiedFileNameIdent {
2154+
table_id,
2155+
// Using a empty file to to list all
2156+
file: "".to_string(),
2157+
};
21632158

2164-
let files = list_keys(kv_api, &dbid_tbname_idlist).await?;
2165-
for file in files {
2166-
let (file_seq, _opt): (_, Option<TableCopiedFileInfo>) =
2167-
get_struct_value(kv_api, &file).await?;
2168-
if file_seq != 0 {
2169-
condition.push(txn_cond_seq(&file, Eq, file_seq));
2170-
if_then.push(txn_op_del(&file));
2159+
let files = list_keys(kv_api, &dbid_tbname_idlist).await?;
2160+
for file in files {
2161+
let (file_seq, _opt): (_, Option<TableCopiedFileInfo>) =
2162+
get_struct_value(kv_api, &file).await?;
2163+
if file_seq != 0 {
2164+
condition.push(txn_cond_seq(&file, Eq, file_seq));
2165+
if_then.push(txn_op_del(&file));
2166+
}
21712167
}
21722168
}
21732169

0 commit comments

Comments
 (0)