Skip to content

Commit 3461dd2

Browse files
authored
[fix](cloud) Avoid write recycle partition key if operation log is written (apache#53828)
1 parent 122f766 commit 3461dd2

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

cloud/src/meta-service/meta_service_partition.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ void MetaServiceImpl::drop_partition(::google::protobuf::RpcController* controll
604604
pb.SerializeToString(&to_save_val);
605605
}
606606
bool need_commit = false;
607+
bool is_versioned_write = is_version_write_enabled(instance_id);
607608
DropPartitionLogPB drop_partition_log;
608609
drop_partition_log.set_db_id(request->db_id());
609610
drop_partition_log.set_table_id(request->table_id());
@@ -615,9 +616,12 @@ void MetaServiceImpl::drop_partition(::google::protobuf::RpcController* controll
615616
std::string val;
616617
err = txn->get(key, &val);
617618
if (err == TxnErrorCode::TXN_KEY_NOT_FOUND) { // UNKNOWN
618-
LOG_INFO("put recycle partition").tag("key", hex(key));
619-
txn->put(key, to_save_val);
620-
drop_partition_log.add_partition_ids(part_id);
619+
if (is_versioned_write) {
620+
drop_partition_log.add_partition_ids(part_id);
621+
} else {
622+
LOG_INFO("put recycle partition").tag("key", hex(key));
623+
txn->put(key, to_save_val);
624+
}
621625
need_commit = true;
622626
continue;
623627
}
@@ -661,7 +665,7 @@ void MetaServiceImpl::drop_partition(::google::protobuf::RpcController* controll
661665

662666
if ((drop_partition_log.update_table_version() ||
663667
drop_partition_log.partition_ids_size() > 0) &&
664-
is_version_write_enabled(instance_id)) {
668+
is_versioned_write) {
665669
std::string operation_log_key = versioned::log_key({instance_id});
666670
std::string operation_log_value;
667671
OperationLogPB operation_log;
@@ -673,6 +677,10 @@ void MetaServiceImpl::drop_partition(::google::protobuf::RpcController* controll
673677
return;
674678
}
675679
versioned_put(txn.get(), operation_log_key, operation_log_value);
680+
LOG(INFO) << "put drop partition operation log"
681+
<< " instance_id=" << instance_id << " table_id=" << request->table_id()
682+
<< " partition_ids=" << drop_partition_log.partition_ids_size()
683+
<< " log_size=" << operation_log_value.size();
676684
}
677685

678686
err = txn->commit();

cloud/test/meta_service_operation_log_test.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,14 @@ TEST(MetaServiceOperationLogTest, DropPartitionLog) {
285285
ASSERT_EQ(new_num_logs, num_logs)
286286
<< "Expected no new operation logs for drop partition 0, but found "
287287
<< new_num_logs - num_logs << dump_range(txn_kv.get());
288+
289+
// The recycle partition key must exists.
290+
std::string recycle_key = recycle_partition_key({instance_id, partition_id});
291+
std::unique_ptr<Transaction> txn;
292+
ASSERT_EQ(txn_kv->create_txn(&txn), TxnErrorCode::TXN_OK);
293+
std::string value;
294+
TxnErrorCode err = txn->get(recycle_key, &value);
295+
ASSERT_EQ(err, TxnErrorCode::TXN_OK);
288296
}
289297

290298
{
@@ -328,6 +336,16 @@ TEST(MetaServiceOperationLogTest, DropPartitionLog) {
328336
<< "Expected new operation logs for drop partition 3, but found "
329337
<< new_num_logs - num_logs << dump_range(txn_kv.get());
330338
num_logs = new_num_logs;
339+
340+
// The recycle partition key should not be exists.
341+
std::string recycle_key = recycle_partition_key({instance_id, partition_id + 3});
342+
std::unique_ptr<Transaction> txn;
343+
ASSERT_EQ(txn_kv->create_txn(&txn), TxnErrorCode::TXN_OK);
344+
std::string value;
345+
TxnErrorCode err = txn->get(recycle_key, &value);
346+
ASSERT_EQ(err, TxnErrorCode::TXN_KEY_NOT_FOUND)
347+
<< "Expected recycle partition key to not exist, but found it: " << hex(recycle_key)
348+
<< " with value: " << escape_hex(value);
331349
}
332350

333351
Versionstamp version1;

0 commit comments

Comments
 (0)