diff --git a/readers/multishard.cc b/readers/multishard.cc index 4c65b71e014a..3abfecc6318b 100644 --- a/readers/multishard.cc +++ b/readers/multishard.cc @@ -607,7 +607,7 @@ future<> evictable_reader_v2::fill_buffer() { // First make sure we've made progress w.r.t. _next_position_in_partition. // This loop becomes inifinite when next pos is a partition start. // In that case progress is guranteed anyway, so skip this loop entirely. - while (!_next_position_in_partition.is_partition_start() && next_mf && _tri_cmp(_next_position_in_partition, buffer().back().position()) <= 0) { + while (!_next_position_in_partition.is_partition_start() && next_mf && _tri_cmp(buffer().back().position(), _next_position_in_partition) <= 0) { push_mutation_fragment(_reader->pop_mutation_fragment()); next_mf = co_await _reader->peek(); } diff --git a/test/boost/mutation_reader_test.cc b/test/boost/mutation_reader_test.cc index 1773392d814d..be9b7cb736b8 100644 --- a/test/boost/mutation_reader_test.cc +++ b/test/boost/mutation_reader_test.cc @@ -3648,9 +3648,13 @@ SEASTAR_THREAD_TEST_CASE(test_evictable_reader_next_pos_is_partition_start) { auto stop_rd = deferred_close(rd); rd.set_max_buffer_size(max_buf_size); + // #13491 - the reader must not consume the entire partition but a small batch of fragments based on the buffer size. + rd.fill_buffer().get(); rd.fill_buffer().get(); auto buf1 = rd.detach_buffer(); - BOOST_REQUIRE_EQUAL(buf1.size(), 3); + // There should be 6-7 fragments, but to avoid computing the exact number of fragments that should fit in `max_buf_size`, + // just ensure that there are <= 10 (consuming the whole partition would give ~1000 fragments). + BOOST_REQUIRE_LE(buf1.size(), 10); } struct mutation_bounds {