]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/table/iterator_wrapper.h
ff46f2536cbe48e41f49a5edc7ad5205d8c30088
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
6 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file. See the AUTHORS file for names of contributors.
14 #include "table/internal_iterator.h"
15 #include "test_util/sync_point.h"
17 namespace ROCKSDB_NAMESPACE
{
19 // A internal wrapper class with an interface similar to Iterator that caches
20 // the valid() and key() results for an underlying iterator.
21 // This can help avoid virtual function calls and also gives better
23 template <class TValue
= Slice
>
24 class IteratorWrapperBase
{
26 IteratorWrapperBase() : iter_(nullptr), valid_(false) {}
27 explicit IteratorWrapperBase(InternalIteratorBase
<TValue
>* _iter
)
31 ~IteratorWrapperBase() {}
32 InternalIteratorBase
<TValue
>* iter() const { return iter_
; }
34 // Set the underlying Iterator to _iter and return
35 // previous underlying Iterator.
36 InternalIteratorBase
<TValue
>* Set(InternalIteratorBase
<TValue
>* _iter
) {
37 InternalIteratorBase
<TValue
>* old_iter
= iter_
;
40 if (iter_
== nullptr) {
48 void DeleteIter(bool is_arena_mode
) {
53 iter_
->~InternalIteratorBase
<TValue
>();
58 // Iterator interface methods
59 bool Valid() const { return valid_
; }
64 TValue
value() const {
66 return iter_
->value();
68 // Methods below require iter() != nullptr
69 Status
status() const {
71 return iter_
->status();
75 if (result_
.value_prepared
) {
78 if (iter_
->PrepareValue()) {
79 result_
.value_prepared
= true;
83 assert(!iter_
->Valid());
89 valid_
= iter_
->NextAndGetResult(&result_
);
90 assert(!valid_
|| iter_
->status().ok());
92 bool NextAndGetResult(IterateResult
* result
) {
94 valid_
= iter_
->NextAndGetResult(&result_
);
96 assert(!valid_
|| iter_
->status().ok());
104 void Seek(const Slice
& k
) {
109 void SeekForPrev(const Slice
& k
) {
111 iter_
->SeekForPrev(k
);
116 iter_
->SeekToFirst();
125 bool MayBeOutOfLowerBound() {
127 return iter_
->MayBeOutOfLowerBound();
130 IterBoundCheck
UpperBoundCheckResult() {
132 return result_
.bound_check_result
;
135 void SetPinnedItersMgr(PinnedIteratorsManager
* pinned_iters_mgr
) {
137 iter_
->SetPinnedItersMgr(pinned_iters_mgr
);
139 bool IsKeyPinned() const {
141 return iter_
->IsKeyPinned();
143 bool IsValuePinned() const {
145 return iter_
->IsValuePinned();
148 bool IsValuePrepared() const {
149 return result_
.value_prepared
;
152 Slice
user_key() const {
154 return iter_
->user_key();
159 valid_
= iter_
->Valid();
161 assert(iter_
->status().ok());
162 result_
.key
= iter_
->key();
163 result_
.bound_check_result
= IterBoundCheck::kUnknown
;
164 result_
.value_prepared
= false;
168 InternalIteratorBase
<TValue
>* iter_
;
169 IterateResult result_
;
173 using IteratorWrapper
= IteratorWrapperBase
<Slice
>;
176 // Return an empty iterator (yields nothing) allocated from arena.
177 template <class TValue
= Slice
>
178 extern InternalIteratorBase
<TValue
>* NewEmptyInternalIterator(Arena
* arena
);
180 } // namespace ROCKSDB_NAMESPACE