From d2e3644cb17cbe2e5abef0af1b0760d447b703a4 Mon Sep 17 00:00:00 2001 From: csun5285 Date: Mon, 16 Dec 2024 13:31:38 +0800 Subject: [PATCH 1/3] [fix](cloud) fix error in get detached tablet stat --- .../meta_service_tablet_stats.cpp | 9 +- cloud/test/CMakeLists.txt | 1 + cloud/test/meta_service_tablet_stats_test.cpp | 108 ++++++++++++++++++ 3 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 cloud/test/meta_service_tablet_stats_test.cpp diff --git a/cloud/src/meta-service/meta_service_tablet_stats.cpp b/cloud/src/meta-service/meta_service_tablet_stats.cpp index 4cbf629c9a3185..be50c54028cb66 100644 --- a/cloud/src/meta-service/meta_service_tablet_stats.cpp +++ b/cloud/src/meta-service/meta_service_tablet_stats.cpp @@ -94,7 +94,8 @@ int get_detached_tablet_stats(const std::vector +#include + +#include "meta-service/codec.h" +#include "meta-service/keys.h" + +namespace doris::cloud { + +std::string size_value(int64_t tablet_stat_data_size) { + std::string tablet_stat_data_size_value(sizeof(tablet_stat_data_size), '\0'); + memcpy(tablet_stat_data_size_value.data(), &tablet_stat_data_size, + sizeof(tablet_stat_data_size)); + return tablet_stat_data_size_value; +} + +TEST(MetaServiceTabletStatsTest, test_get_detached_tablet_stats) { + std::vector> stats_kvs; + StatsTabletKeyInfo tablet_key_info {"instance_0", 10000, 10001, 10002, 10003}; + + // key->TabletStatsPB + TabletStatsPB tablet_stat; + std::string tablet_stat_key; + std::string tablet_stat_value; + stats_tablet_key(tablet_key_info, &tablet_stat_key); + tablet_stat.SerializeToString(&tablet_stat_value); + stats_kvs.emplace_back(tablet_stat_key, tablet_stat_value); + + // key->data_size + std::string tablet_stat_data_size_key; + stats_tablet_data_size_key(tablet_key_info, &tablet_stat_data_size_key); + stats_kvs.emplace_back(tablet_stat_data_size_key, size_value(100)); + + // key->num_rows + std::string tablet_stat_num_rows_key; + stats_tablet_num_rows_key(tablet_key_info, &tablet_stat_num_rows_key); + stats_kvs.emplace_back(tablet_stat_num_rows_key, size_value(10)); + + // key->num_rowsets + std::string tablet_stat_num_rowsets_key; + stats_tablet_num_rowsets_key(tablet_key_info, &tablet_stat_num_rowsets_key); + stats_kvs.emplace_back(tablet_stat_num_rowsets_key, size_value(1)); + + // key->num_segs + std::string tablet_stat_num_segs_key; + stats_tablet_num_segs_key(tablet_key_info, &tablet_stat_num_segs_key); + stats_kvs.emplace_back(tablet_stat_num_segs_key, size_value(1)); + + // key->index_size + std::string tablet_stat_index_size_key; + stats_tablet_index_size_key(tablet_key_info, &tablet_stat_index_size_key); + stats_kvs.emplace_back(tablet_stat_index_size_key, size_value(50)); + + // key->segment_size + std::string tablet_stat_segment_size_key; + stats_tablet_segment_size_key(tablet_key_info, &tablet_stat_segment_size_key); + stats_kvs.emplace_back(tablet_stat_segment_size_key, size_value(50)); + + TabletStats res1; + int ret = get_detached_tablet_stats(stats_kvs, res1); + EXPECT_EQ(ret, 0); + EXPECT_EQ(res1.data_size, 100); + EXPECT_EQ(res1.num_rows, 10); + EXPECT_EQ(res1.num_rowsets, 1); + EXPECT_EQ(res1.num_segs, 1); + EXPECT_EQ(res1.index_size, 50); + EXPECT_EQ(res1.segment_size, 50); + + stats_kvs.resize(5); + TabletStats res2; + ret = get_detached_tablet_stats(stats_kvs, res2); + EXPECT_EQ(ret, 0); + EXPECT_EQ(res1.data_size, 100); + EXPECT_EQ(res1.num_rows, 10); + EXPECT_EQ(res1.num_rowsets, 1); + EXPECT_EQ(res1.num_segs, 1); + + stats_kvs.resize(2); + TabletStats res3; + ret = get_detached_tablet_stats(stats_kvs, res3); + EXPECT_EQ(ret, 0); + EXPECT_EQ(res1.data_size, 100); + + stats_kvs.resize(1); + TabletStats res4; + ret = get_detached_tablet_stats(stats_kvs, res4); + EXPECT_EQ(ret, 0); +} + +} // namespace doris::cloud From 87d418dc14ee2c005564c870eadb94d144fb71ce Mon Sep 17 00:00:00 2001 From: csun5285 Date: Mon, 16 Dec 2024 13:44:57 +0800 Subject: [PATCH 2/3] fix comment --- cloud/src/meta-service/meta_service_tablet_stats.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cloud/src/meta-service/meta_service_tablet_stats.cpp b/cloud/src/meta-service/meta_service_tablet_stats.cpp index be50c54028cb66..da556b6c574557 100644 --- a/cloud/src/meta-service/meta_service_tablet_stats.cpp +++ b/cloud/src/meta-service/meta_service_tablet_stats.cpp @@ -149,7 +149,8 @@ int get_detached_tablet_stats(const std::vector