/Users/deen/code/yugabyte-db/src/yb/rocksdb/db/db_iter.h
Line | Count | Source |
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 | | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. |
21 | | // Use of this source code is governed by a BSD-style license that can be |
22 | | // found in the LICENSE file. See the AUTHORS file for names of contributors. |
23 | | |
24 | | #ifndef YB_ROCKSDB_DB_DB_ITER_H |
25 | | #define YB_ROCKSDB_DB_DB_ITER_H |
26 | | |
27 | | #pragma once |
28 | | |
29 | | #include <stdint.h> |
30 | | |
31 | | #include <string> |
32 | | |
33 | | #include "yb/rocksdb/immutable_options.h" |
34 | | #include "yb/rocksdb/iterator.h" |
35 | | #include "yb/rocksdb/util/arena.h" |
36 | | |
37 | | namespace rocksdb { |
38 | | |
39 | | class Arena; |
40 | | class DBIter; |
41 | | class InternalIterator; |
42 | | |
43 | | // Return a new iterator that converts internal keys (yielded by |
44 | | // "*internal_iter") that were live at the specified "sequence" number |
45 | | // into appropriate user keys. |
46 | | extern Iterator* NewDBIterator( |
47 | | Env* env, const ImmutableCFOptions& options, |
48 | | const Comparator* user_key_comparator, InternalIterator* internal_iter, |
49 | | const SequenceNumber& sequence, uint64_t max_sequential_skip_in_iterations, |
50 | | uint64_t version_number, const Slice* iterate_upper_bound = nullptr, |
51 | | bool prefix_same_as_start = false, bool pin_data = false); |
52 | | |
53 | | // A wrapper iterator which wraps DB Iterator and the arena, with which the DB |
54 | | // iterator is supposed be allocated. This class is used as an entry point of |
55 | | // an iterator hierarchy whose memory can be allocated inline. In that way, |
56 | | // accessing the iterator tree can be more cache friendly. It is also faster |
57 | | // to allocate. |
58 | | class ArenaWrappedDBIter : public Iterator { |
59 | | public: |
60 | | virtual ~ArenaWrappedDBIter(); |
61 | | |
62 | | // Get the arena to be used to allocate memory for DBIter to be wrapped, |
63 | | // as well as child iterators in it. |
64 | 30.7M | virtual Arena* GetArena() { return &arena_; } |
65 | | |
66 | | // Set the DB Iterator to be wrapped |
67 | | |
68 | | virtual void SetDBIter(DBIter* iter); |
69 | | |
70 | | // Set the internal iterator wrapped inside the DB Iterator. Usually it is |
71 | | // a merging iterator. |
72 | | virtual void SetIterUnderDBIter(InternalIterator* iter); |
73 | | virtual bool Valid() const override; |
74 | | virtual void SeekToFirst() override; |
75 | | virtual void SeekToLast() override; |
76 | | virtual void Seek(const Slice& target) override; |
77 | | virtual void Next() override; |
78 | | virtual void Prev() override; |
79 | | virtual Slice key() const override; |
80 | | virtual Slice value() const override; |
81 | | virtual Status status() const override; |
82 | | |
83 | | void RegisterCleanup(CleanupFunction function, void* arg1, void* arg2); |
84 | | virtual Status PinData(); |
85 | | virtual Status ReleasePinnedData(); |
86 | | virtual Status GetProperty(std::string prop_name, std::string* prop) override; |
87 | | |
88 | | void RevalidateAfterUpperBoundChange() override; |
89 | | |
90 | | private: |
91 | | DBIter* db_iter_; |
92 | | Arena arena_; |
93 | | }; |
94 | | |
95 | | // Generate the arena wrapped iterator class. |
96 | | extern ArenaWrappedDBIter* NewArenaWrappedDbIterator( |
97 | | Env* env, const ImmutableCFOptions& options, |
98 | | const Comparator* user_key_comparator, const SequenceNumber& sequence, |
99 | | uint64_t max_sequential_skip_in_iterations, uint64_t version_number, |
100 | | const Slice* iterate_upper_bound = nullptr, |
101 | | bool prefix_same_as_start = false, bool pin_data = false); |
102 | | |
103 | | } // namespace rocksdb |
104 | | |
105 | | #endif // YB_ROCKSDB_DB_DB_ITER_H |