]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
leveldb: add compact_prefix method
authorSage Weil <sage@inktank.com>
Mon, 29 Apr 2013 22:01:05 +0000 (15:01 -0700)
committerSage Weil <sage@inktank.com>
Mon, 29 Apr 2013 22:45:41 +0000 (15:45 -0700)
Signed-off-by: Sage Weil <sage@inktank.com>
src/os/LevelDBStore.h

index 9f8cd52ca9c758b0dbdcf62456d5421a14b801af..83f2ed3b4c4518bafbe8705aaa8ae4d6909d3367 100644 (file)
@@ -38,6 +38,17 @@ public:
     db->CompactRange(NULL, NULL);
   }
 
+  /// compact leveldb for all keys with a given prefix
+  void compact_prefix(const string& prefix) {
+    // if we combine the prefix with key by adding a '\0' separator,
+    // a char(1) will capture all such keys.
+    string end = prefix;
+    end += (char)1;
+    leveldb::Slice cstart(prefix);
+    leveldb::Slice cend(end);
+    db->CompactRange(&cstart, &cend);
+  }
+
   /**
    * options_t: Holds options which are minimally interpreted
    * on initialization and then passed through to LevelDB.