Skip to content

Commit 6e23a1e

Browse files
committed
crimson/mgr/client: partial move to coroutines
Avoid moving capturing lambdas to coroutines. Specifically lambdas which are passed to dispatch_in_background. See: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rcoro-capture Signed-off-by: Matan Breizman <[email protected]>
1 parent b5f7200 commit 6e23a1e

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

src/crimson/mgr/client.cc

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "crimson/common/log.h"
99
#include "crimson/net/Connection.h"
1010
#include "crimson/net/Messenger.h"
11+
#include "crimson/common/coroutine.h"
1112
#include "messages/MMgrConfigure.h"
1213
#include "messages/MMgrMap.h"
1314
#include "messages/MMgrOpen.h"
@@ -35,20 +36,19 @@ seastar::future<> Client::start()
3536
{
3637
LOG_PREFIX(Client::start);
3738
DEBUGDPP("", *this);
38-
return seastar::now();
39+
co_return;
3940
}
4041

4142
seastar::future<> Client::stop()
4243
{
4344
LOG_PREFIX(Client::stop);
4445
DEBUGDPP("", *this);
4546
report_timer.cancel();
46-
auto fut = gates.close_all();
4747
if (conn) {
4848
DEBUGDPP("marking down", *this);
4949
conn->mark_down();
5050
}
51-
return fut;
51+
co_await gates.close_all();
5252
}
5353

5454
std::optional<seastar::future<>>
@@ -124,24 +124,24 @@ seastar::future<> Client::reconnect()
124124
}
125125
if (!mgrmap.get_available()) {
126126
WARNDPP("No active mgr available yet", *this);
127-
return seastar::now();
127+
co_return;
128128
}
129129
auto retry_interval = std::chrono::duration<double>(
130130
local_conf().get_val<double>("mgr_connect_retry_interval"));
131131
auto a_while = std::chrono::duration_cast<seastar::steady_clock_type::duration>(
132132
retry_interval);
133133
DEBUGDPP("reconnecting in {} seconds", *this, retry_interval);
134-
return seastar::sleep(a_while).then([this, FNAME] {
135-
auto peer = mgrmap.get_active_addrs().pick_addr(msgr.get_myaddr().get_type());
136-
if (peer == entity_addr_t{}) {
137-
// crimson msgr only uses the first bound addr
138-
ERRORDPP("mgr.{} does not have an addr compatible with me",
139-
*this, mgrmap.get_active_name());
140-
return;
141-
}
142-
conn = msgr.connect(peer, CEPH_ENTITY_TYPE_MGR);
143-
DEBUGDPP("reconnected successfully", *this);
144-
});
134+
co_await seastar::sleep(a_while);
135+
136+
auto peer = mgrmap.get_active_addrs().pick_addr(msgr.get_myaddr().get_type());
137+
if (peer == entity_addr_t{}) {
138+
// crimson msgr only uses the first bound addr
139+
ERRORDPP("mgr.{} does not have an addr compatible with me",
140+
*this, mgrmap.get_active_name());
141+
co_return;
142+
}
143+
conn = msgr.connect(peer, CEPH_ENTITY_TYPE_MGR);
144+
DEBUGDPP("reconnected successfully", *this);
145145
}
146146

147147
seastar::future<> Client::handle_mgr_map(crimson::net::ConnectionRef,
@@ -150,13 +150,9 @@ seastar::future<> Client::handle_mgr_map(crimson::net::ConnectionRef,
150150
LOG_PREFIX(Client::handle_mgr_map);
151151
DEBUGDPP("", *this);
152152
mgrmap = m->get_map();
153-
if (!conn) {
154-
return reconnect();
155-
} else if (conn->get_peer_addr() !=
156-
mgrmap.get_active_addrs().legacy_addr()) {
157-
return reconnect();
158-
} else {
159-
return seastar::now();
153+
if (!conn || conn->get_peer_addr() !=
154+
mgrmap.get_active_addrs().legacy_addr()) {
155+
co_await reconnect();
160156
}
161157
}
162158

@@ -178,9 +174,8 @@ seastar::future<> Client::handle_mgr_conf(crimson::net::ConnectionRef,
178174
}
179175
if (!m->osd_perf_metric_queries.empty()) {
180176
ceph_assert(set_perf_queries_cb);
181-
return set_perf_queries_cb(m->osd_perf_metric_queries);
177+
co_await set_perf_queries_cb(m->osd_perf_metric_queries);
182178
}
183-
return seastar::now();
184179
}
185180

186181
void Client::report()

0 commit comments

Comments
 (0)