@ -10,40 +10,27 @@
namespace rocksdb {
// Open the db inside DBWithTTL because options needs pointer to its ttl
DBWithTTL : : DBWithTTL ( const int32_t ttl ,
const Options & options ,
const std : : string & dbname ,
Status & st ,
bool read_only )
: StackableDB ( nullptr ) {
Options options_to_open = options ;
if ( options . compaction_filter ) {
ttl_comp_filter_ . reset (
new TtlCompactionFilter ( ttl , options . compaction_filter ) ) ;
options_to_open . compaction_filter = ttl_comp_filter_ . get ( ) ;
void DBWithTTL : : SanitizeOptions ( int32_t ttl , Options * options ) {
if ( options - > compaction_filter ) {
options - > compaction_filter =
new TtlCompactionFilter ( ttl , options - > compaction_filter ) ;
} else {
options_to_open . compaction_filter_factory =
std : : shared_ptr < CompactionFilterFactory > (
new TtlCompactionFilterFactory (
ttl , options . compaction_filter_factory ) ) ;
options - > compaction_filter_factory =
std : : shared_ptr < CompactionFilterFactory > ( new TtlCompactionFilterFactory (
ttl , options - > compaction_filter_factory ) ) ;
}
if ( options . merge_operator ) {
options_to_open . merge_operator . reset (
new TtlMergeOperator ( options . merge_operator ) ) ;
}
if ( read_only ) {
st = DB : : OpenForReadOnly ( options_to_open , dbname , & db_ ) ;
} else {
st = DB : : Open ( options_to_open , dbname , & db_ ) ;
if ( options - > merge_operator ) {
options - > merge_operator . reset (
new TtlMergeOperator ( options - > merge_operator ) ) ;
}
}
// Open the db inside DBWithTTL because options needs pointer to its ttl
DBWithTTL : : DBWithTTL ( DB * db ) : StackableDB ( db ) { }
DBWithTTL : : ~ DBWithTTL ( ) {
delete db_ ;
delete GetOptions ( ) . compaction_filter ;
}
Status UtilityDB : : OpenTtlDB (
@ -53,9 +40,19 @@ Status UtilityDB::OpenTtlDB(
int32_t ttl ,
bool read_only ) {
Status st ;
* dbptr = new DBWithTTL ( ttl , options , dbname , st , read_only ) ;
if ( ! st . ok ( ) ) {
delete * dbptr ;
Options options_to_open = options ;
DBWithTTL : : SanitizeOptions ( ttl , & options_to_open ) ;
DB * db ;
if ( read_only ) {
st = DB : : OpenForReadOnly ( options_to_open , dbname , & db ) ;
} else {
st = DB : : Open ( options_to_open , dbname , & db ) ;
}
if ( st . ok ( ) ) {
* dbptr = new DBWithTTL ( db ) ;
} else {
delete db ;
}
return st ;
}
@ -122,10 +119,8 @@ Status DBWithTTL::StripTS(std::string* str) {
return st ;
}
Status DBWithTTL : : Put (
const WriteOptions & opt ,
const Slice & key ,
const Slice & val ) {
Status DBWithTTL : : Put ( const WriteOptions & opt , const Slice & key ,
const Slice & val ) {
WriteBatch batch ;
batch . Put ( key , val ) ;
return Write ( opt , & batch ) ;
@ -166,10 +161,6 @@ bool DBWithTTL::KeyMayExist(const ReadOptions& options,
return ret ;
}
Status DBWithTTL : : Delete ( const WriteOptions & wopts , const Slice & key ) {
return db_ - > Delete ( wopts , key ) ;
}
Status DBWithTTL : : Merge ( const WriteOptions & opt ,
const Slice & key ,
const Slice & value ) {
@ -221,86 +212,6 @@ Iterator* DBWithTTL::NewIterator(const ReadOptions& opts) {
return new TtlIterator ( db_ - > NewIterator ( opts ) ) ;
}
const Snapshot * DBWithTTL : : GetSnapshot ( ) {
return db_ - > GetSnapshot ( ) ;
}
void DBWithTTL : : ReleaseSnapshot ( const Snapshot * snapshot ) {
db_ - > ReleaseSnapshot ( snapshot ) ;
}
bool DBWithTTL : : GetProperty ( const Slice & property , std : : string * value ) {
return db_ - > GetProperty ( property , value ) ;
}
void DBWithTTL : : GetApproximateSizes ( const Range * r , int n , uint64_t * sizes ) {
db_ - > GetApproximateSizes ( r , n , sizes ) ;
}
void DBWithTTL : : CompactRange ( const Slice * begin , const Slice * end ,
bool reduce_level , int target_level ) {
db_ - > CompactRange ( begin , end , reduce_level , target_level ) ;
}
int DBWithTTL : : NumberLevels ( ) {
return db_ - > NumberLevels ( ) ;
}
int DBWithTTL : : MaxMemCompactionLevel ( ) {
return db_ - > MaxMemCompactionLevel ( ) ;
}
int DBWithTTL : : Level0StopWriteTrigger ( ) {
return db_ - > Level0StopWriteTrigger ( ) ;
}
Env * DBWithTTL : : GetEnv ( ) const {
return db_ - > GetEnv ( ) ;
}
const Options & DBWithTTL : : GetOptions ( ) const {
return db_ - > GetOptions ( ) ;
}
Status DBWithTTL : : Flush ( const FlushOptions & fopts ) {
return db_ - > Flush ( fopts ) ;
}
Status DBWithTTL : : DisableFileDeletions ( ) {
return db_ - > DisableFileDeletions ( ) ;
}
Status DBWithTTL : : EnableFileDeletions ( ) {
return db_ - > EnableFileDeletions ( ) ;
}
Status DBWithTTL : : GetLiveFiles ( std : : vector < std : : string > & vec , uint64_t * mfs ,
bool flush_memtable ) {
return db_ - > GetLiveFiles ( vec , mfs , flush_memtable ) ;
}
SequenceNumber DBWithTTL : : GetLatestSequenceNumber ( ) const {
return db_ - > GetLatestSequenceNumber ( ) ;
}
Status DBWithTTL : : GetSortedWalFiles ( VectorLogPtr & files ) {
return db_ - > GetSortedWalFiles ( files ) ;
}
Status DBWithTTL : : DeleteFile ( std : : string name ) {
return db_ - > DeleteFile ( name ) ;
}
Status DBWithTTL : : GetDbIdentity ( std : : string & identity ) {
return db_ - > GetDbIdentity ( identity ) ;
}
Status DBWithTTL : : GetUpdatesSince (
SequenceNumber seq_number ,
unique_ptr < TransactionLogIterator > * iter ) {
return db_ - > GetUpdatesSince ( seq_number , iter ) ;
}
void DBWithTTL : : TEST_Destroy_DBWithTtl ( ) {
( ( DBImpl * ) db_ ) - > TEST_Destroy_DBImpl ( ) ;
}