/Users/deen/code/yugabyte-db/src/yb/docdb/bounded_rocksdb_iterator.cc
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 | | #include "yb/docdb/bounded_rocksdb_iterator.h" |
15 | | |
16 | | #include "yb/docdb/key_bounds.h" |
17 | | |
18 | | #include "yb/rocksdb/db.h" |
19 | | |
20 | | namespace yb { |
21 | | namespace docdb { |
22 | | |
23 | | BoundedRocksDbIterator::BoundedRocksDbIterator( |
24 | | rocksdb::DB* rocksdb, const rocksdb::ReadOptions& read_opts, |
25 | | const KeyBounds* key_bounds) |
26 | 15.3M | : iterator_(rocksdb->NewIterator(read_opts)), key_bounds_(key_bounds) { |
27 | 15.3M | CHECK_NOTNULL(key_bounds_); |
28 | 25.0k | VLOG(3) << "key_bounds_ = " << AsString(key_bounds_); |
29 | 15.3M | } |
30 | | |
31 | 1.89G | bool BoundedRocksDbIterator::Valid() const { |
32 | 1.89G | return iterator_->Valid() && key_bounds_->IsWithinBounds(key()); |
33 | 1.89G | } |
34 | | |
35 | 66.9k | void BoundedRocksDbIterator::SeekToFirst() { |
36 | 66.9k | if (!key_bounds_->lower.empty()) { |
37 | 112 | iterator_->Seek(key_bounds_->lower); |
38 | 66.8k | } else { |
39 | 66.8k | iterator_->SeekToFirst(); |
40 | 66.8k | } |
41 | 66.9k | } |
42 | | |
43 | 744 | void BoundedRocksDbIterator::SeekToLast() { |
44 | 744 | if (!key_bounds_->upper.empty()) { |
45 | | // TODO(tsplit): this code path is only used for post-split tablets, particularly during |
46 | | // reverse scan for range-partitioned tables. |
47 | | // Need to add unit-test for this scenario when adding unit-tests for tablet splitting of |
48 | | // range-partitioned tables. |
49 | 76 | iterator_->Seek(key_bounds_->upper); |
50 | 76 | if (iterator_->Valid()) { |
51 | 0 | iterator_->Prev(); |
52 | 76 | } else { |
53 | 76 | iterator_->SeekToLast(); |
54 | 76 | } |
55 | 668 | } else { |
56 | 668 | iterator_->SeekToLast(); |
57 | 668 | } |
58 | 744 | } |
59 | | |
60 | 67.1M | void BoundedRocksDbIterator::Seek(const Slice& target) { |
61 | 67.1M | if (!key_bounds_->lower.empty() && target.compare(key_bounds_->lower) < 0) { |
62 | 4.66k | iterator_->Seek(key_bounds_->lower); |
63 | 67.1M | } else if (!key_bounds_->upper.empty() && target.compare(key_bounds_->upper) > 0) { |
64 | 0 | iterator_->Seek(key_bounds_->upper); |
65 | 67.1M | } else { |
66 | 67.1M | iterator_->Seek(target); |
67 | 67.1M | } |
68 | 67.1M | } |
69 | | |
70 | 332M | void BoundedRocksDbIterator::Next() { |
71 | 332M | iterator_->Next(); |
72 | 332M | } |
73 | | |
74 | 414k | void BoundedRocksDbIterator::Prev() { |
75 | 414k | iterator_->Prev(); |
76 | 414k | } |
77 | | |
78 | 4.48G | Slice BoundedRocksDbIterator::key() const { |
79 | 4.48G | return iterator_->key(); |
80 | 4.48G | } |
81 | | |
82 | 690M | Slice BoundedRocksDbIterator::value() const { |
83 | 690M | return iterator_->value(); |
84 | 690M | } |
85 | | |
86 | 0 | Status BoundedRocksDbIterator::status() const { |
87 | 0 | return iterator_->status(); |
88 | 0 | } |
89 | | |
90 | | } // namespace docdb |
91 | | } // namespace yb |