mirror of https://github.com/facebook/rocksdb.git
Bring read_only into ttl
Summary: added an argument to openttldb for read only and open the db in normal readonly mode if the arguments is set to true Test Plan: make ttl_test; ./ttl_test Reviewers: dhruba, haobo, vamsi, sheki Reviewed By: dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D10749
This commit is contained in:
parent
8d58ecdc29
commit
3102628873
|
@ -30,6 +30,8 @@ class UtilityDB {
|
|||
// Different TTL may be used during different Opens
|
||||
// Example: Open1 at t=0 with ttl=4 and insert k1,k2, close at t=2
|
||||
// Open2 at t=3 with ttl=5. Now k1,k2 should be deleted at t>=5
|
||||
// read_only=true opens in the usual read-only mode. Compactions will not be
|
||||
// triggered(neither manual nor automatic), so no expired entries removed
|
||||
//
|
||||
// CONSTRAINTS:
|
||||
// The caller must not specify any compaction-filter in options
|
||||
|
@ -44,7 +46,8 @@ class UtilityDB {
|
|||
static Status OpenTtlDB(const Options& options,
|
||||
const std::string& name,
|
||||
DB** dbptr,
|
||||
int32_t ttl = 0);
|
||||
int32_t ttl = 0,
|
||||
bool read_only = false);
|
||||
};
|
||||
|
||||
} // namespace leveldb
|
||||
|
|
|
@ -72,13 +72,18 @@ class TtlIterator : public Iterator {
|
|||
DBWithTTL::DBWithTTL(const int32_t ttl,
|
||||
const Options& options,
|
||||
const std::string& dbname,
|
||||
Status& st)
|
||||
Status& st,
|
||||
bool read_only)
|
||||
: ttl_(ttl) {
|
||||
assert(options.CompactionFilter == nullptr);
|
||||
Options options_to_open = options;
|
||||
options_to_open.compaction_filter_args = &ttl_;
|
||||
options_to_open.CompactionFilter = DeleteByTS;
|
||||
if (read_only) {
|
||||
st = DB::OpenForReadOnly(options_to_open, dbname, &db_);
|
||||
} else {
|
||||
st = DB::Open(options_to_open, dbname, &db_);
|
||||
}
|
||||
}
|
||||
|
||||
DBWithTTL::~DBWithTTL() {
|
||||
|
@ -89,9 +94,10 @@ Status UtilityDB::OpenTtlDB(
|
|||
const Options& options,
|
||||
const std::string& dbname,
|
||||
DB** dbptr,
|
||||
int32_t ttl) {
|
||||
int32_t ttl,
|
||||
bool read_only) {
|
||||
Status st;
|
||||
*dbptr = new DBWithTTL(ttl, options, dbname, st);
|
||||
*dbptr = new DBWithTTL(ttl, options, dbname, st, read_only);
|
||||
if (!st.ok()) {
|
||||
delete dbptr;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,8 @@ class DBWithTTL : public DB {
|
|||
DBWithTTL(const int32_t ttl,
|
||||
const Options& options,
|
||||
const std::string& dbname,
|
||||
Status& st);
|
||||
Status& st,
|
||||
bool read_only);
|
||||
|
||||
virtual ~DBWithTTL();
|
||||
|
||||
|
|
|
@ -44,6 +44,12 @@ class TtlTest {
|
|||
ASSERT_OK(UtilityDB::OpenTtlDB(options_, dbname_, &db_ttl_, ttl));
|
||||
}
|
||||
|
||||
// Open database with TTL support in read_only mode
|
||||
void OpenReadOnlyTtl(int32_t ttl) {
|
||||
assert(db_ttl_ == nullptr);
|
||||
ASSERT_OK(UtilityDB::OpenTtlDB(options_, dbname_, &db_ttl_, ttl, true));
|
||||
}
|
||||
|
||||
void CloseTtl() {
|
||||
delete db_ttl_;
|
||||
db_ttl_ = nullptr;
|
||||
|
@ -273,6 +279,19 @@ TEST(TtlTest, MultiOpenDifferent) {
|
|||
CloseTtl();
|
||||
}
|
||||
|
||||
// Checks presence during ttl in read_only mode
|
||||
TEST(TtlTest, ReadOnlyPresentForever) {
|
||||
MakeKVMap(kSampleSize);
|
||||
|
||||
OpenTtl(1); // T=0:Open the db normally
|
||||
PutValues(0, kSampleSize); // T=0:Insert Set1. Delete at t=1
|
||||
CloseTtl();
|
||||
|
||||
OpenReadOnlyTtl(1);
|
||||
SleepCompactCheck(2, 0, kSampleSize, true); // T=2:Set1 should still be there
|
||||
CloseTtl();
|
||||
}
|
||||
|
||||
} // namespace leveldb
|
||||
|
||||
// A black-box test for the ttl wrapper around rocksdb
|
||||
|
|
Loading…
Reference in New Issue