diff --git a/test/boost/sstable_datafile_test.cc b/test/boost/sstable_datafile_test.cc index 6b3f7b8c52..f170c6cb37 100644 --- a/test/boost/sstable_datafile_test.cc +++ b/test/boost/sstable_datafile_test.cc @@ -5678,7 +5678,7 @@ SEASTAR_TEST_CASE(sstable_run_based_compaction_test) { auto tokens = token_generation_for_current_shard(16); std::unordered_set sstables; - std::optional> observer; + std::vector> observers; sstables::sstable_run_based_compaction_strategy_for_tests cs; auto do_replace = [&] (const std::vector& old_sstables, const std::vector& new_sstables) { @@ -5701,15 +5701,20 @@ SEASTAR_TEST_CASE(sstable_run_based_compaction_test) { // check that sstable replacement follows token order BOOST_REQUIRE(*expected_sst == old_sstables.front()->generation()); expected_sst++; - // check that previously released sstable was already closed - BOOST_REQUIRE(*closed_sstables_tracker == old_sstables.front()->generation()); + // check that previously released sstables were already closed + if (old_sstables.front()->generation() % 4 == 0) { + // Due to performance reasons, sstables are not released immediately, but in batches. + // At the time of writing, mutation_reader_merger releases it's sstable references + // in batches of 4. That's why we only perform this check every 4th sstable. + BOOST_REQUIRE(*closed_sstables_tracker == old_sstables.front()->generation()); + } do_replace(old_sstables, new_sstables); - observer = old_sstables.front()->add_on_closed_handler([&] (sstable& sst) { + observers.push_back(old_sstables.front()->add_on_closed_handler([&] (sstable& sst) { testlog.info("Closing sstable of generation {}", sst.generation()); closed_sstables_tracker++; - }); + })); testlog.info("Removing sstable of generation {}, refcnt: {}", old_sstables.front()->generation(), old_sstables.front().use_count()); }; @@ -5745,7 +5750,6 @@ SEASTAR_TEST_CASE(sstable_run_based_compaction_test) { }; auto result = compact(std::move(desc.sstables), replacer); - observer.reset(); BOOST_REQUIRE_EQUAL(expected_output, result.size()); BOOST_REQUIRE(expected_sst == sstable_run.end()); return result;