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)
{
if (conn == c) {
conn = nullptr;
report_timer.cancel();
return reconnect();
} else {
return seastar::now();
}
return seastar::now();
}
seastar::future<> Client::reconnect()
@ -72,17 +85,20 @@ seastar::future<> Client::reconnect()
if (conn) {
// crimson::net::Protocol::close() is able to close() in background
(void)conn->close();
conn = {};
}
if (!mgrmap.get_available()) {
logger().warn("No active mgr available yet");
return seastar::now();
}
auto peer = mgrmap.get_active_addrs().front();
conn = msgr.connect(peer, CEPH_ENTITY_TYPE_MGR);
// 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));
auto retry_interval = std::chrono::duration<double>(
local_conf().get_val<double>("mgr_connect_retry_interval"));
auto a_while = std::chrono::duration_cast<seastar::steady_clock_type::duration>(
retry_interval);
return seastar::sleep(a_while).then([this] {
auto peer = mgrmap.get_active_addrs().front();
conn = msgr.connect(peer, CEPH_ENTITY_TYPE_MGR);
});
}
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) seastar::with_gate(gate, [this] {
if (conn) {
auto pg_stats = with_stats.get_stats();
return conn->send(std::move(pg_stats));
} else {
return reconnect();
}
assert(conn);
auto pg_stats = with_stats.get_stats();
return conn->send(std::move(pg_stats));
});
}

View File

@ -39,7 +39,8 @@ public:
private:
seastar::future<> ms_dispatch(crimson::net::Connection* conn,
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,
Ref<MMgrMap> m);
seastar::future<> handle_mgr_conf(crimson::net::Connection* conn,