From 2fced3c55797ee7c9e9eab2f4dcd50f5fad27d02 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 17 Apr 2024 15:50:45 +0300 Subject: [PATCH] table: Use directory_semaphore for rate-limited snapshot taking The table::take_snapshot() limits its parallelizm with the help of direcoty semaphore already, but implements it "by hand". There's already parallel_for_each() method on the dir.sem. class that does exactly that. Signed-off-by: Pavel Emelyanov --- replica/table.cc | 4 +--- sstables/sstable_directory.hh | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/replica/table.cc b/replica/table.cc index 8daae7b9c9..91346c74f0 100644 --- a/replica/table.cc +++ b/replica/table.cc @@ -2305,13 +2305,11 @@ future table::take_snapshot(database& db, sstring json auto table_names = std::make_unique>(); co_await io_check([&jsondir] { return recursive_touch_directory(jsondir); }); - co_await max_concurrent_for_each(tables, db.get_sharded_sst_dir_semaphore().local()._concurrency, [&db, &jsondir, &table_names] (sstables::shared_sstable sstable) { + co_await db.get_sharded_sst_dir_semaphore().local().parallel_for_each(tables, [&jsondir, &table_names] (sstables::shared_sstable sstable) { table_names->insert(sstable->component_basename(sstables::component_type::Data)); - return with_semaphore(db.get_sharded_sst_dir_semaphore().local()._sem, 1, [&jsondir, sstable] { return io_check([sstable, &dir = jsondir] { return sstable->snapshot(dir); }); - }); }); co_await io_check(sync_directory, jsondir); co_return make_foreign(std::move(table_names)); diff --git a/sstables/sstable_directory.hh b/sstables/sstable_directory.hh index 8d62cc82ab..2b7490a33b 100644 --- a/sstables/sstable_directory.hh +++ b/sstables/sstable_directory.hh @@ -45,8 +45,6 @@ public: { } - friend class ::replica::table; // FIXME table snapshots should switch to sstable_directory - template requires std::is_invocable_r_v, Func, typename std::ranges::range_value_t&> future<> parallel_for_each(Container& c, Func func) {