mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-26 16:30:56 +00:00
fdf882ded2
Summary: When dynamically linking two binaries together, different builds of RocksDB from two sources might cause errors. To provide a tool for user to solve the problem, the RocksDB namespace is changed to a flag which can be overridden in build time. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6433 Test Plan: Build release, all and jtest. Try to build with ROCKSDB_NAMESPACE with another flag. Differential Revision: D19977691 fbshipit-source-id: aa7f2d0972e1c31d75339ac48478f34f6cfcfb3e
148 lines
3.6 KiB
C++
148 lines
3.6 KiB
C++
// 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).
|
|
|
|
#pragma once
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
#include "db/arena_wrapped_db_iter.h"
|
|
#include "monitoring/statistics.h"
|
|
#include "rocksdb/iterator.h"
|
|
#include "util/stop_watch.h"
|
|
#include "utilities/blob_db/blob_db_impl.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
namespace blob_db {
|
|
|
|
using ROCKSDB_NAMESPACE::ManagedSnapshot;
|
|
|
|
class BlobDBIterator : public Iterator {
|
|
public:
|
|
BlobDBIterator(ManagedSnapshot* snapshot, ArenaWrappedDBIter* iter,
|
|
BlobDBImpl* blob_db, Env* env, Statistics* statistics)
|
|
: snapshot_(snapshot),
|
|
iter_(iter),
|
|
blob_db_(blob_db),
|
|
env_(env),
|
|
statistics_(statistics) {}
|
|
|
|
virtual ~BlobDBIterator() = default;
|
|
|
|
bool Valid() const override {
|
|
if (!iter_->Valid()) {
|
|
return false;
|
|
}
|
|
return status_.ok();
|
|
}
|
|
|
|
Status status() const override {
|
|
if (!iter_->status().ok()) {
|
|
return iter_->status();
|
|
}
|
|
return status_;
|
|
}
|
|
|
|
void SeekToFirst() override {
|
|
StopWatch seek_sw(env_, statistics_, BLOB_DB_SEEK_MICROS);
|
|
RecordTick(statistics_, BLOB_DB_NUM_SEEK);
|
|
iter_->SeekToFirst();
|
|
while (UpdateBlobValue()) {
|
|
iter_->Next();
|
|
}
|
|
}
|
|
|
|
void SeekToLast() override {
|
|
StopWatch seek_sw(env_, statistics_, BLOB_DB_SEEK_MICROS);
|
|
RecordTick(statistics_, BLOB_DB_NUM_SEEK);
|
|
iter_->SeekToLast();
|
|
while (UpdateBlobValue()) {
|
|
iter_->Prev();
|
|
}
|
|
}
|
|
|
|
void Seek(const Slice& target) override {
|
|
StopWatch seek_sw(env_, statistics_, BLOB_DB_SEEK_MICROS);
|
|
RecordTick(statistics_, BLOB_DB_NUM_SEEK);
|
|
iter_->Seek(target);
|
|
while (UpdateBlobValue()) {
|
|
iter_->Next();
|
|
}
|
|
}
|
|
|
|
void SeekForPrev(const Slice& target) override {
|
|
StopWatch seek_sw(env_, statistics_, BLOB_DB_SEEK_MICROS);
|
|
RecordTick(statistics_, BLOB_DB_NUM_SEEK);
|
|
iter_->SeekForPrev(target);
|
|
while (UpdateBlobValue()) {
|
|
iter_->Prev();
|
|
}
|
|
}
|
|
|
|
void Next() override {
|
|
assert(Valid());
|
|
StopWatch next_sw(env_, statistics_, BLOB_DB_NEXT_MICROS);
|
|
RecordTick(statistics_, BLOB_DB_NUM_NEXT);
|
|
iter_->Next();
|
|
while (UpdateBlobValue()) {
|
|
iter_->Next();
|
|
}
|
|
}
|
|
|
|
void Prev() override {
|
|
assert(Valid());
|
|
StopWatch prev_sw(env_, statistics_, BLOB_DB_PREV_MICROS);
|
|
RecordTick(statistics_, BLOB_DB_NUM_PREV);
|
|
iter_->Prev();
|
|
while (UpdateBlobValue()) {
|
|
iter_->Prev();
|
|
}
|
|
}
|
|
|
|
Slice key() const override {
|
|
assert(Valid());
|
|
return iter_->key();
|
|
}
|
|
|
|
Slice value() const override {
|
|
assert(Valid());
|
|
if (!iter_->IsBlob()) {
|
|
return iter_->value();
|
|
}
|
|
return value_;
|
|
}
|
|
|
|
// Iterator::Refresh() not supported.
|
|
|
|
private:
|
|
// Return true if caller should continue to next value.
|
|
bool UpdateBlobValue() {
|
|
value_.Reset();
|
|
status_ = Status::OK();
|
|
if (iter_->Valid() && iter_->status().ok() && iter_->IsBlob()) {
|
|
Status s = blob_db_->GetBlobValue(iter_->key(), iter_->value(), &value_);
|
|
if (s.IsNotFound()) {
|
|
return true;
|
|
} else {
|
|
if (!s.ok()) {
|
|
status_ = s;
|
|
}
|
|
return false;
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
std::unique_ptr<ManagedSnapshot> snapshot_;
|
|
std::unique_ptr<ArenaWrappedDBIter> iter_;
|
|
BlobDBImpl* blob_db_;
|
|
Env* env_;
|
|
Statistics* statistics_;
|
|
Status status_;
|
|
PinnableSlice value_;
|
|
};
|
|
} // namespace blob_db
|
|
} // namespace ROCKSDB_NAMESPACE
|
|
#endif // !ROCKSDB_LITE
|