zhannngchen commented on code in PR #50062: URL: https://github.com/apache/doris/pull/50062#discussion_r2055482926
########## cloud/test/recycler_test.cpp: ########## @@ -3105,6 +3105,75 @@ TEST(CheckerTest, delete_bitmap_storage_optimize_check_abnormal) { ASSERT_EQ(expected_abnormal_rowsets, real_abnormal_rowsets); } +std::unique_ptr<MetaServiceProxy> get_meta_service() { + int ret = 0; + // MemKv + auto txn_kv = std::dynamic_pointer_cast<TxnKv>(std::make_shared<MemTxnKv>()); + if (txn_kv != nullptr) { + ret = txn_kv->init(); + [&] { ASSERT_EQ(ret, 0); }(); + } + [&] { ASSERT_NE(txn_kv.get(), nullptr); }(); + + std::unique_ptr<Transaction> txn; + EXPECT_EQ(txn_kv->create_txn(&txn), TxnErrorCode::TXN_OK); + txn->remove("\x00", "\xfe"); // This is dangerous if the fdb is not correctly set + EXPECT_EQ(txn->commit(), TxnErrorCode::TXN_OK); + + auto rs = std::make_shared<MockResourceManager>(txn_kv); + auto rl = std::make_shared<RateLimiter>(); + auto meta_service = std::make_unique<MetaServiceImpl>(txn_kv, rs, rl); + return std::make_unique<MetaServiceProxy>(std::move(meta_service)); +} + +MetaServiceCode get_delete_bitmap_lock(MetaServiceProxy* meta_service, int64_t table_id, + int64_t lock_id, int64_t initiator, int64_t expiration = 5) { + brpc::Controller cntl; + GetDeleteBitmapUpdateLockRequest req; + GetDeleteBitmapUpdateLockResponse res; + req.set_cloud_unique_id("test_cloud_unique_id"); + req.set_table_id(table_id); + req.set_expiration(expiration); + req.set_lock_id(lock_id); + req.set_initiator(initiator); + meta_service->get_delete_bitmap_update_lock( + reinterpret_cast<::google::protobuf::RpcController*>(&cntl), &req, &res, nullptr); + return res.status().code(); +} + +TEST(CheckerTest, check_compaction_key) { + config::enable_compaction_key_check = true; + config::compaction_key_check_expiration_diff_seconds = 0; + std::string instance_id = "test_check_compaction_key"; + [[maybe_unused]] auto sp = SyncPoint::get_instance(); + std::unique_ptr<int, std::function<void(int*)>> defer( + (int*)0x01, [](int*) { SyncPoint::get_instance()->clear_all_call_backs(); }); + sp->set_call_back("get_instance_id", [&](auto&& args) { + auto* ret = try_any_cast_ret<std::string>(args); + ret->first = instance_id; + ret->second = true; + }); + sp->enable_processing(); + + auto meta_service = get_meta_service(); + auto res_code = get_delete_bitmap_lock(meta_service.get(), 2, -1, 123); + ASSERT_EQ(res_code, MetaServiceCode::OK); + std::this_thread::sleep_for(std::chrono::seconds(6)); + res_code = get_delete_bitmap_lock(meta_service.get(), 2, 100, -1); + ASSERT_EQ(res_code, MetaServiceCode::OK); + + auto txn_kv = std::make_shared<MemTxnKv>(); + ASSERT_EQ(txn_kv->init(), 0); + + InstanceInfoPB instance; + instance.set_instance_id(instance_id); + auto obj_info = instance.add_obj_info(); + obj_info->set_id("1"); + InstanceChecker checker(meta_service->txn_kv(), instance_id); + ASSERT_EQ(checker.init(instance), 0); + ASSERT_EQ(checker.do_compaction_key_check(), 0); Review Comment: This case also needs to cover exceptional scenarios, you should construct a situation where the compaction key leaks, ensuring the checker can detect it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org