From 58f4076117fe615e6a0d05f2e9d4feae72275615 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Mon, 13 Feb 2023 19:02:56 +0300 Subject: [PATCH] sstable_directory: Keep files_for_removal on scan_state This list is the list of on-disk files, which is the property of filesystem scan state. When committing directory changes (read: removing those files) the list can be moved-from the state. Signed-off-by: Pavel Emelyanov --- sstables/sstable_directory.cc | 9 +++++---- sstables/sstable_directory.hh | 12 ++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/sstables/sstable_directory.cc b/sstables/sstable_directory.cc index ec50f6b9c4..212c157f1e 100644 --- a/sstables/sstable_directory.cc +++ b/sstables/sstable_directory.cc @@ -77,7 +77,7 @@ sstable_directory::handle_component(components_lister::scan_state& state, sstabl // for instance on mutate_level. We should delete it - so we mark it for deletion // here, but just the component. The old statistics file should still be there // and we'll go with it. - _files_for_removal.insert(filename.native()); + state.files_for_removal.insert(filename.native()); break; case component_type::TOC: state.descriptors.emplace(desc.generation, std::move(desc)); @@ -213,7 +213,7 @@ sstable_directory::process_sstable_dir(process_flags flags) { for (auto it = range.first; it != range.second; ++it) { auto& path = it->second; dirlog.trace("Scheduling to remove file {}, from an SSTable with a Temporary TOC", path.native()); - _files_for_removal.insert(path.native()); + state.files_for_removal.insert(path.native()); } state.generations_found.erase(range.first, range.second); state.descriptors.erase(desc.generation); @@ -244,16 +244,17 @@ sstable_directory::process_sstable_dir(process_flags flags) { throw sstables::malformed_sstable_exception(format("At directory: {}: no TOC found for SSTable {}!. Refusing to boot", _sstable_dir.native(), path.native())); } else { dirlog.info("Found incomplete SSTable {} at directory {}. Removing", path.native(), _sstable_dir.native()); - _files_for_removal.insert(path.native()); + state.files_for_removal.insert(path.native()); } } } future<> sstable_directory::commit_directory_changes() { + auto files_for_removal = std::exchange(_lister->_state->files_for_removal, {}); _lister.reset(); // Remove all files scheduled for removal - return parallel_for_each(std::exchange(_files_for_removal, {}), [] (sstring path) { + return parallel_for_each(std::move(files_for_removal), [] (sstring path) { dirlog.info("Removing file {}", path); return remove_file(std::move(path)); }); diff --git a/sstables/sstable_directory.hh b/sstables/sstable_directory.hh index a108118815..d7ee2f70dd 100644 --- a/sstables/sstable_directory.hh +++ b/sstables/sstable_directory.hh @@ -74,6 +74,12 @@ public: scan_multimap generations_found; scan_descriptors temp_toc_found; scan_descriptors_map descriptors; + + // SSTable files to be deleted: things with a Temporary TOC, missing TOC files, + // TemporaryStatistics, etc. Not part of the scan state, because we want to do a 2-phase + // delete: maybe one of the shards will have signaled an error. And in the case of an error + // we don't want to delete anything. + std::unordered_set files_for_removal; }; directory_lister _lister; @@ -87,12 +93,6 @@ public: private: - // SSTable files to be deleted: things with a Temporary TOC, missing TOC files, - // TemporaryStatistics, etc. Not part of the scan state, because we want to do a 2-phase - // delete: maybe one of the shards will have signaled an error. And in the case of an error - // we don't want to delete anything. - std::unordered_set _files_for_removal; - // prevents an object that respects a phaser (usually a table) from disappearing in the middle of the operation. // Will be destroyed when this object is destroyed. std::optional _operation_barrier;