be/src/storage/rowset_id.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 <cstdint> |
21 | | #include <functional> |
22 | | #include <iosfwd> |
23 | | #include <string> |
24 | | #include <string_view> |
25 | | |
26 | | // Deliberately kept dependency-free (no config/exception/logging/hex utils): |
27 | | // this header is included by core/column/column.h and therefore by nearly |
28 | | // every TU. The method bodies that need those facilities live in |
29 | | // storage/rowset_id.cpp. |
30 | | |
31 | | namespace doris { |
32 | | |
33 | | // 8 bit rowset id version |
34 | | // 56 bit, inc number from 1 |
35 | | // 128 bit backend uid, it is a uuid bit, id version |
36 | | struct RowsetId { |
37 | | int8_t version = 0; |
38 | | int64_t hi = 0; |
39 | | int64_t mi = 0; |
40 | | int64_t lo = 0; |
41 | | |
42 | | void init(std::string_view rowset_id_str); |
43 | | |
44 | | // to compatible with old version |
45 | | void init(int64_t rowset_id); |
46 | | |
47 | | void init(int64_t id_version, int64_t high, int64_t middle, int64_t low); |
48 | | |
49 | | std::string to_string() const; |
50 | | |
51 | | // std::unordered_map need this api |
52 | 172k | bool operator==(const RowsetId& rhs) const { |
53 | 172k | return hi == rhs.hi && mi == rhs.mi && lo == rhs.lo; |
54 | 172k | } |
55 | | |
56 | 280 | bool operator!=(const RowsetId& rhs) const { |
57 | 280 | return hi != rhs.hi || mi != rhs.mi || lo != rhs.lo; |
58 | 280 | } |
59 | | |
60 | 45.1M | bool operator<(const RowsetId& rhs) const { |
61 | 45.1M | if (hi != rhs.hi) { |
62 | 4.59M | return hi < rhs.hi; |
63 | 40.5M | } else if (mi != rhs.mi) { |
64 | 0 | return mi < rhs.mi; |
65 | 40.5M | } else { |
66 | 40.5M | return lo < rhs.lo; |
67 | 40.5M | } |
68 | 45.1M | } |
69 | | }; |
70 | | |
71 | | std::ostream& operator<<(std::ostream& out, const RowsetId& rowset_id); |
72 | | |
73 | | } // namespace doris |
74 | | |
75 | | // This intended to be a "good" hash function. It may change from time to time. |
76 | | template <> |
77 | | struct std::hash<doris::RowsetId> { |
78 | | size_t operator()(const doris::RowsetId& rowset_id) const; |
79 | | }; |