Coverage Report

Created: 2026-03-12 16:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/cloud/cloud_cumulative_compaction_policy.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 <stddef.h>
21
#include <stdint.h>
22
23
#include <memory>
24
#include <string>
25
#include <vector>
26
27
#include "cloud/cloud_tablet.h"
28
#include "common/config.h"
29
#include "storage/rowset/rowset.h"
30
#include "storage/rowset/rowset_meta.h"
31
32
namespace doris {
33
#include "common/compile_check_begin.h"
34
35
class Tablet;
36
struct Version;
37
38
class CloudCumulativeCompactionPolicy {
39
public:
40
262
    virtual ~CloudCumulativeCompactionPolicy() = default;
41
42
    virtual int64_t new_cumulative_point(CloudTablet* tablet, const RowsetSharedPtr& output_rowset,
43
                                         Version& last_delete_version,
44
                                         int64_t last_cumulative_point) = 0;
45
46
    virtual int64_t get_compaction_level(CloudTablet* tablet,
47
                                         const std::vector<RowsetSharedPtr>& input_rowsets,
48
                                         RowsetSharedPtr output_rowset) = 0;
49
50
    virtual int64_t pick_input_rowsets(CloudTablet* tablet,
51
                                       const std::vector<RowsetSharedPtr>& candidate_rowsets,
52
                                       const int64_t max_compaction_score,
53
                                       const int64_t min_compaction_score,
54
                                       std::vector<RowsetSharedPtr>* input_rowsets,
55
                                       Version* last_delete_version, size_t* compaction_score,
56
                                       bool allow_delete = false) = 0;
57
58
    virtual std::string name() = 0;
59
};
60
61
class CloudSizeBasedCumulativeCompactionPolicy : public CloudCumulativeCompactionPolicy {
62
public:
63
    CloudSizeBasedCumulativeCompactionPolicy(
64
            int64_t promotion_size = config::compaction_promotion_size_mbytes * 1024 * 1024,
65
            double promotion_ratio = config::compaction_promotion_ratio,
66
            int64_t promotion_min_size = config::compaction_promotion_min_size_mbytes * 1024 * 1024,
67
            int64_t compaction_min_size = config::compaction_min_size_mbytes * 1024 * 1024);
68
69
    ~CloudSizeBasedCumulativeCompactionPolicy() override = default;
70
71
    int64_t new_cumulative_point(CloudTablet* tablet, const RowsetSharedPtr& output_rowset,
72
                                 Version& last_delete_version,
73
                                 int64_t last_cumulative_point) override;
74
75
    int64_t get_compaction_level(CloudTablet* tablet,
76
                                 const std::vector<RowsetSharedPtr>& input_rowsets,
77
0
                                 RowsetSharedPtr output_rowset) override {
78
0
        return 0;
79
0
    }
80
81
    int64_t pick_input_rowsets(CloudTablet* tablet,
82
                               const std::vector<RowsetSharedPtr>& candidate_rowsets,
83
                               const int64_t max_compaction_score,
84
                               const int64_t min_compaction_score,
85
                               std::vector<RowsetSharedPtr>* input_rowsets,
86
                               Version* last_delete_version, size_t* compaction_score,
87
                               bool allow_delete = false) override;
88
89
9.71k
    std::string name() override { return "size_based"; }
90
91
private:
92
    int64_t _level_size(const int64_t size);
93
94
    int64_t cloud_promotion_size(CloudTablet* tablet) const;
95
96
private:
97
    /// cumulative compaction promotion size, unit is byte.
98
    int64_t _promotion_size;
99
    /// cumulative compaction promotion ratio of base rowset total disk size.
100
    double _promotion_ratio;
101
    /// cumulative compaction promotion min size, unit is byte.
102
    int64_t _promotion_min_size;
103
    /// lower bound size to do compaction compaction.
104
    int64_t _compaction_min_size;
105
};
106
107
class CloudTimeSeriesCumulativeCompactionPolicy : public CloudCumulativeCompactionPolicy {
108
public:
109
132
    CloudTimeSeriesCumulativeCompactionPolicy() = default;
110
    ~CloudTimeSeriesCumulativeCompactionPolicy() override = default;
111
112
    int64_t new_cumulative_point(CloudTablet* tablet, const RowsetSharedPtr& output_rowset,
113
                                 Version& last_delete_version,
114
                                 int64_t last_cumulative_point) override;
115
116
    int64_t get_compaction_level(CloudTablet* tablet,
117
                                 const std::vector<RowsetSharedPtr>& input_rowsets,
118
                                 RowsetSharedPtr output_rowset) override;
119
120
    int64_t pick_input_rowsets(CloudTablet* tablet,
121
                               const std::vector<RowsetSharedPtr>& candidate_rowsets,
122
                               const int64_t max_compaction_score,
123
                               const int64_t min_compaction_score,
124
                               std::vector<RowsetSharedPtr>* input_rowsets,
125
                               Version* last_delete_version, size_t* compaction_score,
126
                               bool allow_delete = false) override;
127
128
3
    std::string name() override { return "time_series"; }
129
};
130
131
void find_longest_consecutive_empty_rowsets(std::vector<RowsetSharedPtr>* result,
132
                                            const std::vector<RowsetSharedPtr>& candidate_rowsets);
133
134
#include "common/compile_check_end.h"
135
} // namespace doris