Coverage Report

Created: 2026-05-22 01:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/rowset/rowset_meta_manager.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
#ifndef DORIS_BE_SRC_OLAP_ROWSET_ROWSET_META_MANAGER_H
19
#define DORIS_BE_SRC_OLAP_ROWSET_ROWSET_META_MANAGER_H
20
21
#include <gen_cpp/olap_file.pb.h>
22
23
#include <cstdint>
24
#include <functional>
25
#include <map>
26
#include <optional>
27
#include <set>
28
#include <string>
29
#include <string_view>
30
#include <utility>
31
#include <vector>
32
33
#include "common/status.h"
34
#include "storage/olap_common.h"
35
#include "storage/rowset/rowset_meta.h"
36
37
namespace doris {
38
class OlapMeta;
39
class RowsetMetaPB;
40
class PartialUpdateInfoPB;
41
} // namespace doris
42
43
namespace doris {
44
namespace {
45
const std::string ROWSET_PREFIX = "rst_";
46
47
constexpr std::string_view PARTIAL_UPDATE_INFO_PREFIX = "pui_";
48
49
} // namespace
50
51
// Helper class for managing rowset meta of one root path.
52
class RowsetMetaManager {
53
public:
54
    static bool check_rowset_meta(OlapMeta* meta, TabletUid tablet_uid, const RowsetId& rowset_id);
55
    static Status exists(OlapMeta* meta, TabletUid tablet_uid, const RowsetId& rowset_id);
56
57
    static Status get_rowset_meta(OlapMeta* meta, TabletUid tablet_uid, const RowsetId& rowset_id,
58
                                  RowsetMetaSharedPtr rowset_meta);
59
    // TODO(Drogon): refactor save && _save_with_binlog to one, adapt to ut temperately
60
    static Status save(OlapMeta* meta, TabletUid tablet_uid, const RowsetId& rowset_id,
61
                       const RowsetMetaPB& rowset_meta_pb,
62
                       std::optional<BinlogFormatPB> binlog_format = std::nullopt,
63
                       const std::map<RowsetId, RowsetMetaPB>* attach_rowset_map = nullptr);
64
65
    // STATEMENT_AND_SNAPSHOT
66
    static Status save(OlapMeta* meta, TabletUid tablet_uid, const RowsetId& rowset_id,
67
22
                       const RowsetMetaPB& rowset_meta_pb, bool enable_binlog) {
68
22
        return save(meta, tablet_uid, rowset_id, rowset_meta_pb,
69
22
                    enable_binlog
70
22
                            ? std::optional<BinlogFormatPB>(BinlogFormatPB::STATEMENT_AND_SNAPSHOT)
71
22
                            : std::nullopt);
72
22
    }
73
74
    static std::vector<std::string> get_binlog_filenames(OlapMeta* meta, TabletUid tablet_uid,
75
                                                         std::string_view binlog_version,
76
                                                         int64_t segment_idx);
77
    static std::pair<std::string, int64_t> get_binlog_info(OlapMeta* meta, TabletUid tablet_uid,
78
                                                           std::string_view binlog_version);
79
    static std::string get_rowset_binlog_meta(OlapMeta* meta, TabletUid tablet_uid,
80
                                              std::string_view binlog_version,
81
                                              std::string_view rowset_id);
82
    static Status get_rowset_binlog_metas(OlapMeta* meta, const TabletUid tablet_uid,
83
                                          const std::vector<int64_t>& binlog_versions,
84
                                          RowsetBinlogMetasPB* metas_pb);
85
    // get all binlog metas of a tablet in version.
86
    static Status get_rowset_binlog_metas(OlapMeta* meta, const TabletUid tablet_uid,
87
                                          Version version, RowsetBinlogMetasPB* metas_pb);
88
    static Status remove_binlog(OlapMeta* meta, const std::string& suffix);
89
    static Status ingest_binlog_metas(OlapMeta* meta, TabletUid tablet_uid,
90
                                      RowsetBinlogMetasPB* metas_pb);
91
92
    static Status remove_row_binlog(OlapMeta* meta, TabletUid tablet_uid,
93
                                    const RowsetId& base_rowset_id,
94
                                    const RowsetId& row_binlog_rowset_id);
95
    static Status remove_row_binlog_metas(OlapMeta* meta, TabletUid tablet_uid,
96
                                          const std::set<RowsetId>& row_binlog_rowset_ids);
97
    static bool row_binlog_meta_exists(OlapMeta* meta, TabletUid tablet_uid,
98
                                       const RowsetId& row_binlog_rowset_id);
99
    static Status get_row_binlog_base_rowset_ids(
100
            OlapMeta* meta, TabletUid tablet_uid,
101
            std::map<RowsetId, RowsetId>& base_rowset_id_to_row_binlog,
102
            const std::set<RowsetId>& row_binlog_rowset_ids);
103
    static Status traverse_row_binlog_metas(
104
            OlapMeta* meta, std::function<bool(const TabletUid&, const RowsetId&, const RowsetId&,
105
                                               const std::string&)> const& func);
106
    static Status traverse_rowset_metas(OlapMeta* meta,
107
                                        std::function<bool(const TabletUid&, const RowsetId&,
108
                                                           std::string_view)> const& collector);
109
    static Status traverse_binlog_metas(
110
            OlapMeta* meta,
111
            std::function<bool(std::string_view, std::string_view, bool)> const& func);
112
113
    static Status remove(OlapMeta* meta, TabletUid tablet_uid, const RowsetId& rowset_id);
114
115
    static Status save_partial_update_info(OlapMeta* meta, int64_t tablet_id, int64_t partition_id,
116
                                           int64_t txn_id,
117
                                           const PartialUpdateInfoPB& partial_update_info_pb);
118
    static Status try_get_partial_update_info(OlapMeta* meta, int64_t tablet_id,
119
                                              int64_t partition_id, int64_t txn_id,
120
                                              PartialUpdateInfoPB* partial_update_info_pb);
121
    static Status traverse_partial_update_info(
122
            OlapMeta* meta,
123
            std::function<bool(int64_t, int64_t, int64_t, std::string_view)> const& func);
124
    static Status remove_partial_update_info(OlapMeta* meta, int64_t tablet_id,
125
                                             int64_t partition_id, int64_t txn_id);
126
    static Status remove_partial_update_infos(
127
            OlapMeta* meta, const std::vector<std::tuple<int64_t, int64_t, int64_t>>& keys);
128
    static Status remove_tablet_related_partial_update_info(OlapMeta* meta, int64_t tablet_id);
129
130
private:
131
    static Status _save(OlapMeta* meta, TabletUid tablet_uid, const RowsetId& rowset_id,
132
                        const RowsetMetaPB& rowset_meta_pb);
133
    static Status _save_with_ccr_binlog(OlapMeta* meta, TabletUid tablet_uid,
134
                                        const RowsetId& rowset_id,
135
                                        const RowsetMetaPB& rowset_meta_pb);
136
    static Status _save_with_row_binlog(OlapMeta* meta, TabletUid tablet_uid,
137
                                        const RowsetId& rowset_id,
138
                                        const RowsetMetaPB& rowset_meta_pb,
139
                                        const std::map<RowsetId, RowsetMetaPB>& attach_rowset_map);
140
    static Status _get_rowset_binlog_metas(OlapMeta* meta, const TabletUid tablet_uid,
141
                                           const std::vector<int64_t>& binlog_versions,
142
                                           RowsetBinlogMetasPB* metas_pb);
143
    static Status _get_all_rowset_binlog_metas(OlapMeta* meta, const TabletUid tablet_uid,
144
                                               RowsetBinlogMetasPB* metas_pb);
145
};
146
147
} // namespace doris
148
149
#endif // DORIS_BE_SRC_OLAP_ROWSET_ROWSET_META_MANAGER_H