]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon:Change monitor compact command to run asynchronously 22056/head
authorpenglaiyxy <penglaiyxy@gmail.com>
Thu, 17 May 2018 10:39:51 +0000 (18:39 +0800)
committerroot <penglaiyxy>
Mon, 21 May 2018 03:03:55 +0000 (23:03 -0400)
In monitor message dispatch code, while one command is executing , it must have the dispatch lock. So indeed all command are executing synchronously. If one command is executing for long time, others command must wait.So change the monitor compact command to execute asynchronously.

Fixed: http://tracker.ceph.com/issues/24159
Signed-off-by: brandy penglaiyxy@gmail.com
src/kv/KeyValueDB.h
src/kv/LevelDBStore.cc
src/kv/LevelDBStore.h
src/kv/RocksDBStore.cc
src/kv/RocksDBStore.h
src/mon/Monitor.cc
src/mon/MonitorDBStore.h

index 50714d247136920108573a93311fc664c46cc91d..f6dace8202dfa407c73f57b524c9cb3098bb7349 100644 (file)
@@ -364,6 +364,9 @@ public:
   /// compact the underlying store
   virtual void compact() {}
 
+  /// compact the underlying store in async mode
+  virtual void compact_async() {}
+
   /// compact db for all keys with a given prefix
   virtual void compact_prefix(const std::string& prefix) {}
   /// compact db for all keys with a given prefix, async
index 7c8b44dc20d4c8838c8b74c3548c4bc1978d7d3f..9f5158a7c755395825dbba7218ba03947a8b7a0f 100644 (file)
@@ -394,7 +394,11 @@ void LevelDBStore::compact_thread_entry()
       logger->set(l_leveldb_compact_queue_len, compact_queue.size());
       compact_queue_lock.Unlock();
       logger->inc(l_leveldb_compact_range);
-      compact_range(range.first, range.second);
+      if (range.first.empty() && range.second.empty()) {
+        compact();
+      } else {
+        compact_range(range.first, range.second);
+      }
       compact_queue_lock.Lock();
       continue;
     }
index decd07977a69ad1817d224282f97fb61a07e9f3a..703f1eb519e8c2f9b6868e7700cc632b8dc84628 100644 (file)
@@ -98,6 +98,10 @@ public:
   /// compact the underlying leveldb store
   void compact() override;
 
+  void compact_async() override {
+    compact_range_async(string(), string());
+  }
+
   /// compact db for all keys with a given prefix
   void compact_prefix(const string& prefix) override {
     compact_range(prefix, past_prefix(prefix));
index 236b02346ac769947958e22e1a383a3f62395127..94df017dfd6f29155b9c4a5ad459df6486d6d3ff 100644 (file)
@@ -1172,7 +1172,11 @@ void RocksDBStore::compact_thread_entry()
       logger->set(l_rocksdb_compact_queue_len, compact_queue.size());
       compact_queue_lock.Unlock();
       logger->inc(l_rocksdb_compact_range);
-      compact_range(range.first, range.second);
+      if (range.first.empty() && range.second.empty()) {
+        compact();
+      } else {
+        compact_range(range.first, range.second);
+      }
       compact_queue_lock.Lock();
       continue;
     }
index 99d0941e7a41735b0bde761b3facc09ec54a6e3b..ce96199d0583cd02400f38feec6d32d6ec950f0f 100644 (file)
@@ -120,6 +120,10 @@ public:
   bool enable_rmrange;
   void compact() override;
 
+  void compact_async() override {
+    compact_range_async(string(), string());
+  }
+
   int tryInterpret(const string& key, const string& val, rocksdb::Options &opt);
   int ParseOptionsFromString(const string& opt_str, rocksdb::Options &opt);
   static int _test_init(const string& dir);
index 9c60431cb1884f27878e5484dfd5934753be5c15..2f99ef7ed6b70ddcecdc11a2706c97c621f7c722 100644 (file)
@@ -3168,7 +3168,7 @@ void Monitor::handle_command(MonOpRequestRef op)
   if (prefix == "compact" || prefix == "mon compact") {
     dout(1) << "triggering manual compaction" << dendl;
     auto start = ceph::coarse_mono_clock::now();
-    store->compact();
+    store->compact_async();
     auto end = ceph::coarse_mono_clock::now();
     double duration = std::chrono::duration<double>(end-start).count();
     dout(1) << "finished manual compaction in " << duration << " seconds" << dendl;
index f1e0efd7da879ecaf66bc49c6b735058086b08e1..43dac528636c7bd37934c5921cc1f2b1ac0ce10b 100644 (file)
@@ -688,6 +688,10 @@ class MonitorDBStore
     db->compact();
   }
 
+  void compact_async() {
+    db->compact_async();
+  }
+
   void compact_prefix(const string& prefix) {
     db->compact_prefix(prefix);
   }