crimson/mgr: reconnect in ms_handle_reset()

since `reconnect()` does not wait for `conn->close()` anymore, we
can actually call `reconnect()` right in `ms_handle_reset()`.

also, to avoid connecting mgr too frequently, connect the mgr with
specified interval (1 second by default).

send the MMgrOpen message in `ms_handle_connect()` to make it explicit
that we sends this message when the connection is established.

Signed-off-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2020-03-10 18:42:38 +08:00
parent 74001778ef
commit 9318c18218
2 changed files with 29 additions and 15 deletions

View File

@ -58,13 +58,26 @@ seastar::future<> Client::ms_dispatch(crimson::net::Connection* conn,
} }
} }
seastar::future<> Client::ms_handle_connect(crimson::net::ConnectionRef c)
{
if (conn == c) {
// ask for the mgrconfigure message
auto m = ceph::make_message<MMgrOpen>();
m->daemon_name = local_conf()->name.get_id();
return conn->send(std::move(m));
} else {
return seastar::now();
}
}
seastar::future<> Client::ms_handle_reset(crimson::net::ConnectionRef c) seastar::future<> Client::ms_handle_reset(crimson::net::ConnectionRef c)
{ {
if (conn == c) { if (conn == c) {
conn = nullptr;
report_timer.cancel(); report_timer.cancel();
return reconnect();
} else {
return seastar::now();
} }
return seastar::now();
} }
seastar::future<> Client::reconnect() seastar::future<> Client::reconnect()
@ -72,17 +85,20 @@ seastar::future<> Client::reconnect()
if (conn) { if (conn) {
// crimson::net::Protocol::close() is able to close() in background // crimson::net::Protocol::close() is able to close() in background
(void)conn->close(); (void)conn->close();
conn = {};
} }
if (!mgrmap.get_available()) { if (!mgrmap.get_available()) {
logger().warn("No active mgr available yet"); logger().warn("No active mgr available yet");
return seastar::now(); return seastar::now();
} }
auto peer = mgrmap.get_active_addrs().front(); auto retry_interval = std::chrono::duration<double>(
conn = msgr.connect(peer, CEPH_ENTITY_TYPE_MGR); local_conf().get_val<double>("mgr_connect_retry_interval"));
// ask for the mgrconfigure message auto a_while = std::chrono::duration_cast<seastar::steady_clock_type::duration>(
auto m = ceph::make_message<MMgrOpen>(); retry_interval);
m->daemon_name = local_conf()->name.get_id(); return seastar::sleep(a_while).then([this] {
return conn->send(std::move(m)); auto peer = mgrmap.get_active_addrs().front();
conn = msgr.connect(peer, CEPH_ENTITY_TYPE_MGR);
});
} }
seastar::future<> Client::handle_mgr_map(crimson::net::Connection*, seastar::future<> Client::handle_mgr_map(crimson::net::Connection*,
@ -120,12 +136,9 @@ seastar::future<> Client::handle_mgr_conf(crimson::net::Connection* conn,
void Client::report() void Client::report()
{ {
(void) seastar::with_gate(gate, [this] { (void) seastar::with_gate(gate, [this] {
if (conn) { assert(conn);
auto pg_stats = with_stats.get_stats(); auto pg_stats = with_stats.get_stats();
return conn->send(std::move(pg_stats)); return conn->send(std::move(pg_stats));
} else {
return reconnect();
}
}); });
} }

View File

@ -39,7 +39,8 @@ public:
private: private:
seastar::future<> ms_dispatch(crimson::net::Connection* conn, seastar::future<> ms_dispatch(crimson::net::Connection* conn,
Ref<Message> m) override; Ref<Message> m) override;
seastar::future<> ms_handle_reset(crimson::net::ConnectionRef conn) override; seastar::future<> ms_handle_reset(crimson::net::ConnectionRef conn) final;
seastar::future<> ms_handle_connect(crimson::net::ConnectionRef conn) final;
seastar::future<> handle_mgr_map(crimson::net::Connection* conn, seastar::future<> handle_mgr_map(crimson::net::Connection* conn,
Ref<MMgrMap> m); Ref<MMgrMap> m);
seastar::future<> handle_mgr_conf(crimson::net::Connection* conn, seastar::future<> handle_mgr_conf(crimson::net::Connection* conn,