mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-26 07:30:54 +00:00
35c8c814e8
Summary: In D19581 I made `ForwardIterator::status()` check all child iterators, including immutable ones. It's, however, not necessary to do it every time -- it'll suffice to check only when they're used and their status could change. This diff: * introduces `immutable_status_` which is updated by `Seek()` and `Next()` * removes special handling of `kIncomplete` status in those methods Test Plan: * `db_test` * hacked ReadSequential in db_bench.cc to check `status()` in addition to validity: ``` $ ./db_bench -use_existing_db -benchmarks readseq -disable_auto_compactions \ -use_tailing_iterator # without this patch Keys: 16 bytes each Values: 100 bytes each (50 bytes after compression) Entries: 1000000 [...] DB path: [/dev/shm/rocksdbtest/dbbench] readseq : 0.562 micros/op 1778103 ops/sec; 98.4 MB/s $ ./db_bench -use_existing_db -benchmarks readseq -disable_auto_compactions \ -use_tailing_iterator # with the patch readseq : 0.433 micros/op 2311363 ops/sec; 127.8 MB/s ``` Reviewers: igor, sdong, ljin Reviewed By: ljin Subscribers: dhruba, leveldb, march, lovro Differential Revision: https://reviews.facebook.net/D24063
111 lines
3.1 KiB
C++
111 lines
3.1 KiB
C++
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under the BSD-style license found in the
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
#pragma once
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <queue>
|
|
|
|
#include "rocksdb/db.h"
|
|
#include "rocksdb/iterator.h"
|
|
#include "rocksdb/options.h"
|
|
#include "db/dbformat.h"
|
|
#include "util/arena.h"
|
|
|
|
namespace rocksdb {
|
|
|
|
class DBImpl;
|
|
class Env;
|
|
struct SuperVersion;
|
|
class ColumnFamilyData;
|
|
class LevelIterator;
|
|
struct FileMetaData;
|
|
|
|
class MinIterComparator {
|
|
public:
|
|
explicit MinIterComparator(const Comparator* comparator) :
|
|
comparator_(comparator) {}
|
|
|
|
bool operator()(Iterator* a, Iterator* b) {
|
|
return comparator_->Compare(a->key(), b->key()) > 0;
|
|
}
|
|
private:
|
|
const Comparator* comparator_;
|
|
};
|
|
|
|
typedef std::priority_queue<Iterator*,
|
|
std::vector<Iterator*>,
|
|
MinIterComparator> MinIterHeap;
|
|
|
|
/**
|
|
* ForwardIterator is a special type of iterator that only supports Seek()
|
|
* and Next(). It is expected to perform better than TailingIterator by
|
|
* removing the encapsulation and making all information accessible within
|
|
* the iterator. At the current implementation, snapshot is taken at the
|
|
* time Seek() is called. The Next() followed do not see new values after.
|
|
*/
|
|
class ForwardIterator : public Iterator {
|
|
public:
|
|
ForwardIterator(DBImpl* db, const ReadOptions& read_options,
|
|
ColumnFamilyData* cfd, SuperVersion* current_sv = nullptr);
|
|
virtual ~ForwardIterator();
|
|
|
|
void SeekToLast() override {
|
|
status_ = Status::NotSupported("ForwardIterator::SeekToLast()");
|
|
valid_ = false;
|
|
}
|
|
void Prev() {
|
|
status_ = Status::NotSupported("ForwardIterator::Prev");
|
|
valid_ = false;
|
|
}
|
|
|
|
virtual bool Valid() const override;
|
|
void SeekToFirst() override;
|
|
virtual void Seek(const Slice& target) override;
|
|
virtual void Next() override;
|
|
virtual Slice key() const override;
|
|
virtual Slice value() const override;
|
|
virtual Status status() const override;
|
|
|
|
private:
|
|
void Cleanup(bool release_sv);
|
|
void RebuildIterators(bool refresh_sv);
|
|
void ResetIncompleteIterators();
|
|
void SeekInternal(const Slice& internal_key, bool seek_to_first);
|
|
void UpdateCurrent();
|
|
bool NeedToSeekImmutable(const Slice& internal_key);
|
|
uint32_t FindFileInRange(
|
|
const std::vector<FileMetaData*>& files, const Slice& internal_key,
|
|
uint32_t left, uint32_t right);
|
|
|
|
DBImpl* const db_;
|
|
const ReadOptions read_options_;
|
|
ColumnFamilyData* const cfd_;
|
|
const SliceTransform* const prefix_extractor_;
|
|
const Comparator* user_comparator_;
|
|
MinIterHeap immutable_min_heap_;
|
|
|
|
SuperVersion* sv_;
|
|
Iterator* mutable_iter_;
|
|
std::vector<Iterator*> imm_iters_;
|
|
std::vector<Iterator*> l0_iters_;
|
|
std::vector<LevelIterator*> level_iters_;
|
|
Iterator* current_;
|
|
// internal iterator status
|
|
Status status_;
|
|
Status immutable_status_;
|
|
bool valid_;
|
|
|
|
IterKey prev_key_;
|
|
bool is_prev_set_;
|
|
bool is_prev_inclusive_;
|
|
Arena arena_;
|
|
};
|
|
|
|
} // namespace rocksdb
|
|
#endif // ROCKSDB_LITE
|