Coverage Report

Created: 2026-04-10 18:35

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