Coverage Report

Created: 2026-03-16 19:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/compaction/compaction_profile_mgr.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
#include <rapidjson/document.h>
21
22
#include <atomic>
23
#include <cstdint>
24
#include <deque>
25
#include <shared_mutex>
26
#include <string>
27
#include <vector>
28
29
namespace doris {
30
31
enum class CompactionProfileType : uint8_t {
32
    BASE = 0,
33
    CUMULATIVE = 1,
34
    FULL = 2,
35
    SINGLE_REPLICA = 3,
36
    COLD_DATA = 4,
37
    INDEX_CHANGE = 5,
38
};
39
40
const char* to_string(CompactionProfileType type);
41
42
struct CompactionProfileRecord {
43
    int64_t compaction_id {0};
44
    CompactionProfileType compaction_type {CompactionProfileType::BASE};
45
    int64_t tablet_id {0};
46
    int64_t start_time_ms {0};
47
    int64_t end_time_ms {0};
48
    int64_t cost_time_ms {0};
49
    bool success {false};
50
    std::string status_msg;
51
52
    // input stats (from member variables, available in all paths)
53
    int64_t input_rowsets_data_size {0};
54
    int64_t input_rowsets_count {0};
55
    int64_t input_row_num {0};
56
    int64_t input_segments_num {0};
57
    int64_t input_rowsets_index_size {0};
58
    int64_t input_rowsets_total_size {0};
59
60
    // merge stats (from Merger::Statistics, updated in merge path)
61
    int64_t merged_rows {0};
62
    int64_t filtered_rows {0};
63
    int64_t output_rows {0};
64
65
    // output rowset stats (available when _output_rowset is built)
66
    int64_t output_rowset_data_size {0};
67
    int64_t output_row_num {0};
68
    int64_t output_segments_num {0};
69
    int64_t output_rowset_index_size {0};
70
    int64_t output_rowset_total_size {0};
71
72
    // timer (from RuntimeProfile, updated in merge path, 0 for ordered path)
73
    int64_t merge_rowsets_latency_ns {0};
74
75
    // IO stats
76
    int64_t bytes_read_from_local {0};
77
    int64_t bytes_read_from_remote {0};
78
79
    // version info
80
    std::string output_version;
81
82
    void to_json(rapidjson::Value& obj, rapidjson::Document::AllocatorType& allocator) const;
83
};
84
85
class CompactionProfileManager {
86
public:
87
    static CompactionProfileManager* instance();
88
89
702
    int64_t next_compaction_id() { return _next_id.fetch_add(1, std::memory_order_relaxed); }
90
91
    void add_record(CompactionProfileRecord record);
92
93
    // Non-const: when config=0, upgrades to write lock to clear stale records.
94
    std::vector<CompactionProfileRecord> get_records(int64_t tablet_id = 0, int64_t top_n = 0);
95
96
private:
97
1
    CompactionProfileManager() = default;
98
99
    void _trim_locked();
100
101
    std::atomic<int64_t> _next_id {1};
102
103
    std::shared_mutex _mutex;
104
    std::deque<CompactionProfileRecord> _records;
105
};
106
107
} // namespace doris