/Users/deen/code/yugabyte-db/src/yb/rocksdb/db/forward_iterator.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
2 | | // This source code is licensed under the BSD-style license found in the |
3 | | // LICENSE file in the root directory of this source tree. An additional grant |
4 | | // of patent rights can be found in the PATENTS file in the same directory. |
5 | | // |
6 | | // The following only applies to changes made to this file as part of YugaByte development. |
7 | | // |
8 | | // Portions Copyright (c) YugaByte, Inc. |
9 | | // |
10 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
11 | | // in compliance with the License. You may obtain a copy of the License at |
12 | | // |
13 | | // http://www.apache.org/licenses/LICENSE-2.0 |
14 | | // |
15 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
16 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
17 | | // or implied. See the License for the specific language governing permissions and limitations |
18 | | // under the License. |
19 | | // |
20 | | #ifndef ROCKSDB_DB_FORWARD_ITERATOR_H |
21 | | #define ROCKSDB_DB_FORWARD_ITERATOR_H |
22 | | |
23 | | #pragma once |
24 | | |
25 | | #ifndef ROCKSDB_LITE |
26 | | |
27 | | #include <string> |
28 | | #include <vector> |
29 | | #include <queue> |
30 | | |
31 | | #include "yb/rocksdb/db.h" |
32 | | #include "yb/rocksdb/iterator.h" |
33 | | #include "yb/rocksdb/options.h" |
34 | | #include "yb/rocksdb/db/dbformat.h" |
35 | | #include "yb/rocksdb/table/internal_iterator.h" |
36 | | #include "yb/rocksdb/util/arena.h" |
37 | | |
38 | | namespace rocksdb { |
39 | | |
40 | | class DBImpl; |
41 | | class Env; |
42 | | struct SuperVersion; |
43 | | class ColumnFamilyData; |
44 | | class LevelIterator; |
45 | | class VersionStorageInfo; |
46 | | struct FileMetaData; |
47 | | |
48 | | class MinIterComparator { |
49 | | public: |
50 | | explicit MinIterComparator(const Comparator* comparator) : |
51 | 6.17k | comparator_(comparator) {} |
52 | | |
53 | 21.0k | bool operator()(InternalIterator* a, InternalIterator* b) { |
54 | 21.0k | return comparator_->Compare(a->key(), b->key()) > 0; |
55 | 21.0k | } |
56 | | private: |
57 | | const Comparator* comparator_; |
58 | | }; |
59 | | |
60 | | typedef std::priority_queue<InternalIterator*, std::vector<InternalIterator*>, |
61 | | MinIterComparator> MinIterHeap; |
62 | | |
63 | | /** |
64 | | * ForwardIterator is a special type of iterator that only supports Seek() |
65 | | * and Next(). It is expected to perform better than TailingIterator by |
66 | | * removing the encapsulation and making all information accessible within |
67 | | * the iterator. At the current implementation, snapshot is taken at the |
68 | | * time Seek() is called. The Next() followed do not see new values after. |
69 | | */ |
70 | | class ForwardIterator : public InternalIterator { |
71 | | public: |
72 | | ForwardIterator(DBImpl* db, const ReadOptions& read_options, |
73 | | ColumnFamilyData* cfd, SuperVersion* current_sv = nullptr); |
74 | | virtual ~ForwardIterator(); |
75 | | |
76 | 0 | void SeekToLast() override { |
77 | 0 | status_ = STATUS(NotSupported, "ForwardIterator::SeekToLast()"); |
78 | 0 | valid_ = false; |
79 | 0 | } Unexecuted instantiation: _ZN7rocksdb15ForwardIterator10SeekToLastEv Unexecuted instantiation: _ZN7rocksdb15ForwardIterator10SeekToLastEv |
80 | 0 | void Prev() override { |
81 | 0 | status_ = STATUS(NotSupported, "ForwardIterator::Prev"); |
82 | 0 | valid_ = false; |
83 | 0 | } Unexecuted instantiation: _ZN7rocksdb15ForwardIterator4PrevEv Unexecuted instantiation: _ZN7rocksdb15ForwardIterator4PrevEv |
84 | | |
85 | | virtual bool Valid() const override; |
86 | | void SeekToFirst() override; |
87 | | virtual void Seek(const Slice& target) override; |
88 | | virtual void Next() override; |
89 | | virtual Slice key() const override; |
90 | | virtual Slice value() const override; |
91 | | virtual Status status() const override; |
92 | | virtual Status GetProperty(std::string prop_name, std::string* prop) override; |
93 | | |
94 | | bool TEST_CheckDeletedIters(int* deleted_iters, int* num_iters); |
95 | | |
96 | | private: |
97 | | void Cleanup(bool release_sv); |
98 | | void SVCleanup(); |
99 | | void RebuildIterators(bool refresh_sv); |
100 | | void RenewIterators(); |
101 | | void BuildLevelIterators(const VersionStorageInfo* vstorage); |
102 | | void ResetIncompleteIterators(); |
103 | | void SeekInternal(const Slice& internal_key, bool seek_to_first); |
104 | | void UpdateCurrent(); |
105 | | bool NeedToSeekImmutable(const Slice& internal_key); |
106 | | void DeleteCurrentIter(); |
107 | | uint32_t FindFileInRange( |
108 | | const std::vector<FileMetaData*>& files, const Slice& internal_key, |
109 | | uint32_t left, uint32_t right); |
110 | | |
111 | | bool IsOverUpperBound(const Slice& internal_key) const; |
112 | | |
113 | | DBImpl* const db_; |
114 | | const ReadOptions read_options_; |
115 | | ColumnFamilyData* const cfd_; |
116 | | const SliceTransform* const prefix_extractor_; |
117 | | const Comparator* user_comparator_; |
118 | | MinIterHeap immutable_min_heap_; |
119 | | |
120 | | SuperVersion* sv_; |
121 | | InternalIterator* mutable_iter_; |
122 | | std::vector<InternalIterator*> imm_iters_; |
123 | | std::vector<InternalIterator*> l0_iters_; |
124 | | std::vector<LevelIterator*> level_iters_; |
125 | | InternalIterator* current_; |
126 | | bool valid_; |
127 | | |
128 | | // Internal iterator status; set only by one of the unsupported methods. |
129 | | Status status_; |
130 | | // Status of immutable iterators, maintained here to avoid iterating over |
131 | | // all of them in status(). |
132 | | Status immutable_status_; |
133 | | // Indicates that at least one of the immutable iterators pointed to a key |
134 | | // larger than iterate_upper_bound and was therefore destroyed. Seek() may |
135 | | // need to rebuild such iterators. |
136 | | bool has_iter_trimmed_for_upper_bound_; |
137 | | // Is current key larger than iterate_upper_bound? If so, makes Valid() |
138 | | // return false. |
139 | | bool current_over_upper_bound_; |
140 | | |
141 | | // Left endpoint of the range of keys that immutable iterators currently |
142 | | // cover. When Seek() is called with a key that's within that range, immutable |
143 | | // iterators don't need to be moved; see NeedToSeekImmutable(). This key is |
144 | | // included in the range after a Seek(), but excluded when advancing the |
145 | | // iterator using Next(). |
146 | | IterKey prev_key_; |
147 | | bool is_prev_set_; |
148 | | bool is_prev_inclusive_; |
149 | | |
150 | | Arena arena_; |
151 | | }; |
152 | | |
153 | | } // namespace rocksdb |
154 | | #endif // ROCKSDB_LITE |
155 | | |
156 | | #endif // ROCKSDB_DB_FORWARD_ITERATOR_H |