diff --git a/sstables/sstable_directory.cc b/sstables/sstable_directory.cc index 5b0d1d9340..ea831b44a7 100644 --- a/sstables/sstable_directory.cc +++ b/sstables/sstable_directory.cc @@ -545,8 +545,8 @@ bool sstable_directory::compare_sstable_storage_prefix(const sstring& prefix_a, return size_a == size_b && sstring::traits_type::compare(prefix_a.begin(), prefix_b.begin(), size_a) == 0; } -future<> sstable_directory::delete_with_pending_deletion_log(std::vector ssts) { - return seastar::async([ssts = std::move(ssts)] { +future> sstable_directory::create_pending_deletion_log(const std::vector& ssts) { + return seastar::async([&ssts] { shared_sstable first = nullptr; min_max_tracker gen_tracker; @@ -601,11 +601,18 @@ future<> sstable_directory::delete_with_pending_deletion_log(std::vector(std::move(pending_delete_log), first->_storage->prefix()); + }); +} + +future<> sstable_directory::delete_with_pending_deletion_log(std::vector ssts) { + return seastar::async([ssts = std::move(ssts)] { + auto [ pending_delete_log, sst_directory] = create_pending_deletion_log(ssts).get0(); + parallel_for_each(ssts, [] (shared_sstable sst) { return sst->unlink(sstables::storage::sync_dir::no); }).get(); - - sync_directory(first->_storage->prefix()).get(); + sync_directory(sst_directory).get(); // Once all sstables are deleted, the log file can be removed. // Note: the log file will be removed also if unlink failed to remove diff --git a/sstables/sstable_directory.hh b/sstables/sstable_directory.hh index 6613c18683..18b6d1df42 100644 --- a/sstables/sstable_directory.hh +++ b/sstables/sstable_directory.hh @@ -277,6 +277,10 @@ public: // // This function only solves the second problem for now. static future<> delete_with_pending_deletion_log(std::vector ssts); + // Creates the deletion log for atomic deletion of sstables (helper for the + // above function that's also used by tests) + // Returns a pair of "logilfe name" and "directory with sstables" + static future> create_pending_deletion_log(const std::vector& ssts); static bool compare_sstable_storage_prefix(const sstring& a, const sstring& b) noexcept; };