From 86d4945395681fc6ffe70b734ec91fcfff5ee96c Mon Sep 17 00:00:00 2001 From: bobhan1 Date: Tue, 10 Dec 2024 11:56:11 +0800 Subject: [PATCH] update --- cloud/src/meta-service/meta_service.cpp | 18 +++-- cloud/test/meta_service_test.cpp | 92 ++++++++++++++++++++++++- 2 files changed, 104 insertions(+), 6 deletions(-) diff --git a/cloud/src/meta-service/meta_service.cpp b/cloud/src/meta-service/meta_service.cpp index 569d36a232cc0ef..76f51a6f71a38c2 100644 --- a/cloud/src/meta-service/meta_service.cpp +++ b/cloud/src/meta-service/meta_service.cpp @@ -1865,7 +1865,7 @@ void MetaServiceImpl::update_delete_bitmap(google::protobuf::RpcController* cont request->lock_id(), request->initiator())) { LOG(WARNING) << "failed to check delete bitmap lock, table_id=" << table_id << " request lock_id=" << request->lock_id() - << " request initiator=" << request->initiator() << " msg" << msg; + << " request initiator=" << request->initiator() << " msg " << msg; return; } } @@ -2179,6 +2179,14 @@ void MetaServiceImpl::get_delete_bitmap_update_lock(google::protobuf::RpcControl // 2. read tablets' stats // 3. check whether we still hold the delete bitmap update lock // these steps can be done in different fdb txns + + err = txn_kv_->create_txn(&txn); + if (err != TxnErrorCode::TXN_OK) { + code = cast_as(err); + msg = "failed to init txn"; + return; + } + for (const auto& tablet_index : request->tablet_indexes()) { TabletIndexPB idx(tablet_index); TabletStatsPB tablet_stat; @@ -2203,9 +2211,9 @@ void MetaServiceImpl::get_delete_bitmap_update_lock(google::protobuf::RpcControl response->clear_cumulative_compaction_cnts(); response->clear_cumulative_points(); LOG_WARNING( - "failed to get tablet stats when get_delete_bitmap_update_lock, " - "lock_id={}, initiator={}, tablet_id={}", - request->lock_id(), request->initiator(), tablet_index.tablet_id()); + "failed to get tablet stats when internal_get_tablet_stats, " + "lock_id={}, initiator={}, tablet_id={}, msg={}", + request->lock_id(), request->initiator(), tablet_index.tablet_id(), msg); return; } response->add_base_compaction_cnts(tablet_stat.base_compaction_cnt()); @@ -2217,7 +2225,7 @@ void MetaServiceImpl::get_delete_bitmap_update_lock(google::protobuf::RpcControl request->initiator())) { LOG(WARNING) << "failed to check delete bitmap lock after get tablet stats, table_id=" << table_id << " request lock_id=" << request->lock_id() - << " request initiator=" << request->initiator() << " msg" << msg; + << " request initiator=" << request->initiator() << " msg " << msg; return; } } diff --git a/cloud/test/meta_service_test.cpp b/cloud/test/meta_service_test.cpp index d2dd80f6871e3e1..d178f66fb11a6ee 100644 --- a/cloud/test/meta_service_test.cpp +++ b/cloud/test/meta_service_test.cpp @@ -230,6 +230,26 @@ static void insert_rowset(MetaServiceProxy* meta_service, int64_t db_id, const s commit_txn(meta_service, db_id, txn_id, label); } +static void add_tablet_stats(MetaServiceProxy* meta_service, std::string instance_id, + int64_t table_id, int64_t index_id, + const std::vector>& tablet_idxes) { + std::unique_ptr txn; + ASSERT_EQ(meta_service->txn_kv()->create_txn(&txn), TxnErrorCode::TXN_OK); + + for (const auto& idx : tablet_idxes) { + int64_t partition_id = idx[0]; + int64_t tablet_id = idx[1]; + std::string stats_key = + stats_tablet_key({instance_id, table_id, index_id, partition_id, tablet_id}); + TabletStatsPB stats; + stats.set_base_compaction_cnt(10); + stats.set_cumulative_compaction_cnt(20); + stats.set_cumulative_point(30); + txn->put(stats_key, stats.SerializeAsString()); + } + ASSERT_EQ(txn->commit(), TxnErrorCode::TXN_OK); +} + TEST(MetaServiceTest, GetInstanceIdTest) { extern std::string get_instance_id(const std::shared_ptr& rc_mgr, const std::string& cloud_unique_id); @@ -4488,7 +4508,7 @@ TEST(MetaServiceTest, GetTabletStatsTest) { EXPECT_EQ(res.tablet_stats(0).segment_size(), 40000); } -TEST(MetaServiceTest, GetDeleteBitmapUpdateLock) { +TEST(MetaServiceTest, GetDeleteBitmapUpdateLockNoReadStats) { auto meta_service = get_meta_service(); brpc::Controller cntl; @@ -4530,6 +4550,76 @@ TEST(MetaServiceTest, GetDeleteBitmapUpdateLock) { ASSERT_EQ(res.status().code(), MetaServiceCode::OK); } +TEST(MetaServiceTest, GetDeleteBitmapUpdateLockTabletStats) { + auto meta_service = get_meta_service(); + + { + // 1. normal path + std::string instance_id = "test_get_delete_bitmap_update_lock_normal"; + [[maybe_unused]] auto* sp = SyncPoint::get_instance(); + std::unique_ptr> 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(args); + ret->first = instance_id; + ret->second = true; + }); + + // store tablet stats + int64_t db_id = 1000; + int64_t table_id = 2001; + int64_t index_id = 3001; + // [(partition_id, tablet_id)] + std::vector> tablet_idxes { + {70001, 12345}, {80001, 3456}, {90001, 6789}}; + + add_tablet_stats(meta_service.get(), instance_id, table_id, index_id, tablet_idxes); + + brpc::Controller cntl; + GetDeleteBitmapUpdateLockRequest req; + GetDeleteBitmapUpdateLockResponse res; + req.set_cloud_unique_id("test_cloud_unique_id"); + req.set_table_id(table_id); + for (const auto& [partition_id, _] : tablet_idxes) { + req.add_partition_ids(partition_id); + } + req.set_expiration(5); + req.set_lock_id(999999); + req.set_initiator(-1); + req.set_require_compaction_stats(true); + for (const auto& [partition_id, tablet_id] : tablet_idxes) { + TabletIndexPB* idx = req.add_tablet_indexes(); + idx->set_db_id(db_id); + idx->set_table_id(table_id); + idx->set_index_id(index_id); + idx->set_partition_id(partition_id); + idx->set_tablet_id(tablet_id); + } + + meta_service->get_delete_bitmap_update_lock( + reinterpret_cast<::google::protobuf::RpcController*>(&cntl), &req, &res, nullptr); + ASSERT_EQ(res.status().code(), MetaServiceCode::OK); + + ASSERT_EQ(res.base_compaction_cnts().size(), tablet_idxes.size()); + for (const auto& base_compaction_cnt : res.base_compaction_cnts()) { + ASSERT_EQ(base_compaction_cnt, 10); + } + ASSERT_EQ(res.cumulative_compaction_cnts().size(), tablet_idxes.size()); + for (const auto& cumu_compaction_cnt : res.cumulative_compaction_cnts()) { + ASSERT_EQ(cumu_compaction_cnt, 20); + } + ASSERT_EQ(res.cumulative_points().size(), tablet_idxes.size()); + for (const auto& cumulative_point : res.cumulative_points()) { + ASSERT_EQ(cumulative_point, 30); + } + } + + { + ; + ; + } +} + static std::string generate_random_string(int length) { std::string char_set = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; std::random_device rd;