diff options
author | Mayank Agarwal <amayank@fb.com> | 2013-05-10 14:19:47 -0700 |
---|---|---|
committer | Mayank Agarwal <amayank@fb.com> | 2013-05-10 16:15:08 -0700 |
commit | 85688c8b8ad985943514c456070896a5b5ef0e1b (patch) | |
tree | c09222827d01a31e256effcae2d4a588a9314e79 | |
parent | 6b4dc4450b7528f705576cf4201d11367e62c190 (diff) |
Bring read_only into ttl1.5.9.2.fb
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
-rw-r--r-- | include/utilities/utility_db.h | 5 | ||||
-rw-r--r-- | utilities/ttl/db_ttl.cc | 14 | ||||
-rw-r--r-- | utilities/ttl/db_ttl.h | 3 | ||||
-rw-r--r-- | utilities/ttl/ttl_test.cc | 19 |
4 files changed, 35 insertions, 6 deletions
diff --git a/include/utilities/utility_db.h b/include/utilities/utility_db.h index be2f2c407..0bbfd7dc0 100644 --- a/include/utilities/utility_db.h +++ b/include/utilities/utility_db.h @@ -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 diff --git a/utilities/ttl/db_ttl.cc b/utilities/ttl/db_ttl.cc index a1ea38a14..4a955fa21 100644 --- a/utilities/ttl/db_ttl.cc +++ b/utilities/ttl/db_ttl.cc @@ -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; - 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() { @@ -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; } diff --git a/utilities/ttl/db_ttl.h b/utilities/ttl/db_ttl.h index e02472db8..93635fdb8 100644 --- a/utilities/ttl/db_ttl.h +++ b/utilities/ttl/db_ttl.h @@ -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(); diff --git a/utilities/ttl/ttl_test.cc b/utilities/ttl/ttl_test.cc index fb4ad1acd..0c3207499 100644 --- a/utilities/ttl/ttl_test.cc +++ b/utilities/ttl/ttl_test.cc @@ -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 |