YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/docdb/key_bounds.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#ifndef YB_DOCDB_KEY_BOUNDS_H
15
#define YB_DOCDB_KEY_BOUNDS_H
16
17
#include "yb/docdb/key_bytes.h"
18
#include "yb/rocksdb/rocksdb_fwd.h"
19
20
namespace yb {
21
namespace docdb {
22
23
// Optional inclusive lower bound and exclusive upper bound for keys served by DocDB.
24
// Could be used to split tablet without doing actual splitting of RocksDB files.
25
// DocDBCompactionFilter also respects these bounds, so it will filter out non-relevant keys
26
// during compaction.
27
// Both bounds should be encoded DocKey or its part to avoid splitting DocDB row.
28
struct KeyBounds {
29
  KeyBytes lower;
30
  KeyBytes upper;
31
32
  static const KeyBounds kNoBounds;
33
34
427k
  KeyBounds() = default;
35
276k
  KeyBounds(const Slice& _lower, const Slice& _upper) : lower(_lower), upper(_upper) {}
36
37
5.03G
  bool IsWithinBounds(const Slice& key) const {
38
5.03G
    return (lower.empty() || 
key.compare(lower) >= 014.7M
) &&
39
5.04G
           (upper.empty() || 
key.compare(upper) < 011.5M
);
40
5.03G
  }
41
42
3.09M
  bool IsInitialized() const {
43
3.09M
    return !lower.empty() || 
!upper.empty()3.02M
;
44
3.09M
  }
45
46
  std::string ToString() const;
47
};
48
49
// Combined DB to store regular records and intents.
50
// TODO: move this to a more appropriate header file.
51
struct DocDB {
52
  rocksdb::DB* regular = nullptr;
53
  rocksdb::DB* intents = nullptr;
54
  const KeyBounds* key_bounds = nullptr;
55
56
362k
  static DocDB FromRegularUnbounded(rocksdb::DB* regular) {
57
362k
    return {regular, nullptr /* intents */, &KeyBounds::kNoBounds};
58
362k
  }
59
60
0
  DocDB WithoutIntents() {
61
0
    return {regular, nullptr /* intents */, key_bounds};
62
0
  }
63
};
64
65
// Checks whether key belongs to specified key_bounds, always true if key_bounds is nullptr.
66
bool IsWithinBounds(const KeyBounds* key_bounds, const Slice& key);
67
68
}  // namespace docdb
69
}  // namespace yb
70
71
#endif  // YB_DOCDB_KEY_BOUNDS_H