From 631d14a92047088884055c6bb013ddb94580cc36 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Wed, 14 Feb 2024 22:50:40 -0500 Subject: [PATCH] rgw/dmclock: async_request() uses async_initiate Signed-off-by: Casey Bodley (cherry picked from commit d478d66bf38f1e9edf10fd364bbdec0b39923626) --- src/rgw/rgw_dmclock_async_scheduler.h | 61 +++++++++++++-------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/src/rgw/rgw_dmclock_async_scheduler.h b/src/rgw/rgw_dmclock_async_scheduler.h index f18318f302981..01ca0a3a80335 100644 --- a/src/rgw/rgw_dmclock_async_scheduler.h +++ b/src/rgw/rgw_dmclock_async_scheduler.h @@ -125,38 +125,35 @@ auto AsyncScheduler::async_request(const client_id& client, const Time& time, Cost cost, CompletionToken&& token) { - boost::asio::async_completion init(token); - - auto ex1 = get_executor(); - auto& handler = init.completion_handler; - - // allocate the Request and add it to the queue - auto completion = Completion::create(ex1, std::move(handler), - Request{client, time, cost}); - // cast to unique_ptr - auto req = RequestRef{std::move(completion)}; - int r = queue.add_request(std::move(req), client, params, time, cost); - if (r == 0) { - // schedule an immediate call to process() on the executor - schedule(crimson::dmclock::TimeZero); - if (auto c = counters(client)) { - c->inc(queue_counters::l_qlen); - c->inc(queue_counters::l_cost, cost); - } - } else { - // post the error code - boost::system::error_code ec(r, boost::system::system_category()); - // cast back to Completion - auto completion = static_cast(req.release()); - async::post(std::unique_ptr{completion}, - ec, PhaseType::priority); - if (auto c = counters(client)) { - c->inc(queue_counters::l_limit); - c->inc(queue_counters::l_limit_cost, cost); - } - } - - return init.result.get(); + return boost::asio::async_initiate( + [this] (auto handler, auto ex, const client_id& client, + const ReqParams& params, const Time& time, Cost cost) { + // allocate the Request and add it to the queue + auto completion = Completion::create(ex, std::move(handler), + Request{client, time, cost}); + // cast to unique_ptr + auto req = RequestRef{std::move(completion)}; + int r = queue.add_request(std::move(req), client, params, time, cost); + if (r == 0) { + // schedule an immediate call to process() on the executor + schedule(crimson::dmclock::TimeZero); + if (auto c = counters(client)) { + c->inc(queue_counters::l_qlen); + c->inc(queue_counters::l_cost, cost); + } + } else { + // post the error code + boost::system::error_code ec(r, boost::system::system_category()); + // cast back to Completion + auto completion = static_cast(req.release()); + async::post(std::unique_ptr{completion}, + ec, PhaseType::priority); + if (auto c = counters(client)) { + c->inc(queue_counters::l_limit); + c->inc(queue_counters::l_limit_cost, cost); + } + } + }, token, get_executor(), client, params, time, cost); } class SimpleThrottler : public md_config_obs_t, public dmclock::Scheduler { -- 2.39.5