From 680403d2cdf122d37a447a80700ad5bf690a68cd Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Thu, 11 Jul 2024 23:03:03 +0200 Subject: [PATCH] sstables/storage: synch "dst_dir" more leanly in create_links_common() filesystem_storage::create_links_common() runs on directories that generally differ from "_dir", thus, we can't replace its sync_directory() calls with _dir.sync(). We can still use a common (temporary) "opened_directory" object for synching "dst_dir" three times, saving two open and two close operations. This patch is best viewed with "git show -W". Signed-off-by: Laszlo Ersek --- sstables/storage.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sstables/storage.cc b/sstables/storage.cc index 8adb6a4815..0b037cb708 100644 --- a/sstables/storage.cc +++ b/sstables/storage.cc @@ -355,13 +355,14 @@ future<> filesystem_storage::create_links_common(const sstable& sst, sstring dst // TemporaryTOC is always first, TOC is always last auto dst = sstable::filename(dst_dir, sst._schema->ks_name(), sst._schema->cf_name(), sst._version, generation, sst._format, component_type::TemporaryTOC); co_await sst.sstable_write_io_check(idempotent_link_file, sst.filename(component_type::TOC), std::move(dst)); - co_await sst.sstable_write_io_check(sync_directory, dst_dir); + auto dir = opened_directory(dst_dir); + co_await dir.sync(sst._write_error_handler); co_await parallel_for_each(comps, [this, &sst, &dst_dir, generation] (auto p) { auto src = sstable::filename(_dir.native(), sst._schema->ks_name(), sst._schema->cf_name(), sst._version, sst._generation, sst._format, p.second); auto dst = sstable::filename(dst_dir, sst._schema->ks_name(), sst._schema->cf_name(), sst._version, generation, sst._format, p.second); return sst.sstable_write_io_check(idempotent_link_file, std::move(src), std::move(dst)); }); - co_await sst.sstable_write_io_check(sync_directory, dst_dir); + co_await dir.sync(sst._write_error_handler); auto dst_temp_toc = sstable::filename(dst_dir, sst._schema->ks_name(), sst._schema->cf_name(), sst._version, generation, sst._format, component_type::TemporaryTOC); if (mark_for_removal) { // Now that the source sstable is linked to new_dir, mark the source links for @@ -374,7 +375,8 @@ future<> filesystem_storage::create_links_common(const sstable& sst, sstring dst // the TemporaryTOC file at the destination. co_await sst.sstable_write_io_check(remove_file, std::move(dst_temp_toc)); } - co_await sst.sstable_write_io_check(sync_directory, dst_dir); + co_await dir.sync(sst._write_error_handler); + co_await dir.close(); sstlog.trace("create_links: {} -> {} generation={}: done", sst.get_filename(), dst_dir, generation); }