@ -10,152 +10,140 @@ 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 :
explicit StackableDB ( StackableDB * sdb ) : sdb_ ( sdb ) { }
// StackableDB is the owner of db now!
explicit StackableDB ( DB * db ) : db_ ( db ) { }
// Returns the DB object that is the lowermost component in the stack of DBs
~ StackableDB ( ) {
virtual DB * GetRawDB ( ) {
delete db_ ;
return sdb_ - > GetRawDB ( ) ;
}
}
// convert a DB to StackableDB
virtual DB * GetBaseDB ( ) {
// TODO: This function does not work yet. Passing nullptr to StackableDB in
return db_ ;
// NewStackableDB's constructor will cause segfault on object's usage
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 ,
virtual Status Put ( const WriteOptions & options ,
const Slice & key ,
const Slice & key ,
const Slice & val ) override {
const Slice & val ) override {
return s db_- > Put ( options , key , val ) ;
return db_ - > Put ( options , key , val ) ;
}
}
virtual Status Get ( const ReadOptions & options ,
virtual Status Get ( const ReadOptions & options ,
const Slice & key ,
const Slice & key ,
std : : string * value ) override {
std : : string * value ) override {
return s db_- > Get ( options , key , value ) ;
return db_ - > Get ( options , key , value ) ;
}
}
virtual std : : vector < Status > MultiGet ( const ReadOptions & options ,
virtual std : : vector < Status > MultiGet ( const ReadOptions & options ,
const std : : vector < Slice > & keys ,
const std : : vector < Slice > & keys ,
std : : vector < std : : string > * values )
std : : vector < std : : string > * values )
override {
override {
return s db_- > MultiGet ( options , keys , values ) ;
return db_ - > MultiGet ( options , keys , values ) ;
}
}
virtual bool KeyMayExist ( const ReadOptions & options ,
virtual bool KeyMayExist ( const ReadOptions & options ,
const Slice & key ,
const Slice & key ,
std : : string * value ,
std : : string * value ,
bool * value_found = nullptr ) override {
bool * value_found = nullptr ) override {
return s db_- > KeyMayExist ( options , key , value , value_found ) ;
return db_ - > KeyMayExist ( options , key , value , value_found ) ;
}
}
virtual Status Delete ( const WriteOptions & wopts , const Slice & key ) override {
virtual Status Delete ( const WriteOptions & wopts , const Slice & key ) override {
return s db_- > Delete ( wopts , key ) ;
return db_ - > Delete ( wopts , key ) ;
}
}
virtual Status Merge ( const WriteOptions & options ,
virtual Status Merge ( const WriteOptions & options ,
const Slice & key ,
const Slice & key ,
const Slice & value ) override {
const Slice & value ) override {
return s db_- > Merge ( options , key , value ) ;
return db_ - > Merge ( options , key , value ) ;
}
}
virtual Status Write ( const WriteOptions & opts , WriteBatch * updates )
virtual Status Write ( const WriteOptions & opts , WriteBatch * updates )
override {
override {
return s db_- > Write ( opts , updates ) ;
return db_ - > Write ( opts , updates ) ;
}
}
virtual Iterator * NewIterator ( const ReadOptions & opts ) override {
virtual Iterator * NewIterator ( const ReadOptions & opts ) override {
return s db_- > NewIterator ( opts ) ;
return db_ - > NewIterator ( opts ) ;
}
}
virtual const Snapshot * GetSnapshot ( ) override {
virtual const Snapshot * GetSnapshot ( ) override {
return s db_- > GetSnapshot ( ) ;
return db_ - > GetSnapshot ( ) ;
}
}
virtual void ReleaseSnapshot ( const Snapshot * snapshot ) override {
virtual void ReleaseSnapshot ( const Snapshot * snapshot ) override {
return s db_- > ReleaseSnapshot ( snapshot ) ;
return db_ - > ReleaseSnapshot ( snapshot ) ;
}
}
virtual bool GetProperty ( const Slice & property , std : : string * value )
virtual bool GetProperty ( const Slice & property , std : : string * value )
override {
override {
return s db_- > GetProperty ( property , value ) ;
return db_ - > GetProperty ( property , value ) ;
}
}
virtual void GetApproximateSizes ( const Range * r , int n , uint64_t * sizes )
virtual void GetApproximateSizes ( const Range * r , int n , uint64_t * sizes )
override {
override {
return s db_- > GetApproximateSizes ( r , n , sizes ) ;
return db_ - > GetApproximateSizes ( r , n , sizes ) ;
}
}
virtual void CompactRange ( const Slice * begin , const Slice * end ,
virtual void CompactRange ( const Slice * begin , const Slice * end ,
bool reduce_level = false ,
bool reduce_level = false ,
int target_level = - 1 ) override {
int target_level = - 1 ) override {
return s db_- > CompactRange ( begin , end , reduce_level , target_level ) ;
return db_ - > CompactRange ( begin , end , reduce_level , target_level ) ;
}
}
virtual int NumberLevels ( ) override {
virtual int NumberLevels ( ) override {
return s db_- > NumberLevels ( ) ;
return db_ - > NumberLevels ( ) ;
}
}
virtual int MaxMemCompactionLevel ( ) override {
virtual int MaxMemCompactionLevel ( ) override {
return s db_- > MaxMemCompactionLevel ( ) ;
return db_ - > MaxMemCompactionLevel ( ) ;
}
}
virtual int Level0StopWriteTrigger ( ) override {
virtual int Level0StopWriteTrigger ( ) override {
return sdb_ - > Level0StopWriteTrigger ( ) ;
return db_ - > Level0StopWriteTrigger ( ) ;
}
virtual Env * GetEnv ( ) const override {
return db_ - > GetEnv ( ) ;
}
}
virtual Status Flush ( const FlushOptions & fopts ) override {
virtual Status Flush ( const FlushOptions & fopts ) override {
return sdb_ - > Flush ( fopts ) ;
return db_ - > Flush ( fopts ) ;
}
}
virtual Status DisableFileDeletions ( ) override {
virtual Status DisableFileDeletions ( ) override {
return s db_- > DisableFileDeletions ( ) ;
return db_ - > DisableFileDeletions ( ) ;
}
}
virtual Status EnableFileDeletions ( ) override {
virtual Status EnableFileDeletions ( ) override {
return s db_- > EnableFileDeletions ( ) ;
return db_ - > EnableFileDeletions ( ) ;
}
}
virtual Status GetLiveFiles ( std : : vector < std : : string > & vec , uint64_t * mfs ,
virtual Status GetLiveFiles ( std : : vector < std : : string > & vec , uint64_t * mfs ,
bool flush_memtable = true ) override {
bool flush_memtable = true ) override {
return s db_- > GetLiveFiles ( vec , mfs , flush_memtable ) ;
return db_ - > GetLiveFiles ( vec , mfs , flush_memtable ) ;
}
}
virtual SequenceNumber GetLatestSequenceNumber ( ) const override {
virtual SequenceNumber GetLatestSequenceNumber ( ) const override {
return s db_- > GetLatestSequenceNumber ( ) ;
return db_ - > GetLatestSequenceNumber ( ) ;
}
}
virtual Status GetSortedWalFiles ( VectorLogPtr & files ) override {
virtual Status GetSortedWalFiles ( VectorLogPtr & files ) override {
return s db_- > GetSortedWalFiles ( files ) ;
return db_ - > GetSortedWalFiles ( files ) ;
}
}
virtual Status DeleteFile ( std : : string name ) override {
virtual Status DeleteFile ( std : : string name ) override {
return s db_- > DeleteFile ( name ) ;
return db_ - > DeleteFile ( name ) ;
}
}
virtual Status GetUpdatesSince ( SequenceNumber seq_number ,
virtual Status GetUpdatesSince ( SequenceNumber seq_number ,
unique_ptr < TransactionLogIterator > * iter )
unique_ptr < TransactionLogIterator > * iter )
override {
override {
return s db_- > GetUpdatesSince ( seq_number , iter ) ;
return db_ - > GetUpdatesSince ( seq_number , iter ) ;
}
}
protected :
protected :
Stackable DB* s db_;
DB * db_ ;
} ;
} ;
} // namespace rocksdb
} // namespace rocksdb