Coverage Report

Created: 2026-08-10 15:19

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(
61
            OlapMeta* meta, TabletUid tablet_uid, const RowsetId& rowset_id,
62
            const RowsetMetaPB& rowset_meta_pb,
63
            std::optional<BinlogFormatPB> binlog_format = std::nullopt,
64
            const std::optional<RowsetMetaPB>& attach_row_binlog_rowset_meta = std::nullopt);
65
66
    // STATEMENT_AND_SNAPSHOT
67
    static Status save(OlapMeta* meta, TabletUid tablet_uid, const RowsetId& rowset_id,
68
22
                       const RowsetMetaPB& rowset_meta_pb, bool enable_binlog) {
69
22
        return save(meta, tablet_uid, rowset_id, rowset_meta_pb,
70
22
                    enable_binlog
71
22
                            ? std::optional<BinlogFormatPB>(BinlogFormatPB::STATEMENT_AND_SNAPSHOT)
72
22
                            : std::nullopt);
73
22
    }
74
75
    static std::vector<std::string> get_binlog_filenames(OlapMeta* meta, TabletUid tablet_uid,
76
                                                         std::string_view binlog_version,
77
                                                         int64_t segment_idx);
78
    static std::pair<std::string, int64_t> get_binlog_info(OlapMeta* meta, TabletUid tablet_uid,
79
                                                           std::string_view binlog_version);
80
    static std::string get_rowset_binlog_meta(OlapMeta* meta, TabletUid tablet_uid,
81
                                              std::string_view binlog_version,
82
                                              std::string_view rowset_id);
83
    static Status get_rowset_binlog_metas(OlapMeta* meta, const TabletUid tablet_uid,
84
                                          const std::vector<int64_t>& binlog_versions,
85
                                          RowsetBinlogMetasPB* metas_pb);
86
    // get all binlog metas of a tablet in version.
87
    static Status get_rowset_binlog_metas(OlapMeta* meta, const TabletUid tablet_uid,
88
                                          Version version, RowsetBinlogMetasPB* metas_pb);
89
    static Status remove_binlog(OlapMeta* meta, const std::string& suffix);
90
    static Status ingest_binlog_metas(OlapMeta* meta, TabletUid tablet_uid,
91
                                      RowsetBinlogMetasPB* metas_pb);
92
93
    static Status traverse_rowset_metas(OlapMeta* meta,
94
                                        std::function<bool(const TabletUid&, const RowsetId&,
95
                                                           std::string_view)> const& collector);
96
    static Status traverse_binlog_metas(
97
            OlapMeta* meta,
98
            std::function<bool(std::string_view, std::string_view, bool)> const& func);
99
100
    static Status remove(OlapMeta* meta, TabletUid tablet_uid, const RowsetId& rowset_id);
101
102
    static Status save_partial_update_info(OlapMeta* meta, int64_t tablet_id, int64_t partition_id,
103
                                           int64_t txn_id,
104
                                           const PartialUpdateInfoPB& partial_update_info_pb);
105
    static Status try_get_partial_update_info(OlapMeta* meta, int64_t tablet_id,
106
                                              int64_t partition_id, int64_t txn_id,
107
                                              PartialUpdateInfoPB* partial_update_info_pb);
108
    static Status traverse_partial_update_info(
109
            OlapMeta* meta,
110
            std::function<bool(int64_t, int64_t, int64_t, std::string_view)> const& func);
111
    static Status remove_partial_update_info(OlapMeta* meta, int64_t tablet_id,
112
                                             int64_t partition_id, int64_t txn_id);
113
    static Status remove_partial_update_infos(
114
            OlapMeta* meta, const std::vector<std::tuple<int64_t, int64_t, int64_t>>& keys);
115
    static Status remove_tablet_related_partial_update_info(OlapMeta* meta, int64_t tablet_id);
116
117
private:
118
    static Status _save(OlapMeta* meta, TabletUid tablet_uid, const RowsetId& rowset_id,
119
                        const RowsetMetaPB& rowset_meta_pb);
120
    static Status _save_with_ccr_binlog(OlapMeta* meta, TabletUid tablet_uid,
121
                                        const RowsetId& rowset_id,
122
                                        const RowsetMetaPB& rowset_meta_pb);
123
    static Status _save_with_row_binlog(OlapMeta* meta, TabletUid tablet_uid,
124
                                        const RowsetId& rowset_id,
125
                                        const RowsetMetaPB& rowset_meta_pb,
126
                                        const RowsetMetaPB& attach_row_binlog_rowset_meta);
127
    static Status _get_rowset_binlog_metas(OlapMeta* meta, const TabletUid tablet_uid,
128
                                           const std::vector<int64_t>& binlog_versions,
129
                                           RowsetBinlogMetasPB* metas_pb);
130
    static Status _get_all_rowset_binlog_metas(OlapMeta* meta, const TabletUid tablet_uid,
131
                                               RowsetBinlogMetasPB* metas_pb);
132
};
133
134
} // namespace doris
135
136
#endif // DORIS_BE_SRC_OLAP_ROWSET_ROWSET_META_MANAGER_H