Skip to content

Commit

Permalink
[BugFix] fix incorrect part of compaction profile
Browse files Browse the repository at this point in the history
Signed-off-by: starrocks-xupeng <[email protected]>
  • Loading branch information
starrocks-xupeng committed Jan 3, 2025
1 parent a0b2a63 commit 84224f1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion be/src/storage/lake/compaction_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ CompactionTask::CompactionTask(VersionedTablet tablet, std::vector<std::shared_p

Status CompactionTask::execute_index_major_compaction(TxnLogPB* txn_log) {
if (_tablet.get_schema()->keys_type() == KeysType::PRIMARY_KEYS) {
SCOPED_RAW_TIMER(&_context->stats->sst_merge_ns);
SCOPED_RAW_TIMER(&_context->stats->pk_sst_merge_ns);
auto metadata = _tablet.metadata();
if (metadata->enable_persistent_index() &&
metadata->persistent_index_type() == PersistentIndexTypePB::CLOUD_NATIVE) {
Expand Down
6 changes: 5 additions & 1 deletion be/src/storage/lake/compaction_task_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ CompactionTaskStats CompactionTaskStats::operator+(const CompactionTaskStats& th
diff.column_iterator_init_ns = column_iterator_init_ns + that.column_iterator_init_ns;
diff.io_count_local_disk = io_count_local_disk + that.io_count_local_disk;
diff.io_count_remote = io_count_remote + that.io_count_remote;
diff.in_queue_time_sec = in_queue_time_sec + that.in_queue_time_sec;
diff.pk_sst_merge_ns = pk_sst_merge_ns + that.pk_sst_merge_ns;
return diff;
}

Expand All @@ -59,6 +61,8 @@ CompactionTaskStats CompactionTaskStats::operator-(const CompactionTaskStats& th
diff.column_iterator_init_ns = column_iterator_init_ns - that.column_iterator_init_ns;
diff.io_count_local_disk = io_count_local_disk - that.io_count_local_disk;
diff.io_count_remote = io_count_remote - that.io_count_remote;
diff.in_queue_time_sec = in_queue_time_sec - that.in_queue_time_sec;
diff.pk_sst_merge_ns = pk_sst_merge_ns - that.pk_sst_merge_ns;
return diff;
}

Expand All @@ -77,7 +81,7 @@ std::string CompactionTaskStats::to_json_stats() {
root.AddMember("column_iterator_init_sec", rapidjson::Value(column_iterator_init_ns / TIME_UNIT_NS_PER_SECOND),
allocator);
root.AddMember("in_queue_sec", rapidjson::Value(in_queue_time_sec), allocator);
root.AddMember("sst_merge_sec", rapidjson::Value(sst_merge_ns / TIME_UNIT_NS_PER_SECOND), allocator);
root.AddMember("pk_sst_merge_sec", rapidjson::Value(pk_sst_merge_ns / TIME_UNIT_NS_PER_SECOND), allocator);

rapidjson::StringBuffer strbuf;
rapidjson::Writer<rapidjson::StringBuffer> writer(strbuf);
Expand Down
2 changes: 1 addition & 1 deletion be/src/storage/lake/compaction_task_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct CompactionTaskStats {
int64_t io_count_local_disk = 0;
int64_t io_count_remote = 0;
int64_t in_queue_time_sec = 0;
int64_t sst_merge_ns = 0;
int64_t pk_sst_merge_ns = 0;

void collect(const OlapReaderStatistics& reader_stats);
CompactionTaskStats operator+(const CompactionTaskStats& that) const;
Expand Down
10 changes: 10 additions & 0 deletions be/test/storage/lake/compaction_task_context_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ TEST_F(CompactionTaskContextTest, test_calculation) {
reader_stats.compressed_bytes_read_remote = 1024;
reader_stats.compressed_bytes_read_local_disk = 1024;

stats.in_queue_time_sec = 5;
stats.pk_sst_merge_ns = 5;
stats.collect(reader_stats);

EXPECT_EQ(stats.io_ns_remote, 200);
Expand All @@ -80,6 +82,8 @@ TEST_F(CompactionTaskContextTest, test_calculation) {
EXPECT_EQ(stats.io_count_remote, 700);
EXPECT_EQ(stats.io_bytes_read_remote, 1024);
EXPECT_EQ(stats.io_bytes_read_local_disk, 1024);
EXPECT_EQ(stats.in_queue_time_sec, 5);
EXPECT_EQ(stats.pk_sst_merge_ns, 5);

CompactionTaskStats after_add = stats + stats;

Expand All @@ -91,6 +95,8 @@ TEST_F(CompactionTaskContextTest, test_calculation) {
EXPECT_EQ(after_add.io_count_remote, 1400);
EXPECT_EQ(after_add.io_bytes_read_remote, 2048);
EXPECT_EQ(after_add.io_bytes_read_local_disk, 2048);
EXPECT_EQ(after_add.in_queue_time_sec, 10);
EXPECT_EQ(after_add.pk_sst_merge_ns, 10);

CompactionTaskStats after_minus = stats - stats;

Expand All @@ -102,6 +108,8 @@ TEST_F(CompactionTaskContextTest, test_calculation) {
EXPECT_EQ(after_minus.io_count_remote, 0);
EXPECT_EQ(after_minus.io_bytes_read_remote, 0);
EXPECT_EQ(after_minus.io_bytes_read_local_disk, 0);
EXPECT_EQ(after_minus.in_queue_time_sec, 0);
EXPECT_EQ(after_minus.pk_sst_merge_ns, 0);
}

TEST_F(CompactionTaskContextTest, test_to_json_stats) {
Expand All @@ -118,6 +126,7 @@ TEST_F(CompactionTaskContextTest, test_to_json_stats) {
context.stats->segment_init_ns = 3 * TIME_UNIT_NS_PER_SECOND;
context.stats->column_iterator_init_ns = 4 * TIME_UNIT_NS_PER_SECOND;
context.stats->in_queue_time_sec = 5;
context.stats->pk_sst_merge_ns = 5 * TIME_UNIT_NS_PER_SECOND;

// Call the method under test
std::string json_stats = context.stats->to_json_stats();
Expand All @@ -130,5 +139,6 @@ TEST_F(CompactionTaskContextTest, test_to_json_stats) {
EXPECT_THAT(json_stats, testing::HasSubstr(R"("read_remote_count":3)"));
EXPECT_THAT(json_stats, testing::HasSubstr(R"("read_local_count":2)"));
EXPECT_THAT(json_stats, testing::HasSubstr(R"("in_queue_sec":5)"));
EXPECT_THAT(json_stats, testing::HasSubstr(R"("pk_sst_merge_sec":5)"));
}
} // namespace starrocks::lake

0 comments on commit 84224f1

Please sign in to comment.