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.
13 #include "db/db_impl.h"
14 #include "db/dbformat.h"
15 #include "db/range_del_aggregator.h"
16 #include "options/cf_options.h"
17 #include "rocksdb/db.h"
18 #include "rocksdb/iterator.h"
19 #include "util/arena.h"
20 #include "util/autovector.h"
27 // Return a new iterator that converts internal keys (yielded by
28 // "*internal_iter") that were live at the specified "sequence" number
29 // into appropriate user keys.
30 extern Iterator
* NewDBIterator(
31 Env
* env
, const ReadOptions
& read_options
,
32 const ImmutableCFOptions
& cf_options
,
33 const MutableCFOptions
& mutable_cf_options
,
34 const Comparator
* user_key_comparator
, InternalIterator
* internal_iter
,
35 const SequenceNumber
& sequence
, uint64_t max_sequential_skip_in_iterations
,
36 ReadCallback
* read_callback
, DBImpl
* db_impl
= nullptr,
37 ColumnFamilyData
* cfd
= nullptr, bool allow_blob
= false);
39 // A wrapper iterator which wraps DB Iterator and the arena, with which the DB
40 // iterator is supposed be allocated. This class is used as an entry point of
41 // a iterator hierarchy whose memory can be allocated inline. In that way,
42 // accessing the iterator tree can be more cache friendly. It is also faster
44 class ArenaWrappedDBIter
: public Iterator
{
46 virtual ~ArenaWrappedDBIter();
48 // Get the arena to be used to allocate memory for DBIter to be wrapped,
49 // as well as child iterators in it.
50 virtual Arena
* GetArena() { return &arena_
; }
51 virtual ReadRangeDelAggregator
* GetRangeDelAggregator();
53 // Set the internal iterator wrapped inside the DB Iterator. Usually it is
54 // a merging iterator.
55 virtual void SetIterUnderDBIter(InternalIterator
* iter
);
56 virtual bool Valid() const override
;
57 virtual void SeekToFirst() override
;
58 virtual void SeekToLast() override
;
59 virtual void Seek(const Slice
& target
) override
;
60 virtual void SeekForPrev(const Slice
& target
) override
;
61 virtual void Next() override
;
62 virtual void Prev() override
;
63 virtual Slice
key() const override
;
64 virtual Slice
value() const override
;
65 virtual Status
status() const override
;
66 virtual Status
Refresh() override
;
69 virtual Status
GetProperty(std::string prop_name
, std::string
* prop
) override
;
71 void Init(Env
* env
, const ReadOptions
& read_options
,
72 const ImmutableCFOptions
& cf_options
,
73 const MutableCFOptions
& mutable_cf_options
,
74 const SequenceNumber
& sequence
,
75 uint64_t max_sequential_skip_in_iterations
, uint64_t version_number
,
76 ReadCallback
* read_callback
, DBImpl
* db_impl
, ColumnFamilyData
* cfd
,
77 bool allow_blob
, bool allow_refresh
);
79 void StoreRefreshInfo(const ReadOptions
& read_options
, DBImpl
* db_impl
,
80 ColumnFamilyData
* cfd
, ReadCallback
* read_callback
,
82 read_options_
= read_options
;
85 read_callback_
= read_callback
;
86 allow_blob_
= allow_blob
;
93 ColumnFamilyData
* cfd_
= nullptr;
94 DBImpl
* db_impl_
= nullptr;
95 ReadOptions read_options_
;
96 ReadCallback
* read_callback_
;
97 bool allow_blob_
= false;
98 bool allow_refresh_
= true;
101 // Generate the arena wrapped iterator class.
102 // `db_impl` and `cfd` are used for reneweal. If left null, renewal will not
104 extern ArenaWrappedDBIter
* NewArenaWrappedDbIterator(
105 Env
* env
, const ReadOptions
& read_options
,
106 const ImmutableCFOptions
& cf_options
,
107 const MutableCFOptions
& mutable_cf_options
, const SequenceNumber
& sequence
,
108 uint64_t max_sequential_skip_in_iterations
, uint64_t version_number
,
109 ReadCallback
* read_callback
, DBImpl
* db_impl
= nullptr,
110 ColumnFamilyData
* cfd
= nullptr, bool allow_blob
= false,
111 bool allow_refresh
= true);
112 } // namespace rocksdb