StackableDB optionally take shared ownership of the underlying DB
This commit is contained in:
parent
1039133f2d
commit
849dca7221
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "rocksdb/db.h"
|
#include "rocksdb/db.h"
|
||||||
|
|
||||||
@ -18,11 +19,19 @@ namespace rocksdb {
|
|||||||
// This class contains APIs to stack rocksdb wrappers.Eg. Stack TTL over base d
|
// This class contains APIs to stack rocksdb wrappers.Eg. Stack TTL over base d
|
||||||
class StackableDB : public DB {
|
class StackableDB : public DB {
|
||||||
public:
|
public:
|
||||||
// StackableDB is the owner of db now!
|
// StackableDB take sole ownership of the underlying db.
|
||||||
explicit StackableDB(DB* db) : db_(db) {}
|
explicit StackableDB(DB* db) : db_(db) {}
|
||||||
|
|
||||||
|
// StackableDB take shared ownership of the underlying db.
|
||||||
|
explicit StackableDB(std::shared_ptr<DB>& db)
|
||||||
|
: db_(db.get()), shared_db_(db) {}
|
||||||
|
|
||||||
~StackableDB() {
|
~StackableDB() {
|
||||||
delete db_;
|
if (shared_db_ == nullptr) {
|
||||||
|
delete db_;
|
||||||
|
} else {
|
||||||
|
assert(shared_db_.get() == db_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Status Close() override { return db_->Close(); }
|
virtual Status Close() override { return db_->Close(); }
|
||||||
@ -375,6 +384,7 @@ class StackableDB : public DB {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
DB* db_;
|
DB* db_;
|
||||||
|
std::shared_ptr<DB> shared_db_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace rocksdb
|
} // namespace rocksdb
|
||||||
|
@ -215,14 +215,17 @@ class BlockBasedTable : public TableReader {
|
|||||||
private:
|
private:
|
||||||
friend class MockedBlockBasedTable;
|
friend class MockedBlockBasedTable;
|
||||||
// input_iter: if it is not null, update this one and return it as Iterator
|
// input_iter: if it is not null, update this one and return it as Iterator
|
||||||
static BlockIter* NewDataBlockIterator(
|
static BlockIter* NewDataBlockIterator(Rep* rep, const ReadOptions& ro,
|
||||||
Rep* rep, const ReadOptions& ro, const Slice& index_value,
|
const Slice& index_value,
|
||||||
BlockIter* input_iter = nullptr, bool is_index = false,
|
BlockIter* input_iter = nullptr,
|
||||||
GetContext* get_context = nullptr);
|
bool is_index = false,
|
||||||
static BlockIter* NewDataBlockIterator(
|
GetContext* get_context = nullptr);
|
||||||
Rep* rep, const ReadOptions& ro, const BlockHandle& block_hanlde,
|
static BlockIter* NewDataBlockIterator(Rep* rep, const ReadOptions& ro,
|
||||||
BlockIter* input_iter = nullptr, bool is_index = false,
|
const BlockHandle& block_hanlde,
|
||||||
GetContext* get_context = nullptr, Status s = Status());
|
BlockIter* input_iter = nullptr,
|
||||||
|
bool is_index = false,
|
||||||
|
GetContext* get_context = nullptr,
|
||||||
|
Status s = Status());
|
||||||
// If block cache enabled (compressed or uncompressed), looks for the block
|
// If block cache enabled (compressed or uncompressed), looks for the block
|
||||||
// identified by handle in (1) uncompressed cache, (2) compressed cache, and
|
// identified by handle in (1) uncompressed cache, (2) compressed cache, and
|
||||||
// then (3) file. If found, inserts into the cache(s) that were searched
|
// then (3) file. If found, inserts into the cache(s) that were searched
|
||||||
|
Loading…
x
Reference in New Issue
Block a user