Coverage Report

Created: 2026-05-09 09:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/binlog.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 <fmt/format.h>
21
22
#include <string>
23
#include <string_view>
24
25
#include "storage/olap_common.h"
26
27
namespace doris {
28
constexpr std::string_view kBinlogPrefix = "binlog_";
29
constexpr std::string_view kBinlogMetaPrefix = "binlog_meta_";
30
constexpr std::string_view kBinlogDataPrefix = "binlog_data_";
31
constexpr std::string_view kRowBinlogPrefix = "binlog_row_";
32
// used in file directory
33
constexpr std::string_view FDRowBinlogSuffix = "_row_binlog";
34
35
inline auto make_binlog_meta_key(const std::string_view tablet, int64_t version,
36
2
                                 const std::string_view rowset) {
37
2
    return fmt::format("{}meta_{}_{:020d}_{}", kBinlogPrefix, tablet, version, rowset);
38
2
}
39
40
inline auto make_binlog_meta_key(const std::string_view tablet, const std::string_view version_str,
41
0
                                 const std::string_view rowset) {
42
0
    // TODO(Drogon): use fmt::format not convert to version_num, only string with length prefix '0'
43
0
    int64_t version = std::atoll(version_str.data());
44
0
    return make_binlog_meta_key(tablet, version, rowset);
45
0
}
46
47
inline auto make_binlog_meta_key(const TabletUid& tablet_uid, int64_t version,
48
2
                                 const RowsetId& rowset_id) {
49
2
    return make_binlog_meta_key(tablet_uid.to_string(), version, rowset_id.to_string());
50
2
}
51
52
6
inline auto make_binlog_meta_key_prefix(const TabletUid& tablet_uid) {
53
6
    return fmt::format("{}meta_{}_", kBinlogPrefix, tablet_uid.to_string());
54
6
}
55
56
10
inline auto make_binlog_meta_key_prefix(const TabletUid& tablet_uid, int64_t version) {
57
10
    return fmt::format("{}meta_{}_{:020d}_", kBinlogPrefix, tablet_uid.to_string(), version);
58
10
}
59
60
inline auto make_binlog_data_key(const std::string_view tablet, int64_t version,
61
2
                                 const std::string_view rowset) {
62
2
    return fmt::format("{}data_{}_{:020d}_{}", kBinlogPrefix, tablet, version, rowset);
63
2
}
64
65
inline auto make_binlog_data_key(const std::string_view tablet, const std::string_view version,
66
0
                                 const std::string_view rowset) {
67
0
    return fmt::format("{}data_{}_{:0>20}_{}", kBinlogPrefix, tablet, version, rowset);
68
0
}
69
70
inline auto make_binlog_data_key(const TabletUid& tablet_uid, int64_t version,
71
2
                                 const RowsetId& rowset_id) {
72
2
    return make_binlog_data_key(tablet_uid.to_string(), version, rowset_id.to_string());
73
2
}
74
75
inline auto make_binlog_data_key(const TabletUid& tablet_uid, int64_t version,
76
0
                                 const std::string_view rowset_id) {
77
0
    return make_binlog_data_key(tablet_uid.to_string(), version, rowset_id);
78
0
}
79
80
0
inline auto make_binlog_data_key_prefix(const TabletUid& tablet_uid, int64_t version) {
81
0
    return fmt::format("{}data_{}_{:020d}_", kBinlogPrefix, tablet_uid.to_string(), version);
82
0
}
83
84
0
inline auto make_binlog_filename_key(const TabletUid& tablet_uid, const std::string_view version) {
85
0
    return fmt::format("{}meta_{}_{:0>20}_", kBinlogPrefix, tablet_uid.to_string(), version);
86
0
}
87
88
0
inline bool starts_with_binlog_meta(const std::string_view str) {
89
0
    auto prefix = kBinlogMetaPrefix;
90
0
    if (prefix.length() > str.length()) {
91
0
        return false;
92
0
    }
93
94
0
    return str.compare(0, prefix.length(), prefix) == 0;
95
0
}
96
97
1
inline std::string get_binlog_data_key_from_meta_key(const std::string_view meta_key) {
98
    // like "binlog_meta_6943f1585fe834b5-e542c2b83a21d0b7" => "binlog_data-6943f1585fe834b5-e542c2b83a21d0b7"
99
1
    return fmt::format("{}data_{}", kBinlogPrefix, meta_key.substr(kBinlogMetaPrefix.length()));
100
1
}
101
} // namespace doris