From 5bbbbc66ce70b7dc0424467f08af92c8fc18529b Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 3 Jul 2020 16:05:56 +0800 Subject: [PATCH] crimson/osd: implement flush_pg_stats command this command is used by teuthology based tests for updating the mgr with the lastes pg stats on OSD. Signed-off-by: Kefu Chai --- src/crimson/admin/osd_admin.cc | 26 ++++++++++++++++++++++++++ src/crimson/admin/osd_admin.h | 7 ++++--- src/crimson/mgr/client.h | 3 ++- src/crimson/osd/osd.cc | 10 +++++++++- src/crimson/osd/osd.h | 4 ++++ 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/crimson/admin/osd_admin.cc b/src/crimson/admin/osd_admin.cc index a8e0a475363..4675d8d2230 100644 --- a/src/crimson/admin/osd_admin.cc +++ b/src/crimson/admin/osd_admin.cc @@ -178,6 +178,32 @@ public: }; template std::unique_ptr make_asok_hook(); +/** + * send the latest pg stats to mgr + */ +class FlushPgStatsHook : public AdminSocketHook { +public: + explicit FlushPgStatsHook(crimson::osd::OSD& osd) : + AdminSocketHook("flush_pg_stats", + "flush_pg_stats", + "flush pg stats"), + osd{osd} + {} + seastar::future call(const cmdmap_t&, + std::string_view format, + ceph::bufferlist&& input) const final + { + uint64_t seq = osd.send_pg_stats(); + unique_ptr f{Formatter::create(format, "json-pretty", "json-pretty")}; + f->dump_unsigned("stat_seq", seq); + return seastar::make_ready_future(tell_result_t(f.get())); + } + +private: + crimson::osd::OSD& osd; +}; +template std::unique_ptr make_asok_hook(crimson::osd::OSD& osd); + /** * A CephContext admin hook: calling assert (if allowed by * 'debug_asok_assert_abort') diff --git a/src/crimson/admin/osd_admin.h b/src/crimson/admin/osd_admin.h index 2fd82fddb5e..6a0b8b230ba 100644 --- a/src/crimson/admin/osd_admin.h +++ b/src/crimson/admin/osd_admin.h @@ -8,12 +8,13 @@ namespace crimson::admin { -class OsdStatusHook; -class SendBeaconHook; +class AssertAlwaysHook; class ConfigShowHook; class ConfigGetHook; class ConfigSetHook; -class AssertAlwaysHook; +class FlushPgStatsHook; +class OsdStatusHook; +class SendBeaconHook; template std::unique_ptr make_asok_hook(Args&&... args); diff --git a/src/crimson/mgr/client.h b/src/crimson/mgr/client.h index 919fdeb6080..742cf0c0026 100644 --- a/src/crimson/mgr/client.h +++ b/src/crimson/mgr/client.h @@ -35,6 +35,8 @@ public: WithStats& with_stats); seastar::future<> start(); seastar::future<> stop(); + void report(); + private: seastar::future<> ms_dispatch(crimson::net::Connection* conn, Ref m) override; @@ -45,7 +47,6 @@ private: seastar::future<> handle_mgr_conf(crimson::net::Connection* conn, Ref m); seastar::future<> reconnect(); - void report(); void print(std::ostream&) const; friend std::ostream& operator<<(std::ostream& out, const Client& client); diff --git a/src/crimson/osd/osd.cc b/src/crimson/osd/osd.cc index 0744d98d5ea..4c72ccd5892 100644 --- a/src/crimson/osd/osd.cc +++ b/src/crimson/osd/osd.cc @@ -451,7 +451,8 @@ seastar::future<> OSD::start_asok_admin() asok->register_command(make_asok_hook(*this)), asok->register_command(make_asok_hook()), asok->register_command(make_asok_hook()), - asok->register_command(make_asok_hook())); + asok->register_command(make_asok_hook()), + asok->register_command(make_asok_hook(*this))); }); } @@ -708,6 +709,13 @@ MessageRef OSD::get_stats() const return m; } +uint64_t OSD::send_pg_stats() +{ + // mgr client sends the report message in background + mgrc->report(); + return osd_stat_seq; +} + OSD::cached_map_t OSD::get_map() const { return osdmap; diff --git a/src/crimson/osd/osd.h b/src/crimson/osd/osd.h index 0e8723ab8dd..afee53d69de 100644 --- a/src/crimson/osd/osd.h +++ b/src/crimson/osd/osd.h @@ -139,6 +139,10 @@ public: seastar::future<> send_incremental_map(crimson::net::Connection* conn, epoch_t first); + + /// @return the seq id of the pg stats being sent + uint64_t send_pg_stats(); + private: seastar::future<> start_boot(); seastar::future<> _preboot(version_t oldest_osdmap, version_t newest_osdmap); -- 2.39.5