/Users/deen/code/yugabyte-db/src/yb/rocksdb/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 | | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. |
6 | | // Use of this source code is governed by a BSD-style license that can be |
7 | | // found in the LICENSE file. See the AUTHORS file for names of contributors. |
8 | | // |
9 | | // The following only applies to changes made to this file as part of YugaByte development. |
10 | | // |
11 | | // Portions Copyright (c) YugaByte, Inc. |
12 | | // |
13 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
14 | | // in compliance with the License. You may obtain a copy of the License at |
15 | | // |
16 | | // http://www.apache.org/licenses/LICENSE-2.0 |
17 | | // |
18 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
19 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
20 | | // or implied. See the License for the specific language governing permissions and limitations |
21 | | // under the License. |
22 | | // |
23 | | // An iterator yields a sequence of key/value pairs from a source. |
24 | | // The following class defines the interface. Multiple implementations |
25 | | // are provided by this library. In particular, iterators are provided |
26 | | // to access the contents of a Table or a DB. |
27 | | // |
28 | | // Multiple threads can invoke const methods on an Iterator without |
29 | | // external synchronization, but if any of the threads may call a |
30 | | // non-const method, all threads accessing the same Iterator must use |
31 | | // external synchronization. |
32 | | |
33 | | #ifndef YB_ROCKSDB_ITERATOR_H |
34 | | #define YB_ROCKSDB_ITERATOR_H |
35 | | |
36 | | #include <string> |
37 | | #include "yb/util/slice.h" |
38 | | #include "yb/rocksdb/status.h" |
39 | | |
40 | | namespace rocksdb { |
41 | | |
42 | | class Cleanable { |
43 | | public: |
44 | | Cleanable(); |
45 | | ~Cleanable(); |
46 | | // Clients are allowed to register function/arg1/arg2 triples that |
47 | | // will be invoked when this iterator is destroyed. |
48 | | // |
49 | | // Note that unlike all of the preceding methods, this method is |
50 | | // not abstract and therefore clients should not override it. |
51 | | typedef void (*CleanupFunction)(void* arg1, void* arg2); |
52 | | void RegisterCleanup(CleanupFunction function, void* arg1, void* arg2); |
53 | | |
54 | | protected: |
55 | | struct Cleanup { |
56 | | CleanupFunction function; |
57 | | void* arg1; |
58 | | void* arg2; |
59 | | Cleanup* next; |
60 | | }; |
61 | | Cleanup cleanup_; |
62 | | }; |
63 | | |
64 | | class Iterator : public Cleanable { |
65 | | public: |
66 | 160M | Iterator() {} |
67 | 161M | virtual ~Iterator() {} |
68 | | |
69 | | Iterator(const Iterator&) = delete; |
70 | | void operator=(const Iterator&) = delete; |
71 | | |
72 | | Iterator(Iterator&&) = default; |
73 | 36.8M | Iterator& operator=(Iterator&&) = default; |
74 | | |
75 | | // An iterator is either positioned at a key/value pair, or |
76 | | // not valid. This method returns true iff the iterator is valid. |
77 | | virtual bool Valid() const = 0; |
78 | | |
79 | | // Position at the first key in the source. The iterator is Valid() |
80 | | // after this call iff the source is not empty. |
81 | | virtual void SeekToFirst() = 0; |
82 | | |
83 | | // Position at the last key in the source. The iterator is |
84 | | // Valid() after this call iff the source is not empty. |
85 | | virtual void SeekToLast() = 0; |
86 | | |
87 | | // Position at the first key in the source that at or past target |
88 | | // The iterator is Valid() after this call iff the source contains |
89 | | // an entry that comes at or past target. |
90 | | virtual void Seek(const Slice& target) = 0; |
91 | | |
92 | | // Moves to the next entry in the source. After this call, Valid() is |
93 | | // true iff the iterator was not positioned at the last entry in the source. |
94 | | // REQUIRES: Valid() |
95 | | virtual void Next() = 0; |
96 | | |
97 | | // Moves to the previous entry in the source. After this call, Valid() is |
98 | | // true iff the iterator was not positioned at the first entry in source. |
99 | | // REQUIRES: Valid() |
100 | | virtual void Prev() = 0; |
101 | | |
102 | | // Return the key for the current entry. The underlying storage for |
103 | | // the returned slice is valid only until the next modification of |
104 | | // the iterator. |
105 | | // REQUIRES: Valid() |
106 | | virtual Slice key() const = 0; |
107 | | |
108 | | // Return the value for the current entry. The underlying storage for |
109 | | // the returned slice is valid only until the next modification of |
110 | | // the iterator. |
111 | | // REQUIRES: !AtEnd() && !AtStart() |
112 | | virtual Slice value() const = 0; |
113 | | |
114 | | // If an error has occurred, return it. Else return an ok status. |
115 | | // If non-blocking IO is requested and this operation cannot be |
116 | | // satisfied without doing some IO, then this returns STATUS(Incomplete, ). |
117 | | virtual Status status() const = 0; |
118 | | |
119 | | // Property "rocksdb.iterator.is-key-pinned": |
120 | | // If returning "1", this means that the Slice returned by key() is valid |
121 | | // as long as the iterator is not deleted and ReleasePinnedData() is not |
122 | | // called. |
123 | | // It is guaranteed to always return "1" if |
124 | | // - Iterator created with ReadOptions::pin_data = true |
125 | | // - DB tables were created with |
126 | | // BlockBasedTableOptions::use_delta_encoding |
127 | | // set to false. |
128 | | // Property "rocksdb.iterator.super-version-number": |
129 | | // LSM version used by the iterator. The same format as DB Property |
130 | | // kCurrentSuperVersionNumber. See its comment for more information. |
131 | | virtual Status GetProperty(std::string prop_name, std::string* prop); |
132 | | |
133 | | // Upper bound was updated and iterator should revalidate its state, since it could change. |
134 | | // This only affects forward iteration. A previously invalid forward iterator can become valid |
135 | | // if the upper bound has increased. |
136 | 0 | virtual void RevalidateAfterUpperBoundChange() {} |
137 | | }; |
138 | | |
139 | | // Return an empty iterator (yields nothing). |
140 | | extern Iterator* NewEmptyIterator(); |
141 | | |
142 | | // Return an empty iterator with the specified status. |
143 | | extern Iterator* NewErrorIterator(const Status& status); |
144 | | |
145 | | } // namespace rocksdb |
146 | | |
147 | | #endif // YB_ROCKSDB_ITERATOR_H |