]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/LevelDBStore: allow compaction of key ranges
authorSage Weil <sage@inktank.com>
Wed, 29 May 2013 15:34:13 +0000 (08:34 -0700)
committerSage Weil <sage@inktank.com>
Sun, 2 Jun 2013 21:09:51 +0000 (14:09 -0700)
Signed-off-by: Sage Weil <sage@inktank.com>
(cherry picked from commit e20c9a3f79ccfeb816ed634ca25de29fc5975ea8)

src/os/LevelDBStore.cc
src/os/LevelDBStore.h

index 5f052a57aff382187dcaaffeac81178cf8b52709..166a1553578f0a3233f84146aa87d803191ee928 100644 (file)
@@ -146,10 +146,10 @@ void LevelDBStore::compact_thread_entry()
   compact_queue_lock.Lock();
   while (!compact_queue_stop) {
     while (!compact_queue.empty()) {
-      string prefix = compact_queue.front();
+      pair<string,string> range = compact_queue.front();
       compact_queue.pop_front();
       compact_queue_lock.Unlock();
-      compact_prefix(prefix);
+      compact_range(range.first, range.second);
       compact_queue_lock.Lock();
       continue;
     }
index 94a69492247982a0a85ca05ad1722eed50803a58..e4e84107fdf0381110a10cb932d4760befffd3b2 100644 (file)
@@ -36,7 +36,7 @@ class LevelDBStore : public KeyValueDB {
   // manage async compactions
   Mutex compact_queue_lock;
   Cond compact_queue_cond;
-  list<string> compact_queue;
+  list< pair<string,string> > compact_queue;
   bool compact_queue_stop;
   class CompactThread : public Thread {
     LevelDBStore *db;
@@ -51,6 +51,21 @@ class LevelDBStore : public KeyValueDB {
 
   void compact_thread_entry();
 
+  void compact_range(const string& start, const string& end) {
+    leveldb::Slice cstart(start);
+    leveldb::Slice cend(end);
+    db->CompactRange(&cstart, &cend);
+  }
+  void compact_range_async(const string& start, const string& end) {
+    Mutex::Locker l(compact_queue_lock);
+    compact_queue.remove(make_pair(start, end));    // prevent unbounded dups
+    compact_queue.push_back(make_pair(start, end));
+    compact_queue_cond.Signal();
+    if (!compact_thread.is_started()) {
+      compact_thread.create();
+    }
+  }
+
 public:
   /// compact the underlying leveldb store
   void compact() {
@@ -59,23 +74,17 @@ public:
 
   /// 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);
+    compact_range(prefix, past_prefix(prefix));
   }
-
   void compact_prefix_async(const string& prefix) {
-    Mutex::Locker l(compact_queue_lock);
-    compact_queue.remove(prefix);     // prevent unbounded dups
-    compact_queue.push_back(prefix);
-    compact_queue_cond.Signal();
-    if (!compact_thread.is_started()) {
-      compact_thread.create();
-    }
+    compact_range_async(prefix, past_prefix(prefix));
+  }
+
+  void compact_range(const string& prefix, const string& start, const string& end) {
+    compact_range(combine_strings(prefix, start), combine_strings(prefix, end));
+  }
+  void compact_range_async(const string& prefix, const string& start, const string& end) {
+    compact_range_async(combine_strings(prefix, start), combine_strings(prefix, end));
   }
 
   /**