2013-08-06 02:55:44 +02:00
|
|
|
// 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.
|
|
|
|
|
2013-10-05 07:32:05 +02:00
|
|
|
#pragma once
|
2013-08-23 17:38:13 +02:00
|
|
|
#include "rocksdb/db.h"
|
2013-08-06 02:55:44 +02:00
|
|
|
|
2013-10-04 06:49:15 +02:00
|
|
|
namespace rocksdb {
|
2013-08-06 02:55:44 +02:00
|
|
|
|
|
|
|
// This class contains APIs to stack rocksdb wrappers.Eg. Stack TTL over base d
|
|
|
|
class StackableDB : public DB {
|
|
|
|
public:
|
|
|
|
explicit StackableDB(StackableDB* sdb) : sdb_(sdb) {}
|
|
|
|
|
|
|
|
// Returns the DB object that is the lowermost component in the stack of DBs
|
|
|
|
virtual DB* GetRawDB() {
|
|
|
|
return sdb_->GetRawDB();
|
|
|
|
}
|
|
|
|
|
|
|
|
// convert a DB to StackableDB
|
2013-08-21 06:32:24 +02:00
|
|
|
// TODO: This function does not work yet. Passing nullptr to StackableDB in
|
|
|
|
// NewStackableDB's constructor will cause segfault on object's usage
|
2013-08-06 02:55:44 +02:00
|
|
|
static StackableDB* DBToStackableDB(DB* db) {
|
|
|
|
class NewStackableDB : public StackableDB {
|
|
|
|
public:
|
|
|
|
NewStackableDB(DB* db)
|
|
|
|
: StackableDB(nullptr),
|
|
|
|
db_(db) {}
|
|
|
|
|
|
|
|
DB* GetRawDB() {
|
|
|
|
return db_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
DB* db_;
|
|
|
|
};
|
|
|
|
return new NewStackableDB(db);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Status Put(const WriteOptions& options,
|
|
|
|
const Slice& key,
|
|
|
|
const Slice& val) override {
|
|
|
|
return sdb_->Put(options, key, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Status Get(const ReadOptions& options,
|
|
|
|
const Slice& key,
|
|
|
|
std::string* value) override {
|
|
|
|
return sdb_->Get(options, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual std::vector<Status> MultiGet(const ReadOptions& options,
|
|
|
|
const std::vector<Slice>& keys,
|
|
|
|
std::vector<std::string>* values)
|
|
|
|
override {
|
|
|
|
return sdb_->MultiGet(options, keys, values);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool KeyMayExist(const ReadOptions& options,
|
|
|
|
const Slice& key,
|
|
|
|
std::string* value,
|
|
|
|
bool* value_found = nullptr) override {
|
2013-08-19 20:42:47 +02:00
|
|
|
return sdb_->KeyMayExist(options, key, value, value_found);
|
2013-08-06 02:55:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual Status Delete(const WriteOptions& wopts, const Slice& key) override {
|
|
|
|
return sdb_->Delete(wopts, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Status Merge(const WriteOptions& options,
|
|
|
|
const Slice& key,
|
|
|
|
const Slice& value) override {
|
|
|
|
return sdb_->Merge(options, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual Status Write(const WriteOptions& opts, WriteBatch* updates)
|
|
|
|
override {
|
|
|
|
return sdb_->Write(opts, updates);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Iterator* NewIterator(const ReadOptions& opts) override {
|
|
|
|
return sdb_->NewIterator(opts);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual const Snapshot* GetSnapshot() override {
|
|
|
|
return sdb_->GetSnapshot();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void ReleaseSnapshot(const Snapshot* snapshot) override {
|
|
|
|
return sdb_->ReleaseSnapshot(snapshot);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool GetProperty(const Slice& property, std::string* value)
|
|
|
|
override {
|
|
|
|
return sdb_->GetProperty(property, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void GetApproximateSizes(const Range* r, int n, uint64_t* sizes)
|
|
|
|
override {
|
|
|
|
return sdb_->GetApproximateSizes(r, n, sizes);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void CompactRange(const Slice* begin, const Slice* end,
|
2013-09-04 22:13:08 +02:00
|
|
|
bool reduce_level = false,
|
|
|
|
int target_level = -1) override {
|
|
|
|
return sdb_->CompactRange(begin, end, reduce_level, target_level);
|
2013-08-06 02:55:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual int NumberLevels() override {
|
|
|
|
return sdb_->NumberLevels();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int MaxMemCompactionLevel() override {
|
|
|
|
return sdb_->MaxMemCompactionLevel();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int Level0StopWriteTrigger() override {
|
|
|
|
return sdb_->Level0StopWriteTrigger();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Status Flush(const FlushOptions& fopts) override {
|
|
|
|
return sdb_->Flush(fopts);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Status DisableFileDeletions() override {
|
|
|
|
return sdb_->DisableFileDeletions();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Status EnableFileDeletions() override {
|
|
|
|
return sdb_->EnableFileDeletions();
|
|
|
|
}
|
|
|
|
|
2013-10-03 23:38:32 +02:00
|
|
|
virtual Status GetLiveFiles(std::vector<std::string>& vec, uint64_t* mfs,
|
|
|
|
bool flush_memtable = true) override {
|
|
|
|
return sdb_->GetLiveFiles(vec, mfs, flush_memtable);
|
2013-08-06 02:55:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual SequenceNumber GetLatestSequenceNumber() override {
|
|
|
|
return sdb_->GetLatestSequenceNumber();
|
|
|
|
}
|
|
|
|
|
2013-08-06 21:54:37 +02:00
|
|
|
virtual Status GetSortedWalFiles(VectorLogPtr& files) override {
|
|
|
|
return sdb_->GetSortedWalFiles(files);
|
|
|
|
}
|
|
|
|
|
2013-08-29 23:30:52 +02:00
|
|
|
virtual Status DeleteWalFiles(const VectorLogPtr& files) override {
|
|
|
|
return sdb_->DeleteWalFiles(files);
|
2013-08-06 21:54:37 +02:00
|
|
|
}
|
|
|
|
|
2013-08-06 02:55:44 +02:00
|
|
|
virtual Status GetUpdatesSince(SequenceNumber seq_number,
|
|
|
|
unique_ptr<TransactionLogIterator>* iter)
|
|
|
|
override {
|
|
|
|
return sdb_->GetUpdatesSince(seq_number, iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
StackableDB* sdb_;
|
|
|
|
};
|
|
|
|
|
2013-10-04 06:49:15 +02:00
|
|
|
} // namespace rocksdb
|