generic_server: use async function in for_each_gently()

In the following patch, we will add a method to update service levels
parameters for each cql connections.
To support this, this patch allows to pass async function as a parameter
to `for_each_gently()` method.
This commit is contained in:
Michał Jadwiszczak
2024-06-03 21:06:09 +02:00
parent 93e6de0d04
commit 324b3c43c0
3 changed files with 5 additions and 5 deletions

View File

@@ -40,13 +40,12 @@ connection::~connection()
_server.maybe_stop();
}
future<> server::for_each_gently(noncopyable_function<void(connection&)> fn) {
future<> server::for_each_gently(noncopyable_function<future<>(connection&)> fn) {
_gentle_iterators.emplace_front(*this);
std::list<gentle_iterator>::iterator gi = _gentle_iterators.begin();
return seastar::do_until([ gi ] { return gi->iter == gi->end; },
[ gi, fn = std::move(fn) ] {
fn(*(gi->iter++));
return make_ready_future<>();
return fn(*(gi->iter++));
}
).finally([ this, gi ] { _gentle_iterators.erase(gi); });
}

View File

@@ -119,7 +119,7 @@ protected:
virtual future<> unadvertise_connection(shared_ptr<connection> conn);
future<> for_each_gently(noncopyable_function<void(connection&)>);
future<> for_each_gently(noncopyable_function<future<>(connection&)>);
void maybe_stop();
};

View File

@@ -2022,9 +2022,10 @@ void cql_server::response::write(const cql3::prepared_metadata& m, uint8_t versi
future<utils::chunked_vector<client_data>> cql_server::get_client_data() {
utils::chunked_vector<client_data> ret;
co_await for_each_gently([&ret] (const generic_server::connection& c) {
co_await for_each_gently([&ret] (const generic_server::connection& c) -> future<> {
const connection& conn = dynamic_cast<const connection&>(c);
ret.emplace_back(conn.make_client_data());
return make_ready_future<>();
});
co_return ret;
}