]>
git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/mgr/client.cc
6e3d7cdd848c007970be328b8e2d5b6241499eb4
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
6 #include <seastar/core/sleep.hh>
8 #include "crimson/common/log.h"
9 #include "crimson/net/Connection.h"
10 #include "crimson/net/Messenger.h"
11 #include "messages/MMgrConfigure.h"
12 #include "messages/MMgrMap.h"
13 #include "messages/MMgrOpen.h"
16 seastar::logger
& logger()
18 return crimson::get_logger(ceph_subsys_mgrc
);
22 using crimson::common::local_conf
;
24 namespace crimson::mgr
27 Client::Client(crimson::net::Messenger
& msgr
,
28 WithStats
& with_stats
)
30 with_stats
{with_stats
},
31 report_timer
{[this] {report();}}
34 seastar::future
<> Client::start()
36 return seastar::now();
39 seastar::future
<> Client::stop()
41 logger().info("{}", __func__
);
42 report_timer
.cancel();
43 auto fut
= gate
.close();
50 std::optional
<seastar::future
<>>
51 Client::ms_dispatch(crimson::net::ConnectionRef conn
, MessageRef m
)
53 bool dispatched
= true;
54 gate
.dispatch_in_background(__func__
, *this, [this, conn
, &m
, &dispatched
] {
55 switch(m
->get_type()) {
57 return handle_mgr_map(conn
, boost::static_pointer_cast
<MMgrMap
>(m
));
58 case MSG_MGR_CONFIGURE
:
59 return handle_mgr_conf(conn
, boost::static_pointer_cast
<MMgrConfigure
>(m
));
62 return seastar::now();
65 return (dispatched
? std::make_optional(seastar::now()) : std::nullopt
);
68 void Client::ms_handle_connect(crimson::net::ConnectionRef c
)
70 gate
.dispatch_in_background(__func__
, *this, [this, c
] {
72 // ask for the mgrconfigure message
73 auto m
= crimson::make_message
<MMgrOpen
>();
74 m
->daemon_name
= local_conf()->name
.get_id();
75 return conn
->send(std::move(m
));
77 return seastar::now();
82 void Client::ms_handle_reset(crimson::net::ConnectionRef c
, bool /* is_replace */)
84 gate
.dispatch_in_background(__func__
, *this, [this, c
] {
86 report_timer
.cancel();
89 return seastar::now();
94 seastar::future
<> Client::reconnect()
100 if (!mgrmap
.get_available()) {
101 logger().warn("No active mgr available yet");
102 return seastar::now();
104 auto retry_interval
= std::chrono::duration
<double>(
105 local_conf().get_val
<double>("mgr_connect_retry_interval"));
106 auto a_while
= std::chrono::duration_cast
<seastar::steady_clock_type::duration
>(
108 return seastar::sleep(a_while
).then([this] {
109 auto peer
= mgrmap
.get_active_addrs().pick_addr(msgr
.get_myaddr().get_type());
110 if (peer
== entity_addr_t
{}) {
111 // crimson msgr only uses the first bound addr
112 logger().error("mgr.{} does not have an addr compatible with me",
113 mgrmap
.get_active_name());
116 conn
= msgr
.connect(peer
, CEPH_ENTITY_TYPE_MGR
);
120 seastar::future
<> Client::handle_mgr_map(crimson::net::ConnectionRef
,
123 mgrmap
= m
->get_map();
126 } else if (conn
->get_peer_addr() !=
127 mgrmap
.get_active_addrs().legacy_addr()) {
130 return seastar::now();
134 seastar::future
<> Client::handle_mgr_conf(crimson::net::ConnectionRef
,
135 Ref
<MMgrConfigure
> m
)
137 logger().info("{} {}", __func__
, *m
);
139 auto report_period
= std::chrono::seconds
{m
->stats_period
};
140 if (report_period
.count()) {
141 if (report_timer
.armed()) {
142 report_timer
.rearm(report_timer
.get_timeout(), report_period
);
144 report_timer
.arm_periodic(report_period
);
147 report_timer
.cancel();
149 return seastar::now();
152 void Client::report()
154 gate
.dispatch_in_background(__func__
, *this, [this] {
156 logger().warn("report: no conn available; raport skipped");
157 return seastar::now();
159 return with_stats
.get_stats(
160 ).then([this](auto &&pg_stats
) {
161 return conn
->send(std::move(pg_stats
));
166 void Client::print(std::ostream
& out
) const