diff --git a/be/src/storage/tablet_updates.cpp b/be/src/storage/tablet_updates.cpp index 8f08141f17b47..060fa45cbf8b7 100644 --- a/be/src/storage/tablet_updates.cpp +++ b/be/src/storage/tablet_updates.cpp @@ -3266,7 +3266,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; diff --git a/be/test/storage/tablet_updates_test.cpp b/be/test/storage/tablet_updates_test.cpp index d437ccf1cf8de..6fcf1299631ef 100644 --- a/be/test/storage/tablet_updates_test.cpp +++ b/be/test/storage/tablet_updates_test.cpp @@ -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; }); @@ -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 @@ -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 diff --git a/be/test/storage/tablet_updates_test.h b/be/test/storage/tablet_updates_test.h index d94cfd248631d..5024401ab8705 100644 --- a/be/test/storage/tablet_updates_test.h +++ b/be/test/storage/tablet_updates_test.h @@ -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);