From 0ea3cc8f6abb9c1408a8c05fd3b26b2d7558258c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rados=C5=82aw=20Zarzy=C5=84ski?= Date: Wed, 27 Apr 2022 15:51:33 +0200 Subject: [PATCH] crimson/osd: migrate OperationThrottler to new tracking infra. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Radosław Zarzyński --- src/crimson/osd/osd_operation.cc | 4 +-- src/crimson/osd/osd_operation.h | 32 +++++++++++-------- .../osd/osd_operations/background_recovery.cc | 30 +++++++++-------- .../osd/osd_operations/background_recovery.h | 3 ++ 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/crimson/osd/osd_operation.cc b/src/crimson/osd/osd_operation.cc index 90370d57b816f..f3a0964700d23 100644 --- a/src/crimson/osd/osd_operation.cc +++ b/src/crimson/osd/osd_operation.cc @@ -50,13 +50,13 @@ void OperationThrottler::release_throttle() wake(); } -blocking_future<> OperationThrottler::acquire_throttle( +seastar::future<> OperationThrottler::acquire_throttle( crimson::osd::scheduler::params_t params) { crimson::osd::scheduler::item_t item{params, seastar::promise<>()}; auto fut = item.wake.get_future(); scheduler->enqueue(std::move(item)); - return make_blocking_future(std::move(fut)); + return fut; } void OperationThrottler::dump_detail(Formatter *f) const diff --git a/src/crimson/osd/osd_operation.h b/src/crimson/osd/osd_operation.h index f3e4f6386d0d3..054d6e3742403 100644 --- a/src/crimson/osd/osd_operation.h +++ b/src/crimson/osd/osd_operation.h @@ -224,12 +224,7 @@ class OperationThrottler : public BlockerT, crimson::osd::scheduler::params_t params, F &&f) { if (!max_in_progress) return f(); - auto fut = acquire_throttle(params); - // At any given moment a particular op can be blocked by a given - // OperationThrottler instance no more than once. This means the - // same throtter won't be on the op's blockers list more than one - // time. - return op->with_blocking_future(std::move(fut)) + return acquire_throttle(params) .then(std::forward(f)) .then([this](auto x) { release_throttle(); @@ -237,6 +232,17 @@ class OperationThrottler : public BlockerT, }); } + template + seastar::future<> with_throttle_while( + OperationT* op, + crimson::osd::scheduler::params_t params, + F &&f) { + return with_throttle(op, params, f).then([this, params, op, f](bool cont) { + return cont ? with_throttle_while(op, params, f) : seastar::now(); + }); + } + + public: OperationThrottler(ConfigProxy &conf); @@ -245,14 +251,12 @@ public: const std::set &changed) final; void update_from_config(const ConfigProxy &conf); - template + template seastar::future<> with_throttle_while( - OperationT* op, - crimson::osd::scheduler::params_t params, - F &&f) { - return with_throttle(op, params, f).then([this, params, op, f](bool cont) { - return cont ? with_throttle_while(op, params, f) : seastar::now(); - }); + BlockingEvent::Trigger&& trigger, + Args&&... args) { + return trigger.maybe_record_blocking( + with_throttle_while(std::forward(args)...), *this); } private: @@ -267,7 +271,7 @@ private: void wake(); - blocking_future<> acquire_throttle( + seastar::future<> acquire_throttle( crimson::osd::scheduler::params_t params); void release_throttle(); diff --git a/src/crimson/osd/osd_operations/background_recovery.cc b/src/crimson/osd/osd_operations/background_recovery.cc index 0c40e2705340a..6e8319e92a5b6 100644 --- a/src/crimson/osd/osd_operations/background_recovery.cc +++ b/src/crimson/osd/osd_operations/background_recovery.cc @@ -79,19 +79,23 @@ seastar::future<> BackgroundRecoveryT::start() std::chrono::milliseconds(std::lround(delay * 1000))); } return maybe_delay.then([ref, this] { - return ss.throttler.with_throttle_while( - this, get_scheduler_params(), [this] { - return T::interruptor::with_interruption([this] { - return do_recovery(); - }, [](std::exception_ptr) { - return seastar::make_ready_future(false); - }, pg); - }).handle_exception_type([ref, this](const std::system_error& err) { - if (err.code() == std::make_error_code(std::errc::interrupted)) { - logger().debug("{} recovery interruped: {}", *pg, err.what()); - return seastar::now(); - } - return seastar::make_exception_future<>(err); + return this->template with_blocking_event( + [ref, this] (auto&& trigger) { + return ss.throttler.with_throttle_while( + std::move(trigger), + this, get_scheduler_params(), [this] { + return T::interruptor::with_interruption([this] { + return do_recovery(); + }, [](std::exception_ptr) { + return seastar::make_ready_future(false); + }, pg); + }).handle_exception_type([ref, this](const std::system_error& err) { + if (err.code() == std::make_error_code(std::errc::interrupted)) { + logger().debug("{} recovery interruped: {}", *pg, err.what()); + return seastar::now(); + } + return seastar::make_exception_future<>(err); + }); }); }); } diff --git a/src/crimson/osd/osd_operations/background_recovery.h b/src/crimson/osd/osd_operations/background_recovery.h index 1f293e12ba74d..1e5ffb29d0f30 100644 --- a/src/crimson/osd/osd_operations/background_recovery.h +++ b/src/crimson/osd/osd_operations/background_recovery.h @@ -65,6 +65,7 @@ public: void print(std::ostream&) const final; std::tuple< + OperationThrottler::BlockingEvent, RecoveryBackend::RecoveryBlockingEvent > tracking_events; @@ -84,6 +85,7 @@ public: float delay = 0); std::tuple< + OperationThrottler::BlockingEvent, RecoveryBackend::RecoveryBlockingEvent > tracking_events; @@ -114,6 +116,7 @@ public: static BackfillRecoveryPipeline &bp(PG &pg); std::tuple< + OperationThrottler::BlockingEvent, BackfillRecoveryPipeline::Process::BlockingEvent > tracking_events; -- 2.39.5