2019-09-13 22:48:04 +02:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
//
|
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string>
|
|
|
|
#include "db/db_impl/db_impl.h"
|
|
|
|
#include "db/db_iter.h"
|
|
|
|
#include "db/dbformat.h"
|
|
|
|
#include "db/range_del_aggregator.h"
|
|
|
|
#include "memory/arena.h"
|
|
|
|
#include "options/cf_options.h"
|
|
|
|
#include "rocksdb/db.h"
|
|
|
|
#include "rocksdb/iterator.h"
|
|
|
|
#include "util/autovector.h"
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2019-09-13 22:48:04 +02:00
|
|
|
|
|
|
|
class Arena;
|
2020-12-05 06:28:26 +01:00
|
|
|
class Version;
|
2019-09-13 22:48:04 +02:00
|
|
|
|
|
|
|
// A wrapper iterator which wraps DB Iterator and the arena, with which the DB
|
|
|
|
// iterator is supposed to be allocated. This class is used as an entry point of
|
|
|
|
// a iterator hierarchy whose memory can be allocated inline. In that way,
|
|
|
|
// accessing the iterator tree can be more cache friendly. It is also faster
|
|
|
|
// to allocate.
|
|
|
|
// When using the class's Iterator interface, the behavior is exactly
|
|
|
|
// the same as the inner DBIter.
|
|
|
|
class ArenaWrappedDBIter : public Iterator {
|
|
|
|
public:
|
|
|
|
virtual ~ArenaWrappedDBIter() { db_iter_->~DBIter(); }
|
|
|
|
|
|
|
|
// Get the arena to be used to allocate memory for DBIter to be wrapped,
|
|
|
|
// as well as child iterators in it.
|
|
|
|
virtual Arena* GetArena() { return &arena_; }
|
|
|
|
virtual ReadRangeDelAggregator* GetRangeDelAggregator() {
|
|
|
|
return db_iter_->GetRangeDelAggregator();
|
|
|
|
}
|
2020-08-04 00:21:56 +02:00
|
|
|
const ReadOptions& GetReadOptions() { return read_options_; }
|
2019-09-13 22:48:04 +02:00
|
|
|
|
|
|
|
// Set the internal iterator wrapped inside the DB Iterator. Usually it is
|
|
|
|
// a merging iterator.
|
|
|
|
virtual void SetIterUnderDBIter(InternalIterator* iter) {
|
2020-02-22 00:07:55 +01:00
|
|
|
db_iter_->SetIter(iter);
|
2019-09-13 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
2020-02-22 00:07:55 +01:00
|
|
|
bool Valid() const override { return db_iter_->Valid(); }
|
|
|
|
void SeekToFirst() override { db_iter_->SeekToFirst(); }
|
|
|
|
void SeekToLast() override { db_iter_->SeekToLast(); }
|
2020-03-07 01:21:03 +01:00
|
|
|
// 'target' does not contain timestamp, even if user timestamp feature is
|
|
|
|
// enabled.
|
2020-02-22 00:07:55 +01:00
|
|
|
void Seek(const Slice& target) override { db_iter_->Seek(target); }
|
|
|
|
void SeekForPrev(const Slice& target) override {
|
2019-09-13 22:48:04 +02:00
|
|
|
db_iter_->SeekForPrev(target);
|
|
|
|
}
|
2020-02-22 00:07:55 +01:00
|
|
|
void Next() override { db_iter_->Next(); }
|
|
|
|
void Prev() override { db_iter_->Prev(); }
|
|
|
|
Slice key() const override { return db_iter_->key(); }
|
|
|
|
Slice value() const override { return db_iter_->value(); }
|
|
|
|
Status status() const override { return db_iter_->status(); }
|
2020-03-07 01:21:03 +01:00
|
|
|
Slice timestamp() const override { return db_iter_->timestamp(); }
|
2019-09-13 22:48:04 +02:00
|
|
|
bool IsBlob() const { return db_iter_->IsBlob(); }
|
|
|
|
|
2020-02-22 00:07:55 +01:00
|
|
|
Status GetProperty(std::string prop_name, std::string* prop) override;
|
2019-09-13 22:48:04 +02:00
|
|
|
|
2020-02-22 00:07:55 +01:00
|
|
|
Status Refresh() override;
|
2019-09-13 22:48:04 +02:00
|
|
|
|
|
|
|
void Init(Env* env, const ReadOptions& read_options,
|
|
|
|
const ImmutableCFOptions& cf_options,
|
2020-12-05 06:28:26 +01:00
|
|
|
const MutableCFOptions& mutable_cf_options, const Version* version,
|
2019-09-13 22:48:04 +02:00
|
|
|
const SequenceNumber& sequence,
|
|
|
|
uint64_t max_sequential_skip_in_iterations, uint64_t version_number,
|
|
|
|
ReadCallback* read_callback, DBImpl* db_impl, ColumnFamilyData* cfd,
|
2020-12-05 06:28:26 +01:00
|
|
|
bool expose_blob_index, bool allow_refresh);
|
2019-09-13 22:48:04 +02:00
|
|
|
|
|
|
|
// Store some parameters so we can refresh the iterator at a later point
|
|
|
|
// with these same params
|
2020-08-04 00:21:56 +02:00
|
|
|
void StoreRefreshInfo(DBImpl* db_impl, ColumnFamilyData* cfd,
|
2020-12-05 06:28:26 +01:00
|
|
|
ReadCallback* read_callback, bool expose_blob_index) {
|
2019-09-13 22:48:04 +02:00
|
|
|
db_impl_ = db_impl;
|
|
|
|
cfd_ = cfd;
|
|
|
|
read_callback_ = read_callback;
|
2020-12-05 06:28:26 +01:00
|
|
|
expose_blob_index_ = expose_blob_index;
|
2019-09-13 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
DBIter* db_iter_;
|
|
|
|
Arena arena_;
|
|
|
|
uint64_t sv_number_;
|
|
|
|
ColumnFamilyData* cfd_ = nullptr;
|
|
|
|
DBImpl* db_impl_ = nullptr;
|
|
|
|
ReadOptions read_options_;
|
|
|
|
ReadCallback* read_callback_;
|
2020-12-05 06:28:26 +01:00
|
|
|
bool expose_blob_index_ = false;
|
2019-09-13 22:48:04 +02:00
|
|
|
bool allow_refresh_ = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Generate the arena wrapped iterator class.
|
|
|
|
// `db_impl` and `cfd` are used for reneweal. If left null, renewal will not
|
|
|
|
// be supported.
|
|
|
|
extern ArenaWrappedDBIter* NewArenaWrappedDbIterator(
|
|
|
|
Env* env, const ReadOptions& read_options,
|
|
|
|
const ImmutableCFOptions& cf_options,
|
2020-12-05 06:28:26 +01:00
|
|
|
const MutableCFOptions& mutable_cf_options, const Version* version,
|
|
|
|
const SequenceNumber& sequence, uint64_t max_sequential_skip_in_iterations,
|
|
|
|
uint64_t version_number, ReadCallback* read_callback,
|
|
|
|
DBImpl* db_impl = nullptr, ColumnFamilyData* cfd = nullptr,
|
|
|
|
bool expose_blob_index = false, bool allow_refresh = true);
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|