From ecb6fb00f0f399da33ea58b6f07bb9b7808cef4c Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Tue, 20 Jan 2026 21:18:01 +0200 Subject: [PATCH] streamed_mutation_freezer: use chunked_vector instead of std::deque for clustering rows The streamed_mutation_freezer class uses a deque to avoid large allocations, but fails as seen in the referenced issue when the vector backing the deque grows too large. This may be a problem in itself, but the issue doesn't provide enough information to tell. Fix the immediate problem by switching to chunked_vector, which is better in avoiding large allocations. We do lose some early-free in serialize_mutation_fragments(), but since most of the memory should be in the clustering row itself, not in the deque/chunked_vector holding it, it should not be a problem. Fixes #28275 Closes scylladb/scylladb#28281 --- mutation/frozen_mutation.cc | 2 +- mutation/frozen_mutation.hh | 2 +- mutation/mutation_partition_serializer.cc | 7 +++---- mutation/mutation_partition_serializer.hh | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/mutation/frozen_mutation.cc b/mutation/frozen_mutation.cc index 4748248794..8568698b2b 100644 --- a/mutation/frozen_mutation.cc +++ b/mutation/frozen_mutation.cc @@ -178,7 +178,7 @@ class fragmenting_mutation_freezer { tombstone _partition_tombstone; std::optional _sr; - std::deque _crs; + utils::chunked_vector _crs; range_tombstone_list _rts; frozen_mutation_consumer_fn _consumer; diff --git a/mutation/frozen_mutation.hh b/mutation/frozen_mutation.hh index ccfde9d22b..4833d2dab8 100644 --- a/mutation/frozen_mutation.hh +++ b/mutation/frozen_mutation.hh @@ -242,7 +242,7 @@ class streamed_mutation_freezer { tombstone _partition_tombstone; std::optional _sr; - std::deque _crs; + utils::chunked_vector _crs; range_tombstone_list _rts; public: streamed_mutation_freezer(const schema& s, const partition_key& key) diff --git a/mutation/mutation_partition_serializer.cc b/mutation/mutation_partition_serializer.cc index 1f60a9556a..7870e74a9d 100644 --- a/mutation/mutation_partition_serializer.cc +++ b/mutation/mutation_partition_serializer.cc @@ -226,7 +226,7 @@ future<> mutation_partition_serializer::write_gently(ser::writer_of_mutation_par void serialize_mutation_fragments(const schema& s, tombstone partition_tombstone, std::optional sr, range_tombstone_list rts, - std::deque crs, ser::writer_of_mutation_partition&& wr) + utils::chunked_vector crs, ser::writer_of_mutation_partition&& wr) { auto srow_writer = std::move(wr).write_tomb(partition_tombstone).start_static_row(); auto row_tombstones = [&] { @@ -242,10 +242,9 @@ void serialize_mutation_fragments(const schema& s, tombstone partition_tombstone rts.clear(); auto clustering_rows = std::move(row_tombstones).end_range_tombstones().start_rows(); - while (!crs.empty()) { - auto& cr = crs.front(); + for (auto& cr : crs) { write_row(clustering_rows.add(), s, cr.key(), cr.cells(), cr.marker(), cr.tomb()).end_deletable_row(); - crs.pop_front(); + cr = clustering_row(clustering_key_prefix{}); } std::move(clustering_rows).end_rows().end_mutation_partition(); } diff --git a/mutation/mutation_partition_serializer.hh b/mutation/mutation_partition_serializer.hh index 68ad0f99c5..912b64f47a 100644 --- a/mutation/mutation_partition_serializer.hh +++ b/mutation/mutation_partition_serializer.hh @@ -41,4 +41,4 @@ public: void serialize_mutation_fragments(const schema& s, tombstone partition_tombstone, std::optional sr, range_tombstone_list range_tombstones, - std::deque clustering_rows, ser::writer_of_mutation_partition&&); + utils::chunked_vector clustering_rows, ser::writer_of_mutation_partition&&);