From b4ad4297652df2f6ebfadcdededc7a47607ab534 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 --- src/osd/OSD.cc | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 90b11fe484f..f233bb96556 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -42,6 +42,7 @@ #include "common/errno.h" #include "common/ceph_argparse.h" +#include "common/ceph_time.h" #include "common/version.h" #include "common/io_priority.h" @@ -159,6 +160,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) { @@ -2209,6 +2211,18 @@ bool OSD::asok_command(string admin_command, cmdmap_t& cmdmap, string format, pg->unlock(); } f->close_section(); + } else if (admin_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"); } @@ -2746,6 +2760,12 @@ void OSD::final_init() "show recent state history"); 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 @@ -3211,12 +3231,15 @@ int OSD::shutdown() cct->get_admin_socket()->unregister_command("dump_watchers"); cct->get_admin_socket()->unregister_command("dump_reservations"); cct->get_admin_socket()->unregister_command("get_latest_osdmap"); + cct->get_admin_socket()->unregister_command("heap"); cct->get_admin_socket()->unregister_command("set_heap_property"); cct->get_admin_socket()->unregister_command("get_heap_property"); cct->get_admin_socket()->unregister_command("dump_objectstore_kv_stats"); + cct->get_admin_socket()->unregister_command("dump_scrubs"); cct->get_admin_socket()->unregister_command("calc_objectstore_db_histogram"); cct->get_admin_socket()->unregister_command("flush_store_cache"); cct->get_admin_socket()->unregister_command("dump_pgstate_history"); + cct->get_admin_socket()->unregister_command("compact"); delete asok_hook; asok_hook = NULL; @@ -3228,6 +3251,8 @@ int OSD::shutdown() cct->get_admin_socket()->unregister_command("injectdataerr"); cct->get_admin_socket()->unregister_command("injectmdataerr"); cct->get_admin_socket()->unregister_command("set_recovery_delay"); + cct->get_admin_socket()->unregister_command("trigger_scrub"); + cct->get_admin_socket()->unregister_command("injectfull"); delete test_ops_hook; test_ops_hook = NULL; @@ -6193,6 +6218,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) @@ -6607,6 +6636,18 @@ void OSD::do_command(Connection *con, ceph_tid_t tid, vector& cmd, buffe } } + 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