From: Kefu Chai Date: Fri, 4 Jan 2019 12:56:25 +0000 (+0800) Subject: crimson/monc: add subcription helpers X-Git-Tag: v14.1.0~356^2~15 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=07365e71b34e937aebb74e53c2ab2a4335e17c11;p=ceph.git crimson/monc: add subcription helpers Signed-off-by: Kefu Chai --- diff --git a/src/crimson/mon/MonClient.cc b/src/crimson/mon/MonClient.cc index 2d1dde9768fe..ff32b97d5536 100644 --- a/src/crimson/mon/MonClient.cc +++ b/src/crimson/mon/MonClient.cc @@ -10,6 +10,8 @@ #include "auth/AuthMethodList.h" #include "auth/RotatingKeyRing.h" +#include "common/hostname.h" + #include "crimson/auth/KeyRing.h" #include "crimson/common/config_proxy.h" #include "crimson/common/log.h" @@ -26,6 +28,7 @@ #include "messages/MMonGetVersion.h" #include "messages/MMonGetVersionReply.h" #include "messages/MMonMap.h" +#include "messages/MMonSubscribe.h" #include "messages/MMonSubscribeAck.h" namespace { @@ -543,4 +546,47 @@ Client::run_command(const std::vector& cmd, }); } +seastar::future<> Client::send_message(MessageRef m) +{ + return active_con->get_conn()->send(m); +} + +bool Client::sub_want(const std::string& what, version_t start, unsigned flags) +{ + return sub.want(what, start, flags); +} + +void Client::sub_got(const std::string& what, version_t have) +{ + sub.got(what, have); +} + +void Client::sub_unwant(const std::string& what) +{ + sub.unwant(what); +} + +bool Client::sub_want_increment(const std::string& what, + version_t start, + unsigned flags) +{ + return sub.inc_want(what, start, flags); +} + +seastar::future<> Client::renew_subs() +{ + if (!sub.have_new()) { + logger().warn("{} - empty", __func__); + return seastar::now(); + } + logger().trace("{}", __func__); + + auto m = make_message(); + m->what = sub.get_subs(); + m->hostname = ceph_get_short_hostname(); + return active_con->get_conn()->send(m).then([this] { + sub.renewed(); + }); +} + } // namespace ceph::mon diff --git a/src/crimson/mon/MonClient.h b/src/crimson/mon/MonClient.h index c47f9e4ded99..fe15b3416144 100644 --- a/src/crimson/mon/MonClient.h +++ b/src/crimson/mon/MonClient.h @@ -74,6 +74,12 @@ public: get_version_t get_version(const std::string& map); command_result_t run_command(const std::vector& cmd, const bufferlist& bl); + seastar::future<> send_message(MessageRef); + bool sub_want(const std::string& what, version_t start, unsigned flags); + void sub_got(const std::string& what, version_t have); + void sub_unwant(const std::string& what); + bool sub_want_increment(const std::string& what, version_t start, unsigned flags); + seastar::future<> renew_subs(); private: void tick();