From 603c667ed3d28eb489fbdd27d0861c4846339c53 Mon Sep 17 00:00:00 2001 From: liuchang0812 Date: Fri, 30 Jun 2017 20:56:04 +0800 Subject: [PATCH] osd: new command compact via tell/daemon 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 (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 | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 3256b4a42e724..bda9a9761e416 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -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" @@ -153,6 +154,7 @@ #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>(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& cmd, bufferlist& data) @@ -5754,6 +5779,18 @@ void OSD::do_command(Connection *con, ceph_tid_t tid, vector& 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>(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; -- 2.39.5