Coverage Report

Created: 2026-10-30 16:23

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 <cstdint>
23
#include <cstdlib>
24
#include <string>
25
#include <string_view>
26
27
#include "storage/olap_common.h" // TabletUid, RowsetId
28
29
namespace doris {
30
31
constexpr std::string_view kBinlogPrefix = "binlog_";
32
constexpr std::string_view kBinlogMetaPrefix = "binlog_meta_";
33
constexpr std::string_view kBinlogDataPrefix = "binlog_data_";
34
35
inline auto make_binlog_meta_key(const std::string_view tablet, int64_t version,
36
4
                                 const std::string_view rowset) {
37
4
    return fmt::format("{}meta_{}_{:020d}_{}", kBinlogPrefix, tablet, version, rowset);
38
4
}
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
4
                                 const RowsetId& rowset_id) {
49
4
    return make_binlog_meta_key(tablet_uid.to_string(), version, rowset_id.to_string());
50
4
}
51
52
16
inline auto make_binlog_meta_key_prefix(const TabletUid& tablet_uid) {
53
16
    return fmt::format("{}meta_{}_", kBinlogPrefix, tablet_uid.to_string());
54
16
}
55
56
28
inline auto make_binlog_meta_key_prefix(const TabletUid& tablet_uid, int64_t version) {
57
28
    return fmt::format("{}meta_{}_{:020d}_", kBinlogPrefix, tablet_uid.to_string(), version);
58
28
}
59
60
inline auto make_binlog_data_key(const std::string_view tablet, int64_t version,
61
4
                                 const std::string_view rowset) {
62
4
    return fmt::format("{}data_{}_{:020d}_{}", kBinlogPrefix, tablet, version, rowset);
63
4
}
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
4
                                 const RowsetId& rowset_id) {
72
4
    return make_binlog_data_key(tablet_uid.to_string(), version, rowset_id.to_string());
73
4
}
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
2
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
2
    return fmt::format("{}data_{}", kBinlogPrefix, meta_key.substr(kBinlogMetaPrefix.length()));
100
2
}
101
102
} // namespace doris