Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bobhan1 committed Dec 10, 2024
1 parent 2baf2dd commit 0df6084
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 6 deletions.
18 changes: 13 additions & 5 deletions cloud/src/meta-service/meta_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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<ErrCategory::CREATE>(err);
msg = "failed to init txn";
return;
}

for (const auto& tablet_index : request->tablet_indexes()) {
TabletIndexPB idx(tablet_index);
TabletStatsPB tablet_stat;
Expand All @@ -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());
Expand All @@ -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;
}
}
Expand Down
95 changes: 94 additions & 1 deletion cloud/test/meta_service_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::array<int64_t, 2>>& tablet_idxes) {
std::unique_ptr<Transaction> 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<ResourceManager>& rc_mgr,
const std::string& cloud_unique_id);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -4530,6 +4550,79 @@ 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<int, std::function<void(int*)>> defer((int*)0x01, [](int*) {
SyncPoint::get_instance()->disable_processing();
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();

// store tablet stats
int64_t db_id = 1000;
int64_t table_id = 2001;
int64_t index_id = 3001;
// [(partition_id, tablet_id)]
std::vector<std::array<int64_t, 2>> 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;
Expand Down

0 comments on commit 0df6084

Please sign in to comment.