YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/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
314k
  KeyBounds() = default;
35
220k
  KeyBounds(const Slice& _lower, const Slice& _upper) : lower(_lower), upper(_upper) {}
36
37
1.74G
  bool IsWithinBounds(const Slice& key) const {
38
1.74G
    return (lower.empty() || key.compare(lower) >= 0) &&
39
1.74G
           (upper.empty() || key.compare(upper) < 0);
40
1.74G
  }
41
42
722k
  bool IsInitialized() const {
43
722k
    return !lower.empty() || !upper.empty();
44
722k
  }
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
0
  static DocDB FromRegularUnbounded(rocksdb::DB* regular) {
57
0
    return {regular, nullptr /* intents */, &KeyBounds::kNoBounds};
58
0
  }
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