From: Radoslaw Zarzynski Date: Tue, 20 Jan 2026 15:23:22 +0000 (+0000) Subject: crimson/*: rename errorator-loop.h into errorator-utils.h X-Git-Tag: v21.0.0~3^2~46 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=83a9a013a684f28ef2c21cd896ade5b3756b9b76;p=ceph.git crimson/*: rename errorator-loop.h into errorator-utils.h Signed-off-by: Radoslaw Zarzynski (cherry picked from commit 682e4ff4322a895a0bdb6c9cc0d00a516499baad) --- diff --git a/src/crimson/common/errorator-loop.h b/src/crimson/common/errorator-loop.h deleted file mode 100644 index 2af1c4ba4c0c..000000000000 --- a/src/crimson/common/errorator-loop.h +++ /dev/null @@ -1,90 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*- -// vim: ts=8 sw=2 sts=2 expandtab expandtab - -#pragma once - -#include - -#include "crimson/common/errorator.h" - - -namespace crimson { -template -class parallel_for_each_state final : private seastar::continuation_base<> { - using future_t = typename errorator::template future<>; - std::vector _incomplete; - seastar::promise<> _result; - std::exception_ptr _ex; -private: - void wait_for_one() noexcept { - while (!_incomplete.empty() && _incomplete.back().available()) { - if (_incomplete.back().failed()) { - _ex = _incomplete.back().get_exception(); - } - _incomplete.pop_back(); - } - if (!_incomplete.empty()) { - seastar::internal::set_callback(std::move(_incomplete.back()), - static_cast*>(this)); - _incomplete.pop_back(); - return; - } - if (__builtin_expect(bool(_ex), false)) { - _result.set_exception(std::move(_ex)); - } else { - _result.set_value(); - } - delete this; - } - virtual void run_and_dispose() noexcept override { - if (_state.failed()) { - _ex = std::move(_state).get_exception(); - } - _state = {}; - wait_for_one(); - } - task* waiting_task() noexcept override { return _result.waiting_task(); } -public: - parallel_for_each_state(size_t n) { - _incomplete.reserve(n); - } - void add_future(future_t&& f) { - _incomplete.push_back(std::move(f)); - } - future_t get_future() { - auto ret = _result.get_future(); - wait_for_one(); - return ret; - } -}; - -template -static inline typename errorator::template future<> -parallel_for_each(Iterator first, Iterator last, Func&& func) noexcept { - parallel_for_each_state* s = nullptr; - // Process all elements, giving each future the following treatment: - // - available, not failed: do nothing - // - available, failed: collect exception in ex - // - not available: collect in s (allocating it if needed) - for (;first != last; ++first) { - auto f = seastar::futurize_invoke(std::forward(func), *first); - if (!f.available() || f.failed()) { - if (!s) { - auto n = (seastar::internal::iterator_range_estimate_vector_capacity( - first, last) + 1); - s = new parallel_for_each_state(n); - } - s->add_future(std::move(f)); - } - } - // If any futures were not available, hand off to parallel_for_each_state::start(). - // Otherwise we can return a result immediately. - if (s) { - // s->get_future() takes ownership of s (and chains it to one of the futures it contains) - // so this isn't a leak - return s->get_future(); - } - return seastar::make_ready_future<>(); -} - -} // namespace crimson diff --git a/src/crimson/common/errorator-utils.h b/src/crimson/common/errorator-utils.h new file mode 100644 index 000000000000..2af1c4ba4c0c --- /dev/null +++ b/src/crimson/common/errorator-utils.h @@ -0,0 +1,90 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*- +// vim: ts=8 sw=2 sts=2 expandtab expandtab + +#pragma once + +#include + +#include "crimson/common/errorator.h" + + +namespace crimson { +template +class parallel_for_each_state final : private seastar::continuation_base<> { + using future_t = typename errorator::template future<>; + std::vector _incomplete; + seastar::promise<> _result; + std::exception_ptr _ex; +private: + void wait_for_one() noexcept { + while (!_incomplete.empty() && _incomplete.back().available()) { + if (_incomplete.back().failed()) { + _ex = _incomplete.back().get_exception(); + } + _incomplete.pop_back(); + } + if (!_incomplete.empty()) { + seastar::internal::set_callback(std::move(_incomplete.back()), + static_cast*>(this)); + _incomplete.pop_back(); + return; + } + if (__builtin_expect(bool(_ex), false)) { + _result.set_exception(std::move(_ex)); + } else { + _result.set_value(); + } + delete this; + } + virtual void run_and_dispose() noexcept override { + if (_state.failed()) { + _ex = std::move(_state).get_exception(); + } + _state = {}; + wait_for_one(); + } + task* waiting_task() noexcept override { return _result.waiting_task(); } +public: + parallel_for_each_state(size_t n) { + _incomplete.reserve(n); + } + void add_future(future_t&& f) { + _incomplete.push_back(std::move(f)); + } + future_t get_future() { + auto ret = _result.get_future(); + wait_for_one(); + return ret; + } +}; + +template +static inline typename errorator::template future<> +parallel_for_each(Iterator first, Iterator last, Func&& func) noexcept { + parallel_for_each_state* s = nullptr; + // Process all elements, giving each future the following treatment: + // - available, not failed: do nothing + // - available, failed: collect exception in ex + // - not available: collect in s (allocating it if needed) + for (;first != last; ++first) { + auto f = seastar::futurize_invoke(std::forward(func), *first); + if (!f.available() || f.failed()) { + if (!s) { + auto n = (seastar::internal::iterator_range_estimate_vector_capacity( + first, last) + 1); + s = new parallel_for_each_state(n); + } + s->add_future(std::move(f)); + } + } + // If any futures were not available, hand off to parallel_for_each_state::start(). + // Otherwise we can return a result immediately. + if (s) { + // s->get_future() takes ownership of s (and chains it to one of the futures it contains) + // so this isn't a leak + return s->get_future(); + } + return seastar::make_ready_future<>(); +} + +} // namespace crimson diff --git a/src/crimson/os/seastore/cache.h b/src/crimson/os/seastore/cache.h index 16c9d6173851..b465271e2461 100644 --- a/src/crimson/os/seastore/cache.h +++ b/src/crimson/os/seastore/cache.h @@ -8,7 +8,7 @@ #include "include/buffer.h" #include "crimson/common/errorator.h" -#include "crimson/common/errorator-loop.h" +#include "crimson/common/errorator-utils.h" #include "crimson/os/seastore/backref_entry.h" #include "crimson/os/seastore/cached_extent.h" #include "crimson/os/seastore/extent_placement_manager.h" diff --git a/src/crimson/os/seastore/extent_placement_manager.cc b/src/crimson/os/seastore/extent_placement_manager.cc index 47c24de5739a..838c9a18b191 100644 --- a/src/crimson/os/seastore/extent_placement_manager.cc +++ b/src/crimson/os/seastore/extent_placement_manager.cc @@ -3,7 +3,7 @@ #include "crimson/os/seastore/extent_placement_manager.h" -#include "crimson/common/errorator-loop.h" +#include "crimson/common/errorator-utils.h" #include "crimson/common/config_proxy.h" #include "crimson/os/seastore/logging.h" diff --git a/src/crimson/os/seastore/journal/circular_bounded_journal.cc b/src/crimson/os/seastore/journal/circular_bounded_journal.cc index 8e9d5ada6b41..6ebdaf9f5e10 100644 --- a/src/crimson/os/seastore/journal/circular_bounded_journal.cc +++ b/src/crimson/os/seastore/journal/circular_bounded_journal.cc @@ -3,7 +3,7 @@ #include -#include "crimson/common/errorator-loop.h" +#include "crimson/common/errorator-utils.h" #include "include/intarith.h" #include "crimson/os/seastore/async_cleaner.h" #include "crimson/os/seastore/journal/circular_bounded_journal.h" diff --git a/src/crimson/os/seastore/random_block_manager/nvme_block_device.cc b/src/crimson/os/seastore/random_block_manager/nvme_block_device.cc index 9676e711adbd..88d259b1521b 100644 --- a/src/crimson/os/seastore/random_block_manager/nvme_block_device.cc +++ b/src/crimson/os/seastore/random_block_manager/nvme_block_device.cc @@ -8,7 +8,7 @@ #include #include "crimson/common/log.h" -#include "crimson/common/errorator-loop.h" +#include "crimson/common/errorator-utils.h" #include "include/buffer.h" #include "rbm_device.h" diff --git a/src/crimson/os/seastore/random_block_manager/rbm_device.cc b/src/crimson/os/seastore/random_block_manager/rbm_device.cc index 623bc6d4cfe9..e81a959bbbd9 100644 --- a/src/crimson/os/seastore/random_block_manager/rbm_device.cc +++ b/src/crimson/os/seastore/random_block_manager/rbm_device.cc @@ -7,7 +7,7 @@ #include #include "crimson/common/log.h" -#include "crimson/common/errorator-loop.h" +#include "crimson/common/errorator-utils.h" #include "crimson/os/seastore/logging.h" #include "include/buffer.h" diff --git a/src/crimson/os/seastore/segment_manager/block.cc b/src/crimson/os/seastore/segment_manager/block.cc index 67e07dec7cce..d871026d442c 100644 --- a/src/crimson/os/seastore/segment_manager/block.cc +++ b/src/crimson/os/seastore/segment_manager/block.cc @@ -14,7 +14,7 @@ #include "include/buffer.h" #include "crimson/common/config_proxy.h" -#include "crimson/common/errorator-loop.h" +#include "crimson/common/errorator-utils.h" #include "crimson/common/coroutine.h" #include "crimson/os/seastore/logging.h" diff --git a/src/crimson/os/seastore/segment_manager/zbd.cc b/src/crimson/os/seastore/segment_manager/zbd.cc index 2a194914e165..3eef55cc2b24 100644 --- a/src/crimson/os/seastore/segment_manager/zbd.cc +++ b/src/crimson/os/seastore/segment_manager/zbd.cc @@ -9,7 +9,7 @@ #include "crimson/os/seastore/segment_manager/zbd.h" #include "crimson/common/config_proxy.h" #include "crimson/os/seastore/logging.h" -#include "crimson/common/errorator-loop.h" +#include "crimson/common/errorator-utils.h" #include "include/buffer.h" SET_SUBSYS(seastore_device); diff --git a/src/test/crimson/test_errorator.cc b/src/test/crimson/test_errorator.cc index 3d3be4ca62b6..ebbd04c0881a 100644 --- a/src/test/crimson/test_errorator.cc +++ b/src/test/crimson/test_errorator.cc @@ -7,7 +7,7 @@ #include "test/crimson/gtest_seastar.h" #include "crimson/common/errorator.h" -#include "crimson/common/errorator-loop.h" +#include "crimson/common/errorator-utils.h" #include "crimson/common/log.h" #include "seastar/core/sleep.hh" diff --git a/src/test/crimson/test_errorator_abort.cc b/src/test/crimson/test_errorator_abort.cc index 1a42cd1eefdd..b90c48f47f92 100644 --- a/src/test/crimson/test_errorator_abort.cc +++ b/src/test/crimson/test_errorator_abort.cc @@ -7,7 +7,7 @@ #include "test/crimson/gtest_seastar.h" #include "crimson/common/errorator.h" -#include "crimson/common/errorator-loop.h" +#include "crimson/common/errorator-utils.h" #include "crimson/common/log.h" #include "seastar/core/sleep.hh"