Skip to content

Commit

Permalink
7
Browse files Browse the repository at this point in the history
  • Loading branch information
Yukang-Lian committed Nov 22, 2024
1 parent a075197 commit 9b7297a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
13 changes: 6 additions & 7 deletions cloud/src/meta-service/meta_service_tablet_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,8 @@ MetaServiceResponseStatus batch_get_tablet_stats(Transaction* txn,
for (int j = 0; j < 5; ++j) {
auto stat = tablet_stats_values[i + j];
int64_t val = 0;
bool value_miss = false;
// decode detached stat
if (stat.has_value() && j != 0) {
if (j != 0 && stat.has_value()) {
if (stat.value().size() != sizeof(val)) [[unlikely]] {
LOG(WARNING) << "malformed tablet stats data size value v.size="
<< stat.value().size();
Expand All @@ -219,8 +218,6 @@ MetaServiceResponseStatus batch_get_tablet_stats(Transaction* txn,
if constexpr (std::endian::native == std::endian::big) {
val = bswap_64(val);
}
} else if (j != 0) {
value_miss = true;
}

switch (j) {
Expand All @@ -234,24 +231,26 @@ MetaServiceResponseStatus batch_get_tablet_stats(Transaction* txn,
st.set_code(cast_as<ErrCategory::READ>(TxnErrorCode::TXN_KEY_NOT_FOUND));
return st;
}
break;
// handle data_size stat
case 1:
detached_tablet_stat.data_size = val;
break;
// handle num_rows stat
case 2:
detached_tablet_stat.num_rows = val;
break;
// handle num_rowsets stat
case 3:
detached_tablet_stat.num_rowsets = val;
break;
// handle num_segs stat
case 4:
detached_tablet_stat.num_segs = val;
break;
default:
return st;
}
if (value_miss) {
DCHECK_EQ(tablet_stat_pb.num_segments(), 0);
}
}
merge_tablet_stats(tablet_stat_pb, detached_tablet_stat);
tablet_stats_pb_vec.emplace_back(std::move(tablet_stat_pb));
Expand Down
10 changes: 10 additions & 0 deletions cloud/test/fdb_injection_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <foundationdb/fdb_c_options.g.h>
#include <foundationdb/fdb_c_types.h>
#include <gen_cpp/cloud.pb.h>
#include <google/protobuf/message.h>
#include <gtest/gtest.h>

#include <chrono>
Expand Down Expand Up @@ -710,10 +711,19 @@ static Status get_tablet_stats(MetaService* service, const std::string& instance
brpc::Controller ctrl;
cloud::GetTabletStatsRequest req;
cloud::GetTabletStatsResponse resp;
cloud::GetTabletStatsResponse resp_batch;
req.set_cloud_unique_id(cloud_unique_id(instance_id));
auto* tablet_idx = req.mutable_tablet_idx()->Add();
tablet_idx->set_tablet_id(tablet_id);

config::enable_concurrency_get_tablet_stats = true;
service->get_tablet_stats(&ctrl, &req, &resp_batch, nullptr);

config::enable_concurrency_get_tablet_stats = false;
service->get_tablet_stats(&ctrl, &req, &resp, nullptr);

EXPECT_EQ(resp_batch.DebugString(), resp.DebugString());

if (ctrl.Failed()) {
LOG_ERROR("get tablet stats")
.tag("instance_id", instance_id)
Expand Down
9 changes: 9 additions & 0 deletions cloud/test/meta_service_http_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,21 @@ static void get_tablet_stats(MetaService* meta_service, int64_t table_id, int64_
int64_t partition_id, int64_t tablet_id, GetTabletStatsResponse& res) {
brpc::Controller cntl;
GetTabletStatsRequest req;
cloud::GetTabletStatsResponse res_batch;
auto idx = req.add_tablet_idx();
idx->set_table_id(table_id);
idx->set_index_id(index_id);
idx->set_partition_id(partition_id);
idx->set_tablet_id(tablet_id);

sleep(10);
config::enable_concurrency_get_tablet_stats = true;
meta_service->get_tablet_stats(&cntl, &req, &res_batch, nullptr);

config::enable_concurrency_get_tablet_stats = false;
meta_service->get_tablet_stats(&cntl, &req, &res, nullptr);

EXPECT_EQ(res_batch.DebugString(), res.DebugString());
}

static void begin_txn(MetaService* meta_service, int64_t db_id, const std::string& label,
Expand Down
9 changes: 9 additions & 0 deletions cloud/test/meta_service_job_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,18 @@ void get_tablet_stats(MetaService* meta_service, int64_t tablet_id, TabletStatsP
brpc::Controller cntl;
GetTabletStatsRequest req;
GetTabletStatsResponse res;
cloud::GetTabletStatsResponse res_batch;
auto idx = req.add_tablet_idx();
idx->set_tablet_id(tablet_id);

config::enable_concurrency_get_tablet_stats = true;
meta_service->get_tablet_stats(&cntl, &req, &res_batch, nullptr);

config::enable_concurrency_get_tablet_stats = false;
meta_service->get_tablet_stats(&cntl, &req, &res, nullptr);

EXPECT_EQ(res_batch.DebugString(), res.DebugString());

ASSERT_EQ(res.status().code(), MetaServiceCode::OK) << tablet_id;
stats = res.tablet_stats(0);
}
Expand Down
8 changes: 8 additions & 0 deletions cloud/test/meta_service_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4342,12 +4342,20 @@ static void get_tablet_stats(MetaServiceProxy* meta_service, int64_t table_id, i
int64_t partition_id, int64_t tablet_id, GetTabletStatsResponse& res) {
brpc::Controller cntl;
GetTabletStatsRequest req;
cloud::GetTabletStatsResponse res_batch;
auto idx = req.add_tablet_idx();
idx->set_table_id(table_id);
idx->set_index_id(index_id);
idx->set_partition_id(partition_id);
idx->set_tablet_id(tablet_id);

config::enable_concurrency_get_tablet_stats = true;
meta_service->get_tablet_stats(&cntl, &req, &res_batch, nullptr);

config::enable_concurrency_get_tablet_stats = false;
meta_service->get_tablet_stats(&cntl, &req, &res, nullptr);

EXPECT_EQ(res_batch.DebugString(), res.DebugString());
}

TEST(MetaServiceTest, UpdateTablet) {
Expand Down

0 comments on commit 9b7297a

Please sign in to comment.