Skip to content

Commit 0788cb8

Browse files
anand1976facebook-github-bot
authored andcommitted
Add Prepare interface to user defined index iterator (facebook#13728)
Summary: Pull Request resolved: facebook#13728 The Prepare interface allows the user defined index iterator to prefetch index entries, as well as take custom scan termination criteria specified in the property_bag into account. Reviewed By: pdillinger Differential Revision: D76165546 fbshipit-source-id: 83d628598924aa7a60dff7ed62a16ae575b2c8ec
1 parent 768ef1f commit 0788cb8

5 files changed

Lines changed: 409 additions & 167 deletions

File tree

include/rocksdb/iterator.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,18 @@ class Iterator : public IteratorBase {
9595
return Slice();
9696
}
9797

98-
// RocksDB Internal - DO NOT USE
99-
// Prepare the iterator to scan the ranges specified in scan_opts. The
100-
// upper bound and other table specific limits may be specified. This will
101-
// typically be followed by Seeks to the start keys in the order they're
102-
// specified in scan_opts. If the user does a Seek to some other target key,
103-
// the iterator should disregard the scan_opts from that point onwards and
104-
// behave like a normal iterator. Its the user's responsibility to again
105-
// call Prepare().
98+
// Prepare the iterator to scan the ranges specified in scan_opts. This
99+
// includes prefetching relevant blocks from disk. The upper bound and
100+
// other table specific limits should be specified for each
101+
// scan for best results. If an upper bound is not specified, Prepare may
102+
// skip prefetching as it cannot accurately determine how much to prefetch.
103+
//
104+
// Prepare should typically be followed by Seeks to the start keys in the
105+
// order they're specified in scan_opts. If the user does a Seek to some
106+
// other target key, the iterator should disregard the scan_opts from that
107+
// point onwards and behave like a normal iterator. Its the user's
108+
// responsibility to again call Prepare().
109+
//
106110
// If Prepare() is called, it overrides the iterate_upper_bound in
107111
// ReadOptions
108112
virtual void Prepare(const std::vector<ScanOptions>& /*scan_opts*/) {}

include/rocksdb/user_defined_index.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ class UserDefinedIndexIterator {
8989
public:
9090
virtual ~UserDefinedIndexIterator() = default;
9191

92+
// Prepare the iterator for a series of scans. The iterator should use
93+
// this as an opportunity to do any prefetching and buffering of results.
94+
virtual void Prepare(const ScanOptions scan_opts[], size_t num_opts) = 0;
95+
9296
// Given the target key, position the index iterator at the index entry
9397
// with the smallest key >= target. The result must be updated with the
9498
// index key, and the bound_check_result. The bound_check_result should

table/block_based/block_based_table_iterator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ class BlockBasedTableIterator : public InternalIteratorBase<Slice> {
222222
}
223223
}
224224

225+
void Prepare(const std::vector<ScanOptions>* scan_opts) override {
226+
index_iter_->Prepare(scan_opts);
227+
}
228+
225229
FilePrefetchBuffer* prefetch_buffer() {
226230
return block_prefetcher_.prefetch_buffer();
227231
}

table/block_based/user_defined_index_wrapper.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ class UserDefinedIndexIteratorWrapper
181181

182182
Status status() const override { return status_; }
183183

184+
void Prepare(const std::vector<ScanOptions>* scan_opts) override {
185+
udi_iter_->Prepare(scan_opts->data(), scan_opts->size());
186+
}
187+
184188
private:
185189
std::unique_ptr<UserDefinedIndexIterator> udi_iter_;
186190
IterateResult result_;

0 commit comments

Comments
 (0)