]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: new command compact via tell/daemon
authorliuchang0812 <liuchang0812@gmail.com>
Fri, 30 Jun 2017 12:56:04 +0000 (20:56 +0800)
committerVikhyat Umrao <vumrao@redhat.com>
Mon, 9 Oct 2017 14:27:06 +0000 (10:27 -0400)
user could manual compact OSD's omap as following:
1. ceph tell osd.id compact
2. ceph daemon osd.id compact
user's requests will be impacted during compaction.

Fixes: http://tracker.ceph.com/issues/19592
Signed-off-by: liuchang0812 <liuchang0812@gmail.com>
(cherry picked from commit b4ad4297652df2f6ebfadcdededc7a47607ab534)

 Conflicts:
src/osd/OSD.cc
         Removed all admin socket register and unregister commands
         which are not part of this backport
         Changed admin_command to command variable because in jewel
         we use command variable.

src/osd/OSD.cc

index 3256b4a42e7248766ec77df16b57b5f49f92dc59..bda9a9761e4166e4e9fcb50cc79ad790466d0f0e 100644 (file)
@@ -40,6 +40,7 @@
 #include "osdc/Objecter.h"
 
 #include "common/ceph_argparse.h"
+#include "common/ceph_time.h"
 #include "common/version.h"
 #include "common/io_priority.h"
 
 #undef dout_prefix
 #define dout_prefix _prefix(_dout, whoami, get_osdmap_epoch())
 
+
 const double OSD::OSD_TICK_INTERVAL = 1.0;
 
 static ostream& _prefix(std::ostream* _dout, int whoami, epoch_t epoch) {
@@ -1942,6 +1944,18 @@ bool OSD::asok_command(string command, cmdmap_t& cmdmap, string format,
     f->dump_bool("success", success);
     f->dump_int("value", value);
     f->close_section();
+  } else if (command == "compact") {
+    dout(1) << "triggering manual compaction" << dendl;
+    auto start = ceph::coarse_mono_clock::now();
+    store->compact();
+    auto end = ceph::coarse_mono_clock::now();
+    auto time_span = chrono::duration_cast<chrono::duration<double>>(end - start);
+    dout(1) << "finished manual compaction in " 
+            << time_span.count()
+            << " seconds" << dendl;
+    f->open_object_section("compact_result");
+    f->dump_float("elapsed_time", time_span.count());
+    f->close_section();
   } else {
     assert(0 == "broken asok registration");
   }
@@ -2336,6 +2350,12 @@ void OSD::final_init()
   assert(r == 0);
 
 
+  r = admin_socket->register_command("compact", "compact",
+                                    asok_hook,
+                                    "Commpact object store's omap."
+                                     " WARNING: Compaction probably slows your requests");
+  assert(r == 0);
+
   test_ops_hook = new TestOpsSocketHook(&(this->service), this->store);
   // Note: pools are CephString instead of CephPoolname because
   // these commands traditionally support both pool names and numbers
@@ -2656,6 +2676,7 @@ int OSD::shutdown()
   cct->get_admin_socket()->unregister_command("get_latest_osdmap");
   cct->get_admin_socket()->unregister_command("set_heap_property");
   cct->get_admin_socket()->unregister_command("get_heap_property");
+  cct->get_admin_socket()->unregister_command("compact");
   delete asok_hook;
   asok_hook = NULL;
 
@@ -5345,6 +5366,10 @@ COMMAND("dump_pg_recovery_stats", "dump pg recovery statistics",
        "osd", "r", "cli,rest")
 COMMAND("reset_pg_recovery_stats", "reset pg recovery statistics",
        "osd", "rw", "cli,rest")
+COMMAND("compact",
+        "compact object store's omap. "
+        "WARNING: Compaction probably slows your requests",
+        "osd", "rw", "cli,rest")
 };
 
 void OSD::do_command(Connection *con, ceph_tid_t tid, vector<string>& cmd, bufferlist& data)
@@ -5754,6 +5779,18 @@ void OSD::do_command(Connection *con, ceph_tid_t tid, vector<string>& cmd, buffe
     pg_recovery_stats.reset();
   }
 
+  else if (prefix == "compact") {
+    dout(1) << "triggering manual compaction" << dendl;
+    auto start = ceph::coarse_mono_clock::now();
+    store->compact();
+    auto end = ceph::coarse_mono_clock::now();
+    auto time_span = chrono::duration_cast<chrono::duration<double>>(end - start);
+    dout(1) << "finished manual compaction in "
+            << time_span.count()
+            << " seconds" << dendl;
+    ss << "compacted omap in " << time_span.count() << " seconds";
+  }
+
   else {
     ss << "unrecognized command! " << cmd;
     r = -EINVAL;