Skip to content

Commit

Permalink
add abnormal case
Browse files Browse the repository at this point in the history
  • Loading branch information
bobhan1 committed Dec 10, 2024
1 parent 0df6084 commit f74de71
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
1 change: 1 addition & 0 deletions cloud/src/meta-service/meta_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1689,6 +1689,7 @@ static bool check_delete_bitmap_lock(MetaServiceCode& code, std::string& msg, st
msg = "failed to parse DeleteBitmapUpdateLockPB";
return false;
}
TEST_SYNC_POINT_CALLBACK("check_delete_bitmap_lock.set_lock_info", &lock_info);
if (lock_info.lock_id() != lock_id) {
ss << "lock id not match, locked by lock_id=" << lock_info.lock_id();
msg = ss.str();
Expand Down
57 changes: 55 additions & 2 deletions cloud/test/meta_service_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4618,8 +4618,61 @@ TEST(MetaServiceTest, GetDeleteBitmapUpdateLockTabletStats) {
}

{
;
;
// 2.1 abnormal path, lock has been expired and taken by another load/compaction during
// the reading of tablet stats
std::string instance_id = "test_get_delete_bitmap_update_lock_abnormal1";
[[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->set_call_back("check_delete_bitmap_lock.set_lock_info", [&](auto&& args) {
auto* lock_info = try_any_cast<DeleteBitmapUpdateLockPB*>(args[0]);
lock_info->set_lock_id(345);
LOG(INFO) << "change lock_info.lock_id to 345, lock_info=" << lock_info->DebugString();
});

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(0);
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::LOCK_EXPIRED);
}
}

Expand Down

0 comments on commit f74de71

Please sign in to comment.