@@ -247,7 +247,7 @@ ss::future<> replicate_batcher::flush(
247247 auto meta = _ptr->meta ();
248248 const auto term = model::term_id (meta.term );
249249 chunked_vector<model::record_batch> data;
250- std::vector<item_ptr> notifications;
250+ notifications_t notifications;
251251 ssx::semaphore_units item_memory_units (_max_batch_size_sem, 0 );
252252 auto force_flush_requested = false ;
253253 auto has_quorum_ack_requests = false ;
@@ -266,9 +266,16 @@ ss::future<> replicate_batcher::flush(
266266 has_quorum_ack_requests
267267 = has_quorum_ack_requests
268268 || (n->get_consistency_level () == consistency_level::quorum_ack);
269- for (auto & b : batches) {
270- b.set_term (term);
271- data.push_back (std::move (b));
269+ if (data.empty ()) {
270+ data = std::move (batches);
271+ for (auto & b : data) {
272+ b.set_term (term);
273+ }
274+ } else {
275+ for (auto & b : batches) {
276+ b.set_term (term);
277+ data.push_back (std::move (b));
278+ }
272279 }
273280 notifications.push_back (std::move (n));
274281 } else {
@@ -323,7 +330,7 @@ ss::future<> replicate_batcher::flush(
323330template <typename Predicate>
324331static void propagate_result (
325332 result<replicate_result> r,
326- std::vector< replicate_batcher::item_ptr> & notifications,
333+ replicate_batcher::notifications_t & notifications,
327334 const Predicate& pred) {
328335 if (r.has_error ()) {
329336 // propagate an error
@@ -344,8 +351,8 @@ static void propagate_result(
344351 }
345352}
346353
347- static void propagate_current_exception (
348- std::vector< replicate_batcher::item_ptr> & notifications) {
354+ static void
355+ propagate_current_exception ( replicate_batcher::notifications_t & notifications) {
349356 // iterate backward to calculate last offsets
350357 auto e = std::current_exception ();
351358 for (auto & n : notifications) {
@@ -354,7 +361,7 @@ static void propagate_current_exception(
354361}
355362
356363ss::future<> replicate_batcher::do_flush (
357- std::vector< replicate_batcher::item_ptr> notifications,
364+ replicate_batcher::notifications_t notifications,
358365 append_entries_request req,
359366 std::vector<ssx::semaphore_units> u,
360367 absl::flat_hash_map<vnode, follower_req_seq> seqs) {
0 commit comments