From 9b3fbedc8c4d0eb91bfbe482ff92bef884504e5f Mon Sep 17 00:00:00 2001 From: Benny Halevy Date: Sun, 23 Nov 2025 14:40:59 +0200 Subject: [PATCH] table: snapshot_on_all_shards: take snapshot_options And pass the use_sstable_identifier down the stack to the sstables layer. Signed-off-by: Benny Halevy --- replica/database.cc | 5 +++-- replica/database.hh | 4 ++-- replica/table.cc | 19 +++++++++++-------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/replica/database.cc b/replica/database.cc index a8211e7c68..6ab309507a 100644 --- a/replica/database.cc +++ b/replica/database.cc @@ -2815,7 +2815,7 @@ future<> database::snapshot_table_on_all_shards(sharded& sharded_db, t co_await flush_table_on_all_shards(sharded_db, uuid); } auto table_shards = co_await get_table_on_all_shards(sharded_db, uuid); - co_await table::snapshot_on_all_shards(sharded_db, table_shards, tag); + co_await table::snapshot_on_all_shards(sharded_db, table_shards, tag, opts); } future<> database::snapshot_tables_on_all_shards(sharded& sharded_db, std::string_view ks_name, std::vector table_names, sstring tag, db::snapshot_options opts) { @@ -2951,7 +2951,8 @@ future<> database::truncate_table_on_all_shards(sharded& sharded_db, s auto truncated_at = truncated_at_opt.value_or(db_clock::now()); auto name = snapshot_name_opt.value_or( format("{:d}-{}", truncated_at.time_since_epoch().count(), cf.schema()->cf_name())); - co_await table::snapshot_on_all_shards(sharded_db, table_shards, name); + auto opts = db::snapshot_options{}; // FIXME: use_sstable_identifier + co_await table::snapshot_on_all_shards(sharded_db, table_shards, name, opts); } co_await sharded_db.invoke_on_all([&] (database& db) { diff --git a/replica/database.hh b/replica/database.hh index 17042c3af3..efa76bcad9 100644 --- a/replica/database.hh +++ b/replica/database.hh @@ -1040,12 +1040,12 @@ public: private: using snapshot_file_set = foreign_ptr>>; - future take_snapshot(sstring jsondir); + future take_snapshot(sstring jsondir, db::snapshot_options opts); // Writes the table schema and the manifest of all files in the snapshot directory. future<> finalize_snapshot(const global_table_ptr& table_shards, sstring jsondir, std::vector file_sets); static future<> seal_snapshot(sstring jsondir, std::vector file_sets); public: - static future<> snapshot_on_all_shards(sharded& sharded_db, const global_table_ptr& table_shards, sstring name); + static future<> snapshot_on_all_shards(sharded& sharded_db, const global_table_ptr& table_shards, sstring name, db::snapshot_options opts); future> get_snapshot_details(); static future get_snapshot_details(std::filesystem::path snapshot_dir, std::filesystem::path datadir); diff --git a/replica/table.cc b/replica/table.cc index 4acff7fc3d..7caeb0bf4d 100644 --- a/replica/table.cc +++ b/replica/table.cc @@ -3268,7 +3268,7 @@ future<> table::write_schema_as_cql(const global_table_ptr& table_shards, sstrin } // Runs the orchestration code on an arbitrary shard to balance the load. -future<> table::snapshot_on_all_shards(sharded& sharded_db, const global_table_ptr& table_shards, sstring name) { +future<> table::snapshot_on_all_shards(sharded& sharded_db, const global_table_ptr& table_shards, sstring name, db::snapshot_options opts) { auto* so = std::get_if(&table_shards->get_storage_options().value); if (so == nullptr) { throw std::runtime_error("Snapshotting non-local tables is not implemented"); @@ -3291,7 +3291,7 @@ future<> table::snapshot_on_all_shards(sharded& sharded_db, const glob co_await io_check([&jsondir] { return recursive_touch_directory(jsondir); }); co_await coroutine::parallel_for_each(smp::all_cpus(), [&] (unsigned shard) -> future<> { file_sets.emplace_back(co_await smp::submit_to(shard, [&] { - return table_shards->take_snapshot(jsondir); + return table_shards->take_snapshot(jsondir, opts); })); }); co_await io_check(sync_directory, jsondir); @@ -3300,19 +3300,22 @@ future<> table::snapshot_on_all_shards(sharded& sharded_db, const glob }); } -future table::take_snapshot(sstring jsondir) { - tlogger.trace("take_snapshot {}", jsondir); +future table::take_snapshot(sstring jsondir, db::snapshot_options opts) { + tlogger.trace("take_snapshot {}: use_sstable_identifier={}", jsondir, opts.use_sstable_identifier); auto sstable_deletion_guard = co_await get_sstable_list_permit(); auto tables = *_sstables->all() | std::ranges::to>(); auto table_names = std::make_unique>(); - co_await _sstables_manager.dir_semaphore().parallel_for_each(tables, [&jsondir, &table_names] (sstables::shared_sstable sstable) { - table_names->insert(sstable->component_basename(sstables::component_type::Data)); - return io_check([sstable, &dir = jsondir] { - return sstable->snapshot(dir); + auto& ks_name = schema()->ks_name(); + auto& cf_name = schema()->cf_name(); + co_await _sstables_manager.dir_semaphore().parallel_for_each(tables, [&, opts] (sstables::shared_sstable sstable) -> future<> { + auto gen = co_await io_check([sstable, &dir = jsondir, opts] { + return sstable->snapshot(dir, opts.use_sstable_identifier); }); + auto fname = sstable->component_basename(ks_name, cf_name, sstable->get_version(), gen, sstable->get_format(), sstables::component_type::Data); + table_names->insert(fname); }); co_return make_foreign(std::move(table_names)); }