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
// 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
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
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;
- st = DB::Open(options_to_open, dbname, &db_);
+ if (read_only) {
+ st = DB::OpenForReadOnly(options_to_open, dbname, &db_);
+ } else {
+ st = DB::Open(options_to_open, dbname, &db_);
+ }
}
DBWithTTL::~DBWithTTL() {
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;
}
DBWithTTL(const int32_t ttl,
const Options& options,
const std::string& dbname,
- Status& st);
+ Status& st,
+ bool read_only);
virtual ~DBWithTTL();
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;
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