From e57ee84662c8aae8dfb30505eb9b886fce2ce563 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Tue, 13 Jan 2026 13:35:10 +0300 Subject: [PATCH] util: Re-use seastar::util::memory_data_sink A data_sink that stores buffers into an in-memory collection had appeared in seastar recently. In Scylla there's similar thing that uses memory_data_sink_buffer as a container, so it's possible to drop the data_sink_impl iself in favor of seastar implementation. For that to work there should be append_buffers() overload for the aforementioned container. For its nice implementation the container, in turn, needs to get push_back() method and value_type trait. The method already exists, but is called put(), so just rename it. There's one more user of it this method in S3 client, and it can enjoy the added append_buffers() helper. Signed-off-by: Pavel Emelyanov Closes scylladb/scylladb#28124 --- utils/memory_data_sink.hh | 30 +++++++++--------------------- utils/s3/client.cc | 4 +--- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/utils/memory_data_sink.hh b/utils/memory_data_sink.hh index f8ef4f7a0e..f0a7f18291 100644 --- a/utils/memory_data_sink.hh +++ b/utils/memory_data_sink.hh @@ -8,6 +8,7 @@ #include #include +#include #include "utils/small_vector.hh" #include "seastarx.hh" @@ -21,12 +22,14 @@ class memory_data_sink_buffers { buffers_type _bufs; size_t _size = 0; public: + using value_type = temporary_buffer; // for std::back_inserter to work + size_t size() const { return _size; } buffers_type& buffers() { return _bufs; } const buffers_type& buffers() const { return _bufs; } // Strong exception guarantees - void put(temporary_buffer&& buf) { + void push_back(temporary_buffer&& buf) { auto size = buf.size(); _bufs.emplace_back(std::move(buf)); _size += size; @@ -46,23 +49,8 @@ public: } }; -class memory_data_sink : public data_sink_impl { - memory_data_sink_buffers& _bufs; -public: - memory_data_sink(memory_data_sink_buffers& b) : _bufs(b) {} - virtual future<> put(std::span> bufs) override { - for (auto&& buf : bufs) { - _bufs.put(std::move(buf)); - } - return make_ready_future<>(); - } - virtual future<> flush() override { - return make_ready_future<>(); - } - virtual future<> close() override { - return make_ready_future<>(); - } - size_t buffer_size() const noexcept override { - return 128*1024; - } -}; +inline void append_buffers(memory_data_sink_buffers& c, std::span> bufs) { + std::ranges::move(bufs, std::back_inserter(c)); +} + +using memory_data_sink = seastar::util::basic_memory_data_sink; diff --git a/utils/s3/client.cc b/utils/s3/client.cc index d60f223cc0..53b80fc45f 100644 --- a/utils/s3/client.cc +++ b/utils/s3/client.cc @@ -1026,9 +1026,7 @@ public: {} virtual future<> put(std::span> data) override { - for (auto&& buf : data) { - _bufs.put(std::move(buf)); - } + append_buffers(_bufs, std::move(data)); return maybe_flush(); }