From 58cce757a924c5c94b9a1987762ef64e3d14d3fd Mon Sep 17 00:00:00 2001 From: Ronen Friedman Date: Thu, 4 Jul 2024 10:37:09 -0500 Subject: [PATCH] osd/scrub: making osd_scrub_sched.cc compatible with Clang-14 Removing the use of C++ ranges, as Clang versions below 16 are buggy when libstd++ ranges are used. Signed-off-by: Ronen Friedman --- src/osd/scrubber/osd_scrub_sched.cc | 34 +++++++++++++++++------------ 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/osd/scrubber/osd_scrub_sched.cc b/src/osd/scrubber/osd_scrub_sched.cc index f94680a416d..5f6ebc0c2f7 100644 --- a/src/osd/scrubber/osd_scrub_sched.cc +++ b/src/osd/scrubber/osd_scrub_sched.cc @@ -88,17 +88,19 @@ std::unique_ptr ScrubQueue::pop_ready_pg( jb->schedule.deadline <= time_now)))); }; - auto not_ripes = rng::partition(to_scrub, eligible_filtr); - if (not_ripes.begin() == to_scrub.begin()) { + auto not_ripes = + std::partition(to_scrub.begin(), to_scrub.end(), eligible_filtr); + if (not_ripes == to_scrub.begin()) { return nullptr; } - auto top = rng::min_element( - to_scrub.begin(), not_ripes.begin(), rng::less(), - [](const std::unique_ptr& jb) -> utime_t { - return jb->get_sched_time(); + auto top = std::min_element( + to_scrub.begin(), not_ripes, + [](const std::unique_ptr& lhs, + const std::unique_ptr& rhs) -> bool { + return lhs->get_sched_time() < rhs->get_sched_time(); }); - if (top == not_ripes.begin()) { + if (top == not_ripes) { return nullptr; } @@ -129,21 +131,25 @@ std::set ScrubQueue::get_pgs(const ScrubQueue::EntryPred& cond) const { std::lock_guard lck{jobs_lock}; std::set pgs_w_matching_entries; - rng::transform( - to_scrub | std::views::filter( - [&cond](const auto& job) -> bool { return (cond)(*job); }), - std::inserter(pgs_w_matching_entries, pgs_w_matching_entries.end()), - [](const auto& job) { return job->pgid; }); + for (const auto& job : to_scrub) { + if (cond(*job)) { + pgs_w_matching_entries.insert(job->pgid); + } + } return pgs_w_matching_entries; } + void ScrubQueue::for_each_job( std::function fn, int max_jobs) const { std::lock_guard lck(jobs_lock); - std::ranges::for_each( - to_scrub | std::views::take(max_jobs), + // implementation note: not using 'for_each_n()', as it is UB + // if there aren't enough elements + std::for_each( + to_scrub.begin(), + to_scrub.begin() + std::min(max_jobs, static_cast(to_scrub.size())), [fn](const auto& job) { fn(*job); }); } -- 2.39.5