YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/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
38.0M
    : iterator_(rocksdb->NewIterator(read_opts)), key_bounds_(key_bounds) {
27
38.0M
  CHECK_NOTNULL(key_bounds_);
28
38.0M
  VLOG
(3) << "key_bounds_ = " << AsString(key_bounds_)47.0k
;
29
38.0M
}
30
31
5.48G
bool BoundedRocksDbIterator::Valid() const {
32
5.48G
  return iterator_->Valid() && 
key_bounds_->IsWithinBounds(key())4.95G
;
33
5.48G
}
34
35
104k
void BoundedRocksDbIterator::SeekToFirst() {
36
104k
  if (!key_bounds_->lower.empty()) {
37
307
    iterator_->Seek(key_bounds_->lower);
38
104k
  } else {
39
104k
    iterator_->SeekToFirst();
40
104k
  }
41
104k
}
42
43
720k
void BoundedRocksDbIterator::SeekToLast() {
44
720k
  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
720k
  } else {
56
720k
    iterator_->SeekToLast();
57
720k
  }
58
720k
}
59
60
195M
void BoundedRocksDbIterator::Seek(const Slice& target) {
61
195M
  if (!key_bounds_->lower.empty() && 
target.compare(key_bounds_->lower) < 0275k
) {
62
13.3k
    iterator_->Seek(key_bounds_->lower);
63
195M
  } else if (!key_bounds_->upper.empty() && 
target.compare(key_bounds_->upper) > 0229k
) {
64
0
    iterator_->Seek(key_bounds_->upper);
65
195M
  } else {
66
195M
    iterator_->Seek(target);
67
195M
  }
68
195M
}
69
70
973M
void BoundedRocksDbIterator::Next() {
71
973M
  iterator_->Next();
72
973M
}
73
74
5.44M
void BoundedRocksDbIterator::Prev() {
75
5.44M
  iterator_->Prev();
76
5.44M
}
77
78
12.8G
Slice BoundedRocksDbIterator::key() const {
79
12.8G
  return iterator_->key();
80
12.8G
}
81
82
1.99G
Slice BoundedRocksDbIterator::value() const {
83
1.99G
  return iterator_->value();
84
1.99G
}
85
86
0
Status BoundedRocksDbIterator::status() const {
87
0
  return iterator_->status();
88
0
}
89
90
}  // namespace docdb
91
}  // namespace yb