From f60ff44fdfa61481e3da2da91e68bbc5afa2f97f Mon Sep 17 00:00:00 2001 From: Benny Halevy Date: Mon, 18 Jul 2022 14:38:25 +0300 Subject: [PATCH] table: try_flush_memtable_to_sstable: consume: close reader on error If an exception is throws in `consume` before write_memtable_to_sstable is called or if the latter fails, we must close the reader passed to it. Fixes #11075 Signed-off-by: Benny Halevy --- replica/table.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/replica/table.cc b/replica/table.cc index 63b66a4807..0f0bc66561 100644 --- a/replica/table.cc +++ b/replica/table.cc @@ -654,6 +654,8 @@ table::try_flush_memtable_to_sstable(lw_shared_ptr old, sstable_write_ auto estimated_partitions = _compaction_strategy.adjust_partition_estimate(metadata, old->partition_count()); auto consumer = _compaction_strategy.make_interposer_consumer(metadata, [this, old, permit, &newtabs, metadata, estimated_partitions] (flat_mutation_reader_v2 reader) mutable -> future<> { + std::exception_ptr ex; + try { auto&& priority = service::get_local_memtable_flush_priority(); sstables::sstable_writer_config cfg = get_sstables_manager().configure_writer("memtable"); cfg.backup = incremental_backups_enabled(); @@ -666,6 +668,11 @@ table::try_flush_memtable_to_sstable(lw_shared_ptr old, sstable_write_ old->get_max_timestamp()); co_return co_await write_memtable_to_sstable(std::move(reader), *old, newtab, estimated_partitions, monitor, cfg, priority); + } catch (...) { + ex = std::current_exception(); + } + co_await reader.close(); + co_await coroutine::return_exception_ptr(std::move(ex)); }); auto reader = old->make_flush_reader(