task_manager.hh: replace boost ranges with std ranges

Standardize on one range library to reduce dependency load.

Unfortunately, std::views::concat (the replacement for boost::join),
is C++26 only. We use two separate inserts to the result vector to
compensate, and rationalize it by saying that boost::join() is likely
slow due to the need for type-erasure.

Closes scylladb/scylladb#21834
This commit is contained in:
Avi Kivity
2024-12-08 23:00:16 +02:00
committed by Botond Dénes
parent e4dc86b552
commit fe9fcdfe30
5 changed files with 17 additions and 10 deletions

View File

@@ -64,6 +64,7 @@
#include "version.hh"
#include "dht/range_streamer.hh"
#include <boost/range/algorithm.hpp>
#include <boost/range/join.hpp>
#include "transport/server.hh"
#include <seastar/core/rwlock.hh>
#include "db/batchlog_manager.hh"

View File

@@ -13,6 +13,7 @@
#include "tasks/task_handler.hh"
#include "tasks/virtual_task_hint.hh"
#include <seastar/coroutine/maybe_yield.hh>
#include <boost/range/adaptor/transformed.hpp>
namespace service {

View File

@@ -60,6 +60,8 @@
#include "service/topology_coordinator.hh"
#include <boost/range/join.hpp>
using token = dht::token;
using inet_address = gms::inet_address;

View File

@@ -27,6 +27,8 @@
#include <cfloat>
#include <algorithm>
#include <boost/range/adaptor/transformed.hpp>
static logging::logger llog("sstables_loader");
namespace {

View File

@@ -9,9 +9,7 @@
#pragma once
#include <list>
#include <boost/range/adaptor/map.hpp>
#include <boost/range/algorithm/transform.hpp>
#include <boost/range/join.hpp>
#include <ranges>
#include <seastar/core/on_internal_error.hh>
#include <seastar/core/gate.hh>
#include <seastar/core/rwlock.hh>
@@ -172,13 +170,16 @@ public:
std::function<std::optional<Res>(const task_essentials&)> map_finished_children) const {
auto shared_holder = co_await _lock.hold_read_lock();
co_return boost::join(
_children | boost::adaptors::map_values | boost::adaptors::transformed(map_children),
_finished_children | boost::adaptors::transformed(map_finished_children)
)
| std::views::filter([] (const auto& task) { return bool(task); })
| std::views::transform([] (const auto& res) { return res.value(); })
| std::ranges::to<std::vector<Res>>();
auto deopt = std::views::filter([] (const auto& task) { return bool(task); })
| std::views::transform([] (const auto& res) { return res.value(); });
auto kids = _children | std::views::values | std::views::transform(map_children) | deopt;
auto finished_kids = _finished_children | std::views::transform(map_finished_children) | deopt;
std::vector<Res> result;
// Want to use insert_range(), but libstd++ hasn't implemented it yet.
result.insert(result.end(), kids.begin(), kids.end());
result.insert(result.end(), finished_kids.begin(), finished_kids.end());
co_return result;
}
};