]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
Bring read_only into ttl 1.5.9.2.fb
authorMayank Agarwal <amayank@fb.com>
Fri, 10 May 2013 21:19:47 +0000 (14:19 -0700)
committerMayank Agarwal <amayank@fb.com>
Fri, 10 May 2013 23:15:08 +0000 (16:15 -0700)
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

include/utilities/utility_db.h
utilities/ttl/db_ttl.cc
utilities/ttl/db_ttl.h
utilities/ttl/ttl_test.cc

index be2f2c4072c7be0a14e12e4a3d38a3cc1dd97bf2..0bbfd7dc0ea5293801e7dd3eb9d0de0ad8cec3af 100644 (file)
@@ -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
index a1ea38a1436cb51eeaa4442e6d582902676cd8d0..4a955fa21117b21f1be8b5171dc8ed74db047083 100644 (file)
@@ -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;
   }
index e02472db8605d720fd45fe565eb94555a3f7a6cd..93635fdb83447c4129279fc484a7df6a889969ba 100644 (file)
@@ -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();
 
index fb4ad1acd8ee7f045b3efc6357717c28541bfbe1..0c3207499cd8ec7aeb1ab346712011b1bb40bb6f 100644 (file)
@@ -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