Skip to content

Commit

Permalink
[BugFix] Fix incorrect compaction status show in JSON format (StarRoc…
Browse files Browse the repository at this point in the history
…ks#49376)

Signed-off-by: srlch <linzichao@starrocks.com>
  • Loading branch information
srlch authored Aug 8, 2024
1 parent 0d54682 commit d682471
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion be/src/storage/tablet_updates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3284,7 +3284,7 @@ void TabletUpdates::get_compaction_status(std::string* json_result) {
rapidjson::Value last_version_value;
std::string last_version_str =
strings::Substitute("$0_$1", last_version.major_number(), last_version.minor_number());
rowsets_count.SetString(last_version_str.c_str(), last_version_str.size(), root.GetAllocator());
last_version_value.SetString(last_version_str.c_str(), last_version_str.size(), root.GetAllocator());
root.AddMember("last_version", last_version_value, root.GetAllocator());

rapidjson::Document rowset_details;
Expand Down
12 changes: 11 additions & 1 deletion be/test/storage/tablet_updates_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ TEST_F(TabletUpdatesTest, compaction_score_enough_normal) {
}

// NOLINTNEXTLINE
void TabletUpdatesTest::test_horizontal_compaction(bool enable_persistent_index) {
void TabletUpdatesTest::test_horizontal_compaction(bool enable_persistent_index, bool show_status) {
auto orig = config::vertical_compaction_max_columns_per_group;
config::vertical_compaction_max_columns_per_group = 5;
DeferOp unset_config([&] { config::vertical_compaction_max_columns_per_group = orig; });
Expand Down Expand Up @@ -1234,6 +1234,12 @@ void TabletUpdatesTest::test_horizontal_compaction(bool enable_persistent_index)
// the time interval is not enough after last compaction
EXPECT_EQ(best_tablet->updates()->get_compaction_score(), -1);
EXPECT_TRUE(best_tablet->verify().ok());

if (show_status) {
std::string json_result;
best_tablet->updates()->get_compaction_status(&json_result);
EXPECT_TRUE(json_result.find("\"last_version\": \"4_1\"") != std::string::npos);
}
}

// NOLINTNEXTLINE
Expand Down Expand Up @@ -3704,4 +3710,8 @@ TEST_F(TabletUpdatesTest, test_compaction_apply_retry) {
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}

TEST_F(TabletUpdatesTest, test_get_compaction_status) {
test_horizontal_compaction(false, true);
}

} // namespace starrocks
2 changes: 1 addition & 1 deletion be/test/storage/tablet_updates_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ class TabletUpdatesTest : public testing::Test {
void test_compaction_score_not_enough(bool enable_persistent_index);
void test_compaction_score_enough_duplicate(bool enable_persistent_index);
void test_compaction_score_enough_normal(bool enable_persistent_index);
void test_horizontal_compaction(bool enable_persistent_index);
void test_horizontal_compaction(bool enable_persistent_index, bool show_status = false);
void test_vertical_compaction(bool enable_persistent_index);
void test_horizontal_compaction_with_rows_mapper(bool enable_persistent_index);
void test_vertical_compaction_with_rows_mapper(bool enable_persistent_index);
Expand Down

0 comments on commit d682471

Please sign in to comment.