Coverage Report

Created: 2024-11-21 23:27

/root/doris/be/src/olap/binlog.h
Line
Count
Source (jump to first uncovered line)
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 "olap/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
32
inline auto make_binlog_meta_key(const std::string_view tablet, int64_t version,
33
0
                                 const std::string_view rowset) {
34
0
    return fmt::format("{}meta_{}_{:020d}_{}", kBinlogPrefix, tablet, version, rowset);
35
0
}
36
37
inline auto make_binlog_meta_key(const std::string_view tablet, const std::string_view version_str,
38
0
                                 const std::string_view rowset) {
39
0
    // TODO(Drogon): use fmt::format not convert to version_num, only string with length prefix '0'
40
0
    int64_t version = std::atoll(version_str.data());
41
0
    return make_binlog_meta_key(tablet, version, rowset);
42
0
}
43
44
inline auto make_binlog_meta_key(const TabletUid& tablet_uid, int64_t version,
45
0
                                 const RowsetId& rowset_id) {
46
0
    return make_binlog_meta_key(tablet_uid.to_string(), version, rowset_id.to_string());
47
0
}
48
49
4
inline auto make_binlog_meta_key_prefix(const TabletUid& tablet_uid) {
50
4
    return fmt::format("{}meta_{}_", kBinlogPrefix, tablet_uid.to_string());
51
4
}
52
53
8
inline auto make_binlog_meta_key_prefix(const TabletUid& tablet_uid, int64_t version) {
54
8
    return fmt::format("{}meta_{}_{:020d}_", kBinlogPrefix, tablet_uid.to_string(), version);
55
8
}
56
57
inline auto make_binlog_data_key(const std::string_view tablet, int64_t version,
58
0
                                 const std::string_view rowset) {
59
0
    return fmt::format("{}data_{}_{:020d}_{}", kBinlogPrefix, tablet, version, rowset);
60
0
}
61
62
inline auto make_binlog_data_key(const std::string_view tablet, const std::string_view version,
63
0
                                 const std::string_view rowset) {
64
0
    return fmt::format("{}data_{}_{:0>20}_{}", kBinlogPrefix, tablet, version, rowset);
65
0
}
66
67
inline auto make_binlog_data_key(const TabletUid& tablet_uid, int64_t version,
68
0
                                 const RowsetId& rowset_id) {
69
0
    return make_binlog_data_key(tablet_uid.to_string(), version, rowset_id.to_string());
70
0
}
71
72
inline auto make_binlog_data_key(const TabletUid& tablet_uid, int64_t version,
73
0
                                 const std::string_view rowset_id) {
74
0
    return make_binlog_data_key(tablet_uid.to_string(), version, rowset_id);
75
0
}
76
77
0
inline auto make_binlog_data_key_prefix(const TabletUid& tablet_uid, int64_t version) {
78
0
    return fmt::format("{}data_{}_{:020d}_", kBinlogPrefix, tablet_uid.to_string(), version);
79
0
}
80
81
0
inline auto make_binlog_filename_key(const TabletUid& tablet_uid, const std::string_view version) {
82
0
    return fmt::format("{}meta_{}_{:0>20}_", kBinlogPrefix, tablet_uid.to_string(), version);
83
0
}
84
85
0
inline bool starts_with_binlog_meta(const std::string_view str) {
86
0
    auto prefix = kBinlogMetaPrefix;
87
0
    if (prefix.length() > str.length()) {
88
0
        return false;
89
0
    }
90
91
0
    return str.compare(0, prefix.length(), prefix) == 0;
92
0
}
93
94
0
inline std::string get_binlog_data_key_from_meta_key(const std::string_view meta_key) {
95
    // like "binlog_meta_6943f1585fe834b5-e542c2b83a21d0b7" => "binlog_data-6943f1585fe834b5-e542c2b83a21d0b7"
96
0
    return fmt::format("{}data_{}", kBinlogPrefix, meta_key.substr(kBinlogMetaPrefix.length()));
97
0
}
98
} // namespace doris