Coverage Report

Created: 2026-09-01 18:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/cloud/cloud_cumulative_compaction.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 <limits>
21
#include <memory>
22
#include <optional>
23
#include <string_view>
24
#include <vector>
25
26
#include "cloud/cloud_storage_engine.h"
27
#include "cloud/cloud_tablet.h"
28
#include "storage/compaction/compaction.h"
29
#include "storage/compaction_task_tracker.h"
30
#include "storage/tablet/tablet_fwd.h"
31
32
namespace doris {
33
34
class RowsetMeta;
35
36
namespace cloud {
37
38
struct SegmentGroupMergeRange {
39
    int64_t segment_start;
40
    int64_t segment_end;
41
    int64_t merge_way_num;
42
};
43
44
bool is_single_rowset_compaction_candidate(const RowsetSharedPtr& rowset);
45
46
bool should_use_single_rowset_grouped_compaction(const std::vector<RowsetSharedPtr>& input_rowsets,
47
                                                 const TabletSchema& tablet_schema,
48
                                                 std::string_view compaction_policy);
49
50
std::vector<SegmentGroupMergeRange> build_segment_group_merge_ranges(const RowsetMeta& rowset_meta,
51
                                                                     int64_t segment_group_size);
52
53
} // namespace cloud
54
55
class CloudCumulativeCompaction : public CloudCompactionMixin {
56
public:
57
    CloudCumulativeCompaction(CloudStorageEngine& engine, CloudTabletSPtr tablet);
58
59
    ~CloudCumulativeCompaction() override;
60
61
    Status prepare_compact() override;
62
    Status execute_compact() override;
63
    Status request_global_lock();
64
65
8.93k
    std::optional<CompactionProfileType> profile_type() const override {
66
8.93k
        return CompactionProfileType::CUMULATIVE;
67
8.93k
    }
68
18.1k
    int64_t input_segments_num_value() const override { return _input_segments; }
69
70
    void do_lease();
71
72
8.97k
    int64_t get_input_rowsets_bytes() const { return _input_rowsets_total_size; }
73
8.97k
    int64_t get_input_num_rows() const { return _input_row_num; }
74
75
private:
76
    Status advance_cumulative_point_before_pick(int64_t min_conflict_version);
77
78
    Status pick_rowsets_to_compact();
79
80
    Status prepare_merge_input_rowsets(MergeInputRowsetsResult* result) override;
81
82
    Status do_merge_input_rowsets(const std::vector<RowsetReaderSharedPtr>& input_rs_readers,
83
                                  MergeInputRowsetsResult* result) override;
84
85
    void update_output_rowset_after_build(const MergeInputRowsetsResult& result) override;
86
87
    bool should_calculate_new_cumulative_point(int64_t input_cumulative_point) const;
88
89
9.04k
    std::string_view compaction_name() const override { return "CloudCumulativeCompaction"; }
90
91
protected:
92
    Status modify_rowsets() override;
93
94
private:
95
    Status garbage_collection() override;
96
97
    void update_cumulative_point(int64_t input_cumulative_point, int64_t output_cumulative_point);
98
99
38.8k
    ReaderType compaction_type() const override { return ReaderType::READER_CUMULATIVE_COMPACTION; }
100
101
    int64_t _input_segments = 0;
102
    // A task must use one execution mode even if the dynamic config changes while it is running.
103
    const bool _enable_parallel_cumu_compaction;
104
    int64_t _min_conflict_version = std::numeric_limits<int64_t>::max();
105
    int64_t _max_conflict_version = 0;
106
    // Snapshot values when pick input rowsets
107
    int64_t _base_compaction_cnt = 0;
108
    int64_t _cumulative_compaction_cnt = 0;
109
    int64_t _picked_cumulative_point = 0;
110
    Version _last_delete_version {-1, -1};
111
    std::optional<int64_t> _single_rowset_compaction_segment_group_size;
112
};
113
114
} // namespace doris