diff --git a/api/cache_service.cc b/api/cache_service.cc index 4233391517..4f8461d490 100644 --- a/api/cache_service.cc +++ b/api/cache_service.cc @@ -197,7 +197,7 @@ void set_cache_service(http_context& ctx, sharded& db, routes }); cs::get_row_capacity.set(r, [] (std::unique_ptr req) { - return seastar::map_reduce(smp::all_cpus(), [] (int cpu) { + return seastar::map_reduce(this_smp_all_shards(), [] (int cpu) { return make_ready_future(memory::stats().total_memory()); }, uint64_t(0), std::plus()).then([](const int64_t& res) { return make_ready_future(res); diff --git a/api/collectd.cc b/api/collectd.cc index 825f144238..d2e5d65770 100644 --- a/api/collectd.cc +++ b/api/collectd.cc @@ -60,8 +60,8 @@ void set_collectd(http_context& ctx, routes& r) { return do_with(std::vector(), [id] (auto& vec) { - vec.resize(smp::count); - return parallel_for_each(std::views::iota(0u, smp::count), [&vec, id] (auto cpu) { + vec.resize(this_smp_shard_count()); + return parallel_for_each(std::views::iota(0u, this_smp_shard_count()), [&vec, id] (auto cpu) { return smp::submit_to(cpu, [id = *id] { return scollectd::get_collectd_value(id); }).then([&vec, cpu] (auto res) { diff --git a/api/error_injection.cc b/api/error_injection.cc index 72c75c593a..0bc83e7dab 100644 --- a/api/error_injection.cc +++ b/api/error_injection.cc @@ -64,7 +64,7 @@ void set_error_injection(http_context& ctx, routes& r) { hf::read_injection.set(r, [](std::unique_ptr req) -> future { const sstring injection = req->get_path_param("injection"); - std::vector error_injection_infos(smp::count, error_injection_json::error_injection_info{}); + std::vector error_injection_infos(this_smp_shard_count(), error_injection_json::error_injection_info{}); co_await smp::invoke_on_all([&] { auto& info = error_injection_infos[this_shard_id()]; diff --git a/api/storage_service.cc b/api/storage_service.cc index 1f050ee112..7b38c8134c 100644 --- a/api/storage_service.cc +++ b/api/storage_service.cc @@ -449,7 +449,7 @@ void set_sstables_loader(http_context& ctx, routes& r, sharded& // No need to add the keyspace, since all we want is to avoid always sending this to the same // CPU. Even then I am being overzealous here. This is not something that happens all the time. - auto coordinator = std::hash()(cf) % smp::count; + auto coordinator = std::hash()(cf) % this_smp_shard_count(); return sst_loader.invoke_on(coordinator, [ks = std::move(ks), cf = std::move(cf), load_and_stream, primary_replica_only, skip_cleanup, skip_reshape, scope] (sstables_loader& loader) { diff --git a/compaction/compaction.cc b/compaction/compaction.cc index e5dbd423be..fae918f2ae 100644 --- a/compaction/compaction.cc +++ b/compaction/compaction.cc @@ -1974,8 +1974,8 @@ private: public: resharding_compaction(compaction_group_view& table_s, compaction_descriptor descriptor, compaction_data& cdata, compaction_progress_monitor& progress_monitor) : compaction(table_s, std::move(descriptor), cdata, progress_monitor, use_backlog_tracker::no) - , _estimation_per_shard(smp::count) - , _run_identifiers(smp::count) + , _estimation_per_shard(this_smp_shard_count()) + , _run_identifiers(this_smp_shard_count()) , _reshard_vnodes(descriptor.options.as().vnodes_resharding) { if (_reshard_vnodes && !_owned_ranges) { @@ -1990,7 +1990,7 @@ public: _estimation_per_shard[s].estimated_partitions += std::max(uint64_t(1), uint64_t(ceil(double(estimated_partitions) / shards.size()))); } } - for (auto i : std::views::iota(0u, smp::count)) { + for (auto i : std::views::iota(0u, this_smp_shard_count())) { _run_identifiers[i] = sstables::run_id::create_random_id(); } } diff --git a/compaction/compaction_strategy.cc b/compaction/compaction_strategy.cc index 74c195323b..18bf57ae1c 100644 --- a/compaction/compaction_strategy.cc +++ b/compaction/compaction_strategy.cc @@ -785,7 +785,7 @@ compaction_strategy make_compaction_strategy(compaction_strategy_type strategy, future make_reshape_config(const sstables::storage& storage, reshape_mode mode) { co_return reshape_config{ .mode = mode, - .free_storage_space = co_await storage.free_space() / smp::count, + .free_storage_space = co_await storage.free_space() / this_smp_shard_count(), }; } diff --git a/compaction/task_manager_module.cc b/compaction/task_manager_module.cc index 1876269721..81456edd9b 100644 --- a/compaction/task_manager_module.cc +++ b/compaction/task_manager_module.cc @@ -98,7 +98,7 @@ collect_all_shared_sstables(sharded& dir, sharded> distribute_reshard_jobs(sstables::sstable_directory::sstable_open_info_vector source) { - auto destinations = std::vector(smp::count); + auto destinations = std::vector(this_smp_shard_count()); std::sort(source.begin(), source.end(), [] (const sstables::foreign_sstable_open_info& a, const sstables::foreign_sstable_open_info& b) { // Sort on descending SSTable sizes. diff --git a/cql3/functions/error_injection_fcts.cc b/cql3/functions/error_injection_fcts.cc index 05e79d7e89..cdebf92538 100644 --- a/cql3/functions/error_injection_fcts.cc +++ b/cql3/functions/error_injection_fcts.cc @@ -86,7 +86,7 @@ shared_ptr make_enabled_injections_function() { const auto list_type_inst = list_type_impl::get_instance(ascii_type, false); return make_failure_injection_function("enabled_injections", list_type_inst, {}, [list_type_inst] (std::span) -> bytes { - return seastar::map_reduce(smp::all_cpus(), [] (unsigned) { + return seastar::map_reduce(this_smp_all_shards(), [] (unsigned) { return make_ready_future>(utils::get_local_injector().enabled_injections()); }, std::vector(), [](std::vector a, std::vector&& b) -> std::vector { diff --git a/cql3/statements/modification_statement.cc b/cql3/statements/modification_statement.cc index 5e41010726..93be6e9624 100644 --- a/cql3/statements/modification_statement.cc +++ b/cql3/statements/modification_statement.cc @@ -375,7 +375,7 @@ process_forced_rebounce(unsigned shard, query_processor& qp, const query_options // While counter > 1 select a different shard to re-bounce to. // On the last iteration, re-bounce to the correct shard. if (counter != 0) { - const auto shard_num = smp::count; + const auto shard_num = this_smp_shard_count(); const auto local_shard = this_shard_id(); auto target_shard = local_shard + 1; if (target_shard == shard) { diff --git a/db/batchlog_manager.cc b/db/batchlog_manager.cc index 4f6353aaa5..6500f00d75 100644 --- a/db/batchlog_manager.cc +++ b/db/batchlog_manager.cc @@ -168,7 +168,7 @@ future db::batchlog_manager::do_batch_log_replay(post_ auto gate_holder = bm._gate.hold(); auto sem_units = co_await get_units(bm._sem, 1); - auto dest = bm._cpu++ % smp::count; + auto dest = bm._cpu++ % this_smp_shard_count(); blogger.debug("Batchlog replay on shard {}: starts", dest); auto last_replay = gc_clock::now(); all_batches_replayed all_replayed = all_batches_replayed::yes; diff --git a/db/commitlog/commitlog.cc b/db/commitlog/commitlog.cc index ee2155c0f0..56fcfecc06 100644 --- a/db/commitlog/commitlog.cc +++ b/db/commitlog/commitlog.cc @@ -100,7 +100,7 @@ db::commitlog::config db::commitlog::config::from_db_config(const db::config& cf c.sched_group = std::move(sg); c.commit_log_location = cfg.commitlog_directory(); c.metrics_category_name = "commitlog"; - c.commitlog_total_space_in_mb = cfg.commitlog_total_space_in_mb() >= 0 ? cfg.commitlog_total_space_in_mb() : (shard_available_memory * smp::count) >> 20; + c.commitlog_total_space_in_mb = cfg.commitlog_total_space_in_mb() >= 0 ? cfg.commitlog_total_space_in_mb() : (shard_available_memory * this_smp_shard_count()) >> 20; c.commitlog_segment_size_in_mb = cfg.commitlog_segment_size_in_mb(); c.commitlog_sync_period_in_ms = cfg.commitlog_sync_period_in_ms(); c.mode = cfg.commitlog_sync() == "batch" ? sync_mode::BATCH : sync_mode::PERIODIC; @@ -1908,9 +1908,9 @@ db::commitlog::segment_manager::segment_manager(config c) if (cfg.max_active_flushes == 0) { cfg.max_active_flushes = // TODO: call someone to get an idea... - 5 * smp::count; + 5 * this_smp_shard_count(); } - cfg.max_active_flushes = std::max(uint64_t(1), cfg.max_active_flushes / smp::count); + cfg.max_active_flushes = std::max(uint64_t(1), cfg.max_active_flushes / this_smp_shard_count()); if (!cfg.base_segment_id) { cfg.base_segment_id = std::chrono::duration_cast(runtime::get_boot_time().time_since_epoch()).count() + 1; @@ -1920,11 +1920,11 @@ db::commitlog::segment_manager::segment_manager(config c) }()) , max_size(std::min(std::numeric_limits::max() / (1024 * 1024), std::max(cfg.commitlog_segment_size_in_mb, 1)) * 1024 * 1024) , max_mutation_size(max_size >> 1) // note: can't up this by much, because we don't know the CRC sector overhead addition before we've actually opened each segment. - , max_disk_size(size_t(std::ceil(cfg.commitlog_total_space_in_mb / double(smp::count))) * 1024 * 1024) + , max_disk_size(size_t(std::ceil(cfg.commitlog_total_space_in_mb / double(this_smp_shard_count()))) * 1024 * 1024) // our threshold for trying to force a flush. needs heristics, for now max - segment_size/2. , disk_usage_threshold([&] { if (cfg.commitlog_flush_threshold_in_mb.has_value()) { - return size_t(std::ceil(*cfg.commitlog_flush_threshold_in_mb / double(smp::count))) * 1024 * 1024; + return size_t(std::ceil(*cfg.commitlog_flush_threshold_in_mb / double(this_smp_shard_count()))) * 1024 * 1024; } else { return max_disk_size / 2; } @@ -1946,7 +1946,7 @@ db::commitlog::segment_manager::segment_manager(config c) clogger.trace("Commitlog {} maximum disk size: {} MB / cpu ({} cpus)", cfg.commit_log_location, max_disk_size / (1024 * 1024), - smp::count); + this_smp_shard_count()); if (!cfg.metrics_category_name.empty()) { create_counters(cfg.metrics_category_name); @@ -2076,7 +2076,7 @@ future<> db::commitlog::segment_manager::init() { // always run the timer now, since we need to handle segment pre-alloc etc as well. _timer.set_callback(std::bind(&segment_manager::on_timer, this)); - auto delay = this_shard_id() * std::ceil(double(cfg.commitlog_sync_period_in_ms) / smp::count); + auto delay = this_shard_id() * std::ceil(double(cfg.commitlog_sync_period_in_ms) / this_smp_shard_count()); clogger.trace("Delaying timer loop {} ms", delay); // We need to wait until we have scanned all other segments to actually start serving new // segments. We are ready now diff --git a/db/commitlog/commitlog_replayer.cc b/db/commitlog/commitlog_replayer.cc index f6445dde47..3be1969d06 100644 --- a/db/commitlog/commitlog_replayer.cc +++ b/db/commitlog/commitlog_replayer.cc @@ -350,14 +350,14 @@ future<> db::commitlog_replayer::recover(std::vector files, sstring fna for (auto& d : descs) { replay_position p = d; - map[p.shard_id() % smp::count].push_back(std::move(d)); + map[p.shard_id() % this_smp_shard_count()].push_back(std::move(d)); } } co_await _impl->start(); std::exception_ptr e; try { - auto totals = co_await map_reduce(smp::all_cpus(), [&](unsigned id) -> future { + auto totals = co_await map_reduce(this_smp_all_shards(), [&](unsigned id) -> future { co_return co_await smp::submit_to(id, [&] () -> future { impl::stats total; std::unordered_map states; diff --git a/db/hints/internal/hint_storage.cc b/db/hints/internal/hint_storage.cc index 83c89ca6d7..b4bad607a3 100644 --- a/db/hints/internal/hint_storage.cc +++ b/db/hints/internal/hint_storage.cc @@ -133,7 +133,7 @@ future<> rebalance_segments_for(const sstring& ep, size_t segments_per_shard, co_return; } - for (unsigned i = 0; i < smp::count && !segments_to_move.empty(); ++i) { + for (unsigned i = 0; i < this_smp_shard_count() && !segments_to_move.empty(); ++i) { const fs::path endpoint_dir_path = hint_directory / fmt::to_string(i) / ep; segment_list& current_shard_segments = ep_segments[i]; @@ -188,13 +188,13 @@ future<> rebalance_segments(const fs::path& hint_directory, hints_segments_map& std::unordered_map segments_to_move; for (auto& [ep, ep_segments] : segments_map) { - const size_t q = per_ep_hints[ep] / smp::count; + const size_t q = per_ep_hints[ep] / this_smp_shard_count(); auto& current_segments_to_move = segments_to_move[ep]; for (auto& [shard_id, shard_segments] : ep_segments) { // Move all segments from the shards that are no longer relevant // (re-sharding to the lower number of shards). - if (shard_id >= smp::count) { + if (shard_id >= this_smp_shard_count()) { current_segments_to_move.splice(current_segments_to_move.end(), shard_segments); } else if (shard_segments.size() > q) { current_segments_to_move.splice(current_segments_to_move.end(), shard_segments, @@ -221,8 +221,8 @@ future<> rebalance_segments(const fs::path& hint_directory, hints_segments_map& // to the corresponding shard's sub-directory till the requested segments_per_shard level // is reached (see more details in the description of rebalance_segments_for()). for (const auto& [ep, N] : per_ep_hints) { - const size_t q = N / smp::count; - const size_t r = N - q * smp::count; + const size_t q = N / this_smp_shard_count(); + const size_t r = N - q * this_smp_shard_count(); auto& current_segments_to_move = segments_to_move[ep]; auto& current_segments_map = segments_map[ep]; @@ -246,7 +246,7 @@ future<> remove_irrelevant_shards_directories(const fs::path& hint_directory) { // Shard level. co_await scan_shard_hint_directories(hint_directory, [] (fs::path dir, directory_entry de, unsigned shard_id) -> future<> { - if (shard_id >= smp::count) { + if (shard_id >= this_smp_shard_count()) { // IP level. co_await lister::scan_dir(dir / de.name, lister::dir_entry_types::full(), lister::show_hidden::yes, [] (fs::path dir, directory_entry de) { diff --git a/db/hints/resource_manager.cc b/db/hints/resource_manager.cc index 6b088b6dfe..fe0e75c30f 100644 --- a/db/hints/resource_manager.cc +++ b/db/hints/resource_manager.cc @@ -46,7 +46,7 @@ future> resource_manager::ge // require each hint to reserve at least 1/(max concurrency) of the shard budget const size_t per_node_concurrency_limit = _max_hints_send_queue_length(); const size_t per_shard_concurrency_limit = (per_node_concurrency_limit > 0) - ? div_ceil(per_node_concurrency_limit, smp::count) + ? div_ceil(per_node_concurrency_limit, this_smp_shard_count()) : default_per_shard_concurrency_limit; const size_t min_send_hint_budget = _max_send_in_flight_memory / per_shard_concurrency_limit; // Let's approximate the memory size the mutation is going to consume by the size of its serialized form @@ -285,7 +285,7 @@ future<> resource_manager::prepare_per_device_limits(manager& shard_manager) { // Since we possibly deferred, we need to recheck the _per_device_limits_map. if (inserted) { // By default, give each group of managers 10% of the available disk space. Give each shard an equal share of the available space. - it->second.max_shard_disk_space_size = std::filesystem::space(shard_manager.hints_dir().c_str()).capacity / (10 * smp::count); + it->second.max_shard_disk_space_size = std::filesystem::space(shard_manager.hints_dir().c_str()).capacity / (10 * this_smp_shard_count()); // If hints directory is a mountpoint, we assume it's on dedicated (i.e. not shared with data/commitlog/etc) storage. // Then, reserve 90% of all space instead of 10% above. if (is_mountpoint) { diff --git a/db/hints/sync_point.cc b/db/hints/sync_point.cc index 64cc65f960..38d7bf037e 100644 --- a/db/hints/sync_point.cc +++ b/db/hints/sync_point.cc @@ -71,7 +71,7 @@ static std::vector decode_one_type(uint16_t shard_count, size_t(shard_count) * v.endpoints.size(), v.flattened_rps.size())); } - ret.resize(std::max(unsigned(shard_count), smp::count)); + ret.resize(std::max(unsigned(shard_count), this_smp_shard_count())); auto rps_it = v.flattened_rps.begin(); for (const auto ep : v.endpoints) { @@ -81,7 +81,7 @@ static std::vector decode_one_type(uint16_t shard_count, } // Fill missing shards with zero replay positions so that segments // which were moved across shards will be correctly waited on - for (; shard < smp::count; shard++) { + for (; shard < this_smp_shard_count(); shard++) { ret[shard].emplace(ep, db::replay_position()); } } diff --git a/db/schema_applier.hh b/db/schema_applier.hh index 9387451b8b..8753759b8d 100644 --- a/db/schema_applier.hh +++ b/db/schema_applier.hh @@ -99,7 +99,7 @@ class in_progress_types_storage { // wrapped in foreign_ptr so they can be destroyed on the right shard std::vector>> shards; public: - in_progress_types_storage() : shards(smp::count) {} + in_progress_types_storage() : shards(this_smp_shard_count()) {} future<> init(sharded& sharded_db, const affected_keyspaces& affected_keyspaces, const affected_user_types& affected_types); in_progress_types_storage_per_shard& local(); }; @@ -132,7 +132,7 @@ struct schema_diff_per_shard { class pending_token_metadata { - std::vector shards{smp::count}; + std::vector shards{this_smp_shard_count()}; public: future<> assign(locator::mutable_token_metadata_ptr new_token_metadata); locator::mutable_token_metadata_ptr& local(); diff --git a/db/schema_tables.cc b/db/schema_tables.cc index 4bb08d9bd7..da4df10167 100644 --- a/db/schema_tables.cc +++ b/db/schema_tables.cc @@ -2289,7 +2289,7 @@ schema_ptr create_table_from_mutations(const schema_ctxt& ctxt, schema_mutations if (auto partitioner = sm.partitioner()) { builder.with_partitioner(*partitioner); - builder.with_sharder(smp::count, ctxt.murmur3_partitioner_ignore_msb_bits()); + builder.with_sharder(this_smp_shard_count(), ctxt.murmur3_partitioner_ignore_msb_bits()); } return builder.build(); diff --git a/db/snapshot/backup_task.hh b/db/snapshot/backup_task.hh index 7506133325..084ca8035d 100644 --- a/db/snapshot/backup_task.hh +++ b/db/snapshot/backup_task.hh @@ -91,7 +91,7 @@ class backup_task_impl : public tasks::task_manager::task::impl { future<> upload_component(sstring name); }; sharded _sharded_worker; - std::vector _progress_per_shard{smp::count}; + std::vector _progress_per_shard{this_smp_shard_count()}; future<> do_backup(); future<> process_snapshot_dir(); diff --git a/db/system_keyspace.cc b/db/system_keyspace.cc index 3394a236ad..66daa1f9d3 100644 --- a/db/system_keyspace.cc +++ b/db/system_keyspace.cc @@ -1488,7 +1488,7 @@ future<> system_keyspace::drop_truncation_rp_records() { bool any = false; std::unordered_set to_delete; auto db = _qp.db(); - auto max_concurrency = std::min(1024u, smp::count * 8); + auto max_concurrency = std::min(1024u, this_smp_shard_count() * 8); co_await seastar::max_concurrent_for_each(*rs, max_concurrency, [&] (const cql3::untyped_result_set_row& row) -> future<> { auto table_uuid = table_id(row.get_as("table_uuid")); if (!db.try_find_table(table_uuid)) { @@ -2601,7 +2601,7 @@ future<> system_keyspace::register_view_for_building_for_all_shards(sstring ks_n auto timestamp = api::new_timestamp(); mutation m{schema, partition_key::from_single_value(*schema, utf8_type->decompose(ks_name))}; - for (size_t s = 0; s < smp::count; s++) { + for (size_t s = 0; s < this_smp_shard_count(); s++) { auto ck = clustering_key_prefix(std::vector{ utf8_type->decompose(view_name), int32_type->decompose(int32_t(s))}); diff --git a/db/view/view.cc b/db/view/view.cc index 73ca6b6aa7..017a61ad22 100644 --- a/db/view/view.cc +++ b/db/view/view.cc @@ -2452,7 +2452,7 @@ void view_builder::setup_shard_build_step( future<> view_builder::calculate_shard_build_step(view_builder_init_state& vbi) { std::unordered_set loaded_views; - if (vbi.status_per_shard.size() != smp::count) { + if (vbi.status_per_shard.size() != this_smp_shard_count()) { reshard(std::move(vbi.status_per_shard), loaded_views); } else if (!vbi.status_per_shard.empty()) { for (auto& status : vbi.status_per_shard[this_shard_id()]) { @@ -2600,7 +2600,7 @@ future<> view_builder::add_new_view(view_ptr view, build_step& step) { co_await mark_view_build_started(view->ks_name(), view->cf_name()); } - if (this_shard_id() == smp::count - 1) { + if (this_shard_id() == this_smp_shard_count() - 1) { inject_failure("add_new_view_fail_last_shard"); } @@ -3223,7 +3223,7 @@ update_backlog node_update_backlog::fetch() { future> node_update_backlog::fetch_if_changed() { _last_update.store(clock::now(), std::memory_order_relaxed); - auto [np, max] = co_await map_reduce(std::views::iota(0u, smp::count), + auto [np, max] = co_await map_reduce(std::views::iota(0u, this_smp_shard_count()), [this] (shard_id shard) { return smp::submit_to(shard, [this, shard] { // Even if the shard's backlog didn't change, we still need to take it into account when calculating the new max. diff --git a/db/view/view_building_worker.cc b/db/view/view_building_worker.cc index 3d61614e59..0fabd77f50 100644 --- a/db/view/view_building_worker.cc +++ b/db/view/view_building_worker.cc @@ -242,7 +242,7 @@ future>>> view_building_worker::lock_s // so other shards won't interact with their `_staging_sstables` map // until the caller releases them. std::vector>> locks; - locks.resize(smp::count); + locks.resize(this_smp_shard_count()); // Locks are acquired from multiple shards in parallel. // This is the only place where multiple-shard locks are acquired at once // and the method is called only once at a time (from `create_staging_sstable_tasks()` diff --git a/db/virtual_tables.cc b/db/virtual_tables.cc index 6bec1d6e8a..b467bdcab7 100644 --- a/db/virtual_tables.cc +++ b/db/virtual_tables.cc @@ -455,7 +455,7 @@ private: template future map_reduce_shards(std::function map, std::function reduce = std::plus{}, T initial = {}) { co_return co_await map_reduce( - std::views::iota(0u, smp::count), + std::views::iota(0u, this_smp_shard_count()), [map] (shard_id shard) { return smp::submit_to(shard, [map] { return map(); @@ -780,7 +780,7 @@ class clients_table : public streaming_virtual_table { using client_data_vec = utils::chunked_vector>>; using shard_client_data = std::vector; std::vector>> cd_vec; - cd_vec.resize(smp::count); + cd_vec.resize(this_smp_shard_count()); auto servers = co_await _ss.container().invoke_on(0, [] (auto& ss) { return ss.protocol_servers(); }); co_await smp::invoke_on_all([&cd_vec_ = cd_vec, &servers_ = servers] () -> future<> { @@ -814,7 +814,7 @@ class clients_table : public streaming_virtual_table { decorated_ip::compare cmp(*_s); std::set ips(cmp); std::unordered_map cd_map; - for (unsigned i = 0; i < smp::count; i++) { + for (unsigned i = 0; i < this_smp_shard_count(); i++) { for (auto&& ps_cdc : *cd_vec[i]) { for (auto&& cd : ps_cdc) { if (cd_map.contains(cd->ip)) { diff --git a/dht/fixed_shard.cc b/dht/fixed_shard.cc index 845674be70..ec1ac98b34 100644 --- a/dht/fixed_shard.cc +++ b/dht/fixed_shard.cc @@ -87,7 +87,7 @@ fixed_shard_sharder& fixed_shard_sharder::instance() { } fixed_shard_sharder::fixed_shard_sharder() - : static_sharder(smp::count, 0) + : static_sharder(this_smp_shard_count(), 0) { } diff --git a/dht/token-sharding.hh b/dht/token-sharding.hh index fd3326d89a..4b3661c486 100644 --- a/dht/token-sharding.hh +++ b/dht/token-sharding.hh @@ -51,7 +51,7 @@ protected: unsigned _shard_count; unsigned _sharding_ignore_msb_bits; public: - sharder(unsigned shard_count = smp::count, unsigned sharding_ignore_msb_bits = 0); + sharder(unsigned shard_count = this_smp_shard_count(), unsigned sharding_ignore_msb_bits = 0); virtual ~sharder() = default; /** @@ -99,7 +99,7 @@ public: * * If the `spans` parameter is greater than zero, the result is the same as if the function * is called `spans` times, each time applied to its return value, but efficiently. This allows - * selecting ranges that include multiple round trips around the 0..smp::count-1 shard span: + * selecting ranges that include multiple round trips around the 0..this_smp_shard_count()-1 shard span: * * token_for_next_shard(t, shard, spans) == token_for_next_shard(token_for_next_shard(t, shard, 1), spans - 1) * @@ -139,7 +139,7 @@ public: class static_sharder : public sharder { std::vector _shard_start; public: - static_sharder(unsigned shard_count = smp::count, unsigned sharding_ignore_msb_bits = 0); + static_sharder(unsigned shard_count = this_smp_shard_count(), unsigned sharding_ignore_msb_bits = 0); virtual unsigned shard_of(const token& t) const; virtual std::optional next_shard(const token& t) const; diff --git a/ent/encryption/encryption.cc b/ent/encryption/encryption.cc index e8c58f4643..2a64760c20 100644 --- a/ent/encryption/encryption.cc +++ b/ent/encryption/encryption.cc @@ -289,13 +289,13 @@ class encryption_context_impl : public encryption_context { bool _allow_per_table_encryption; public: encryption_context_impl(std::unique_ptr cfg, const service_set& services) - : _per_thread_provider_cache(smp::count) - , _per_thread_system_key_cache(smp::count) - , _per_thread_kmip_host_cache(smp::count) - , _per_thread_kms_host_cache(smp::count) - , _per_thread_gcp_host_cache(smp::count) - , _per_thread_azure_host_cache(smp::count) - , _per_thread_global_user_extension(smp::count) + : _per_thread_provider_cache(this_smp_shard_count()) + , _per_thread_system_key_cache(this_smp_shard_count()) + , _per_thread_kmip_host_cache(this_smp_shard_count()) + , _per_thread_kms_host_cache(this_smp_shard_count()) + , _per_thread_gcp_host_cache(this_smp_shard_count()) + , _per_thread_azure_host_cache(this_smp_shard_count()) + , _per_thread_global_user_extension(this_smp_shard_count()) , _cfg(std::move(cfg)) , _qp(find_or_null(services)) , _mm(find_or_null(services)) diff --git a/gms/gossiper.cc b/gms/gossiper.cc index a9ab070e8f..35457546dd 100644 --- a/gms/gossiper.cc +++ b/gms/gossiper.cc @@ -1006,7 +1006,7 @@ future<> gossiper::failure_detector_loop() { auto generation_number = my_endpoint_state().get_heart_beat_state().get_generation(); co_await coroutine::parallel_for_each(std::views::iota(0u, nodes.size()), [this, generation_number, live_endpoints_version, &nodes] (size_t idx) { const auto& node = nodes[idx]; - auto shard = idx % smp::count; + auto shard = idx % this_smp_shard_count(); logger.debug("failure_detector_loop: Started new round for node={} on shard={}, live_nodes={}, live_endpoints_version={}", node, shard, nodes, live_endpoints_version); return container().invoke_on(shard, [node, generation_number, live_endpoints_version] (gms::gossiper& g) { @@ -1037,11 +1037,11 @@ future<> gossiper::replicate_live_endpoints_on_change(foreign_ptr>> per_shard_data; - per_shard_data.resize(smp::count); + per_shard_data.resize(this_smp_shard_count()); per_shard_data[coordinator] = std::move(data0); // Prepare copies on each other shard - co_await coroutine::parallel_for_each(std::views::iota(0u, smp::count), [&per_shard_data, coordinator] (auto shard) -> future<> { + co_await coroutine::parallel_for_each(std::views::iota(0u, this_smp_shard_count()), [&per_shard_data, coordinator] (auto shard) -> future<> { if (shard != this_shard_id()) { const auto& src = *per_shard_data[coordinator]; per_shard_data[shard] = co_await smp::submit_to(shard, [&] { @@ -1291,11 +1291,11 @@ future<> gossiper::replicate(endpoint_state es, permit_id pid) { // First pass: replicate the new endpoint_state on all shards. // Use foreign_ptr to ensure destroy on remote shards on exception std::vector> ep_states; - ep_states.resize(smp::count); + ep_states.resize(this_smp_shard_count()); auto p = make_foreign(make_endpoint_state_ptr(std::move(es))); const auto *eps = p.get(); ep_states[this_shard_id()] = std::move(p); - co_await coroutine::parallel_for_each(std::views::iota(0u, smp::count), [&, orig = this_shard_id()] (auto shard) -> future<> { + co_await coroutine::parallel_for_each(std::views::iota(0u, this_smp_shard_count()), [&, orig = this_shard_id()] (auto shard) -> future<> { if (shard != orig) { ep_states[shard] = co_await smp::submit_to(shard, [eps] { return make_foreign(make_endpoint_state_ptr(*eps)); @@ -2230,8 +2230,8 @@ future<> gossiper::wait_alive_helper(noncopyable_functionget_host_id()] (gossiper& g) -> size_t { return g.is_alive(node) ? 1 : 0; }, 0, std::plus()); - logger.debug("Marked node={} as alive on {} out of {} shards", node, nr_alive, smp::count); - if (nr_alive == smp::count) { + logger.debug("Marked node={} as alive on {} out of {} shards", node, nr_alive, this_smp_shard_count()); + if (nr_alive == this_smp_shard_count()) { live_nodes.push_back(node); } } diff --git a/locator/abstract_replication_strategy.cc b/locator/abstract_replication_strategy.cc index 2476c07ad5..97223995c3 100644 --- a/locator/abstract_replication_strategy.cc +++ b/locator/abstract_replication_strategy.cc @@ -717,7 +717,7 @@ future<> global_static_effective_replication_map::get_keyspace_erms(shardedget_token_metadata().get_ring_version(); _erms[0] = make_foreign(std::move(erm)); - co_await coroutine::parallel_for_each(std::views::iota(1u, smp::count), [this, &sharded_db, keyspace_name, ring_version] (unsigned shard) -> future<> { + co_await coroutine::parallel_for_each(std::views::iota(1u, this_smp_shard_count()), [this, &sharded_db, keyspace_name, ring_version] (unsigned shard) -> future<> { _erms[shard] = co_await sharded_db.invoke_on(shard, [keyspace_name, ring_version] (const replica::database& db) { const auto& ks = db.find_keyspace(keyspace_name); auto erm = ks.get_static_effective_replication_map(); diff --git a/locator/abstract_replication_strategy.hh b/locator/abstract_replication_strategy.hh index 5c045b7e0f..f58702629c 100644 --- a/locator/abstract_replication_strategy.hh +++ b/locator/abstract_replication_strategy.hh @@ -463,7 +463,7 @@ class global_static_effective_replication_map { std::vector> _erms; public: - global_static_effective_replication_map() : _erms(smp::count) {} + global_static_effective_replication_map() : _erms(this_smp_shard_count()) {} global_static_effective_replication_map(global_static_effective_replication_map&&) = default; global_static_effective_replication_map& operator=(global_static_effective_replication_map&&) = default; diff --git a/locator/tablets.cc b/locator/tablets.cc index aa471385ab..249da7d1d4 100644 --- a/locator/tablets.cc +++ b/locator/tablets.cc @@ -473,7 +473,7 @@ future<> tablet_metadata::clear_gently() { // on this shard. We don't use sharded<> here since it will require a similar // submit_to to each shard owner per tablet-map. std::vector> tablet_maps_per_shard; - tablet_maps_per_shard.resize(smp::count); + tablet_maps_per_shard.resize(this_smp_shard_count()); for (auto& [_, map_ptr] : _tablets) { tablet_maps_per_shard[map_ptr.get_owner_shard()].emplace_back(std::move(map_ptr)); } @@ -1327,7 +1327,7 @@ future check_tablet_replica_shards(const tablet_metadata& tm, host_id this co_await tmap->for_each_tablet([this_host, &valid] (locator::tablet_id tid, const tablet_info& tinfo) -> future<> { for (const auto& replica : tinfo.replicas) { if (replica.host == this_host) { - valid &= replica.shard < smp::count; + valid &= replica.shard < this_smp_shard_count(); } } return make_ready_future<>(); diff --git a/locator/tablets.hh b/locator/tablets.hh index 763414415b..b2b973f452 100644 --- a/locator/tablets.hh +++ b/locator/tablets.hh @@ -996,7 +996,7 @@ public: friend fmt::formatter; }; -// Check that all tablets which have replicas on this host, have a valid replica shard (< smp::count). +// Check that all tablets which have replicas on this host, have a valid replica shard (< this_smp_shard_count()). future check_tablet_replica_shards(const tablet_metadata& tm, host_id this_host); std::optional maybe_get_primary_replica(tablet_id id, const tablet_replica_set& replica_set, const locator::topology& topo, std::function filter); diff --git a/locator/token_metadata.cc b/locator/token_metadata.cc index 1025e446de..04635820de 100644 --- a/locator/token_metadata.cc +++ b/locator/token_metadata.cc @@ -1273,7 +1273,7 @@ future<> shared_token_metadata::mutate_on_all_shards(sharded pending_token_metadata_ptr; - pending_token_metadata_ptr.resize(smp::count); + pending_token_metadata_ptr.resize(this_smp_shard_count()); auto tmptr = stm.local().make_token_metadata_ptr(co_await stm.local().get()->clone_async()); auto& tm = *tmptr; // bump the token_metadata ring_version diff --git a/locator/token_metadata.hh b/locator/token_metadata.hh index 05bbe0300b..a7a819f934 100644 --- a/locator/token_metadata.hh +++ b/locator/token_metadata.hh @@ -495,7 +495,7 @@ private: }; class pending_token_metadata { - std::vector _shards{smp::count}; + std::vector _shards{this_smp_shard_count()}; public: future<> assign(locator::mutable_token_metadata_ptr new_token_metadata); locator::mutable_token_metadata_ptr& local(); diff --git a/main.cc b/main.cc index e71f964cea..d56c154f5c 100644 --- a/main.cc +++ b/main.cc @@ -1408,7 +1408,7 @@ To start the scylla server proper, simply invoke as: scylla server (or just scyl spcfg.write_mv_smp_service_group = create_smp_service_group(storage_proxy_smp_service_group_config).get(); spcfg.hints_write_smp_service_group = create_smp_service_group(storage_proxy_smp_service_group_config).get(); spcfg.write_ack_smp_service_group = create_smp_service_group(storage_proxy_smp_service_group_config).get(); - static db::view::node_update_backlog node_backlog(smp::count, 10ms, cfg->view_flow_control_delay_limit_in_ms); + static db::view::node_update_backlog node_backlog(this_smp_shard_count(), 10ms, cfg->view_flow_control_delay_limit_in_ms); static sharded timeout_cfg; timeout_cfg.start(std::ref(*cfg)).get(); @@ -2116,7 +2116,7 @@ To start the scylla server proper, simply invoke as: scylla server (or just scyl db.invoke_on_all(&replica::database::flush_all_memtables).get(); supervisor::notify("replaying commit log - removing old commitlog segments"); - auto chunks = paths | std::views::chunk(size_t(std::ceil(double(paths.size())/smp::count))); + auto chunks = paths | std::views::chunk(size_t(std::ceil(double(paths.size())/this_smp_shard_count()))); db.invoke_on_all([&chunks](auto& db) { if (this_shard_id() < chunks.size()) { auto chunk = chunks[this_shard_id()]; diff --git a/message/advanced_rpc_compressor.cc b/message/advanced_rpc_compressor.cc index 6377240f54..abcbc66f1c 100644 --- a/message/advanced_rpc_compressor.cc +++ b/message/advanced_rpc_compressor.cc @@ -563,7 +563,7 @@ future<> announce_dict_to_shards(seastar::sharded& arc_logger.debug("Announcing new dictionary: ts={}, origin={}", shared_dict.id.timestamp, shared_dict.id.origin_node); auto dict = make_lw_shared(std::move(shared_dict)); auto foreign_ptrs = std::vector>(); - for (size_t i = 0; i < smp::count; ++i) { + for (size_t i = 0; i < this_smp_shard_count(); ++i) { foreign_ptrs.push_back(make_foreign(dict)); } co_await sharded_tracker.invoke_on_all([&foreign_ptrs] (auto& tracker) { diff --git a/mutation_writer/shard_based_splitting_writer.cc b/mutation_writer/shard_based_splitting_writer.cc index 202c5b1ebd..d381eebe21 100644 --- a/mutation_writer/shard_based_splitting_writer.cc +++ b/mutation_writer/shard_based_splitting_writer.cc @@ -33,7 +33,7 @@ public: : _schema(std::move(schema)) , _permit(std::move(permit)) , _consumer(std::move(consumer)) - , _shards(smp::count) + , _shards(this_smp_shard_count()) {} future<> consume(partition_start&& ps) { diff --git a/repair/repair.cc b/repair/repair.cc index c20e8021f4..8d45ead157 100644 --- a/repair/repair.cc +++ b/repair/repair.cc @@ -1351,7 +1351,7 @@ future<> repair::user_requested_repair_task_impl::run() { auto [_, hints_batchlog_flushed, flush_time] = rs.flush_hints(id, keyspace, cfs, ignore_nodes).get(); std::vector> repair_results; - repair_results.reserve(smp::count); + repair_results.reserve(this_smp_shard_count()); auto table_ids = get_table_ids(db, keyspace, cfs); abort_source as; auto off_strategy_updater = seastar::async([&rs, uuid = uuid.uuid(), &table_ids, &participants, &as] { @@ -1395,7 +1395,7 @@ future<> repair::user_requested_repair_task_impl::run() { auto ranges_parallelism = _ranges_parallelism; bool small_table_optimization = _small_table_optimization; - for (auto shard : std::views::iota(0u, smp::count)) { + for (auto shard : std::views::iota(0u, this_smp_shard_count())) { auto f = rs.container().invoke_on(shard, [keyspace, table_ids, id, ranges, hints_batchlog_flushed, flush_time, ranges_parallelism, small_table_optimization, data_centers, hosts, ignore_nodes, parent_data = get_repair_uniq_id().task_info, germs] (repair_service& local_repair) mutable -> future<> { local_repair.get_metrics().repair_total_ranges_sum += ranges.size(); @@ -1433,7 +1433,7 @@ future<> repair::user_requested_repair_task_impl::run() { } future> repair::user_requested_repair_task_impl::expected_total_workload() const { - co_return _ranges.size() * _cfs.size() * smp::count; + co_return _ranges.size() * _cfs.size() * this_smp_shard_count(); } future repair_start(seastar::sharded& repair, sharded& am, @@ -1534,9 +1534,9 @@ future<> repair::data_sync_repair_task_impl::run() { } auto table_ids = get_table_ids(db, keyspace, cfs); std::vector> repair_results; - repair_results.reserve(smp::count); + repair_results.reserve(this_smp_shard_count()); task_as.check(); - for (auto shard : std::views::iota(0u, smp::count)) { + for (auto shard : std::views::iota(0u, this_smp_shard_count())) { auto f = rs.container().invoke_on(shard, [keyspace, table_ids, id, ranges_reduced_factor, ranges, neighbors, reason, germs, small_table_optimization, parent_data = get_repair_uniq_id().task_info, frozen_topology_guard] (repair_service& local_repair) mutable -> future<> { auto data_centers = std::vector(); auto hosts = std::vector(); @@ -1583,7 +1583,7 @@ future<> repair::data_sync_repair_task_impl::run() { } future> repair::data_sync_repair_task_impl::expected_total_workload() const { - co_return _cfs_size ? std::make_optional(_ranges.size() * _cfs_size * smp::count) : std::nullopt; + co_return _cfs_size ? std::make_optional(_ranges.size() * _cfs_size * this_smp_shard_count()) : std::nullopt; } future<> repair_service::bootstrap_with_repair(locator::token_metadata_ptr tmptr, std::unordered_set bootstrap_tokens, service::frozen_topology_guard frozen_topology_guard) { diff --git a/repair/row_level.cc b/repair/row_level.cc index 9ae9d5a73c..d9c2ed3869 100644 --- a/repair/row_level.cc +++ b/repair/row_level.cc @@ -77,7 +77,7 @@ static shard_id get_dst_shard_id(uint32_t src_cpu_id, const rpc::optional> @@ -3744,7 +3744,7 @@ repair_service::update_history(tasks::task_id repair_id, table_id table_id, dht: } auto finished_shards = ++(rh.finished_ranges[table_id][range]); // Tablet repair runs only on one shard - if (finished_shards == smp::count || is_tablet) { + if (finished_shards == this_smp_shard_count() || is_tablet) { // All shards have finished repair the range. Send an rpc to ask peers to update system.repair_history table rlogger.debug("repair[{}]: Finished range {} for table {} on all shards, updating system.repair_history table, finished_shards={}", repair_id, range, table_id, finished_shards); @@ -3768,7 +3768,7 @@ future<> repair_service::cleanup_history(tasks::task_id repair_id) { future<> repair_service::load_history() { try { co_await get_db().local().get_tables_metadata().parallel_for_each_table(coroutine::lambda([&] (table_id table_uuid, lw_shared_ptr table) -> future<> { - auto shard = utils::uuid_xor_to_uint32(table_uuid.uuid()) % smp::count; + auto shard = utils::uuid_xor_to_uint32(table_uuid.uuid()) % this_smp_shard_count(); if (shard != this_shard_id()) { co_return; } diff --git a/replica/database.cc b/replica/database.cc index fd9f791ce8..80d05b6688 100644 --- a/replica/database.cc +++ b/replica/database.cc @@ -1016,7 +1016,7 @@ void database::update_keyspace(std::unique_ptr change) { } future database::prepare_update_keyspace_on_all_shards(sharded& sharded_db, const keyspace_metadata& ksm, const locator::pending_token_metadata& pending_token_metadata) { - keyspace_change_per_shard changes(smp::count); + keyspace_change_per_shard changes(this_smp_shard_count()); co_await modify_keyspace_on_all_shards(sharded_db, [&] (replica::database& db) -> future<> { auto& ks = db.find_keyspace(ksm.name()); auto new_ksm = ::make_lw_shared(ksm.name(), ksm.strategy_name(), ksm.strategy_options(), ksm.initial_tablets(), ksm.consistency_option(), ksm.durable_writes(), @@ -1279,9 +1279,9 @@ void database::remove(table& cf) noexcept { } global_table_ptr::global_table_ptr() { - _p.resize(smp::count); - _views.resize(smp::count); - _base.resize(smp::count); + _p.resize(this_smp_shard_count()); + _views.resize(this_smp_shard_count()); + _base.resize(this_smp_shard_count()); } void global_table_ptr::assign(database& db, table_id uuid) { @@ -1707,7 +1707,7 @@ void database::insert_keyspace(std::unique_ptr ks) { } future database::prepare_create_keyspace_on_all_shards(sharded& sharded_db, sharded& proxy, const keyspace_metadata& ks_metadata, const locator::pending_token_metadata& pending_token_metadata) { - created_keyspace_per_shard created(smp::count); + created_keyspace_per_shard created(this_smp_shard_count()); co_await modify_keyspace_on_all_shards(sharded_db, [&] (replica::database& db) -> future<> { auto ksm = keyspace_metadata::new_keyspace(ks_metadata); auto ks = co_await db.create_keyspace(ksm, proxy.local().get_erm_factory(), pending_token_metadata.local(), system_keyspace::no); @@ -3047,9 +3047,9 @@ future<> database::truncate_table_on_all_shards(sharded& sharded_db, s dblog.info("Truncating {}.{} {}snapshot", s->ks_name(), s->cf_name(), with_snapshot ? "with auto-" : "without "); std::vector>> table_states; - table_states.resize(smp::count); + table_states.resize(this_smp_shard_count()); - co_await coroutine::parallel_for_each(std::views::iota(0u, smp::count), [&] (unsigned shard) -> future<> { + co_await coroutine::parallel_for_each(std::views::iota(0u, this_smp_shard_count()), [&] (unsigned shard) -> future<> { table_states[shard] = co_await smp::submit_to(shard, [&] () -> future>> { auto& cf = *table_shards; auto& views = table_shards.views(); @@ -3905,7 +3905,7 @@ future>> database::sample_data_file // After the `exclusive_scan` later, this will say which range of chunks // (in the global "list" of chunks) belongs to which shard. // (Shard X owns range `global_offset[X] .. global_offset[X + 1]`). - std::vector global_offset(smp::count + 1); + std::vector global_offset(this_smp_shard_count() + 1); // Watch out: static lambda. Don't add captures to it. static auto size_in_chunks = [] (const sstables::shared_sstable& sst, uint64_t chunk_size) { diff --git a/replica/database.hh b/replica/database.hh index 43c1692e0f..5e8c999208 100644 --- a/replica/database.hh +++ b/replica/database.hh @@ -2295,7 +2295,7 @@ public: : _db(db) , _table_id(table_id) , _compaction_time(compaction_time) - , _contexts(smp::count) { + , _contexts(this_smp_shard_count()) { } virtual mutation_reader create_reader( schema_ptr schema, diff --git a/replica/distributed_loader.cc b/replica/distributed_loader.cc index b70b7dbd09..77b37f631d 100644 --- a/replica/distributed_loader.cc +++ b/replica/distributed_loader.cc @@ -260,7 +260,7 @@ distributed_loader::get_sstables_from(sharded& db, sstring ks start_dir(global_table, directory).get(); auto stop = deferred_stop(directory); - std::vector> sstables_on_shards(smp::count); + std::vector> sstables_on_shards(this_smp_shard_count()); lock_table(global_table, directory).get(); sstables::sstable_directory::process_flags flags { .need_mutate_level = true, diff --git a/replica/distributed_loader.hh b/replica/distributed_loader.hh index 24759b183a..0654b78e16 100644 --- a/replica/distributed_loader.hh +++ b/replica/distributed_loader.hh @@ -86,7 +86,7 @@ public: static future<> init_system_keyspace(sharded&, sharded&, sharded&); static future<> init_non_system_keyspaces(sharded& db, sharded& proxy, sharded& sys_ks); - // Scan sstables under upload directory. Return a vector with smp::count entries. + // Scan sstables under upload directory. Return a vector with this_smp_shard_count() entries. // Each entry with index of idx should be accessed on shard idx only. // Each entry contains a vector of sstables for this shard. // The table UUID is returned too. diff --git a/replica/multishard_query.cc b/replica/multishard_query.cc index 101e34a737..827001f323 100644 --- a/replica/multishard_query.cc +++ b/replica/multishard_query.cc @@ -213,8 +213,8 @@ public: , _cmd(cmd) , _ranges(ranges) , _trace_state(std::move(trace_state)) - , _semaphores(smp::count, nullptr) { - _readers.resize(smp::count); + , _semaphores(this_smp_shard_count(), nullptr) { + _readers.resize(this_smp_shard_count()); _permit.set_max_result_size(get_max_result_size()); if (!_erm->get_replication_strategy().is_vnode_based()) { @@ -405,7 +405,7 @@ future<> read_context::destroy_reader(stopped_reader reader) noexcept { } future<> read_context::stop() { - return parallel_for_each(smp::all_cpus(), [this] (unsigned shard) { + return parallel_for_each(this_smp_all_shards(), [this] (unsigned shard) { if (_readers[shard].rparts) { return _db.invoke_on(shard, [&rparts_fptr = _readers[shard].rparts] (replica::database& db) mutable { auto rparts = rparts_fptr.release(); @@ -625,7 +625,7 @@ future<> read_context::save_readers(mutation_reader::tracked_buffer unconsumed_b tracing::trace(_trace_state, "No compaction state to dismantle, partition exhausted", cs_stats); } - co_await parallel_for_each(std::views::iota(0u, smp::count), [this, &last_pos] (shard_id shard) { + co_await parallel_for_each(std::views::iota(0u, this_smp_shard_count()), [this, &last_pos] (shard_id shard) { auto& rm = _readers[shard]; if (rm.state == reader_state::successful_lookup || rm.state == reader_state::saving) { return save_reader(shard, last_pos); diff --git a/replica/table.cc b/replica/table.cc index 376aa09baa..0b66e100cf 100644 --- a/replica/table.cc +++ b/replica/table.cc @@ -4288,13 +4288,13 @@ future<> database::snapshot_table_on_all_shards(sharded& sharded_db, c co_return; } - auto orchestrator = std::hash()(name) % smp::count; + auto orchestrator = std::hash()(name) % this_smp_shard_count(); co_await smp::submit_to(orchestrator, [&] () -> future<> { auto& t = *table_shards; auto s = t.schema(); tlogger.debug("Taking snapshot of {}.{}: name={}", s->ks_name(), s->cf_name(), name); - std::vector sstable_sets(smp::count); + std::vector sstable_sets(this_smp_shard_count()); co_await writer->init(); co_await smp::invoke_on_all([&] -> future<> { diff --git a/replica/tables_metadata_lock.hh b/replica/tables_metadata_lock.hh index d5cb049ef7..08f6fefba2 100644 --- a/replica/tables_metadata_lock.hh +++ b/replica/tables_metadata_lock.hh @@ -18,7 +18,7 @@ namespace replica { class tables_metadata_lock_on_all_shards { std::vector>> _holders; public: - tables_metadata_lock_on_all_shards() : _holders(seastar::smp::count) {}; + tables_metadata_lock_on_all_shards() : _holders(seastar::this_smp_shard_count()) {}; void assign_lock(seastar::rwlock::holder&& h); }; diff --git a/service/direct_failure_detector/failure_detector.cc b/service/direct_failure_detector/failure_detector.cc index b7babca64e..079a35f93a 100644 --- a/service/direct_failure_detector/failure_detector.cc +++ b/service/direct_failure_detector/failure_detector.cc @@ -104,7 +104,7 @@ struct failure_detector::impl { // Number of workers on each shard. // We use this to decide where to create new workers (we pick a shard with the smallest number of workers). // Used on shard 0 only. - // The size of this vector is smp::count on shard 0 and it's empty on other shards. + // The size of this vector is this_smp_shard_count() on shard 0 and it's empty on other shards. std::vector _num_workers; // For each endpoint in the detected set, the shard of its worker. @@ -190,7 +190,7 @@ failure_detector::impl::impl( return; } - _num_workers.resize(smp::count, 0); + _num_workers.resize(this_smp_shard_count(), 0); _update_endpoint_fiber = update_endpoint_fiber(sg); } @@ -257,7 +257,7 @@ future<> failure_detector::impl::add_endpoint(pinger::endpoint_id ep) { // Pick a shard with the smallest number of workers to create a new worker. auto shard = std::distance(_num_workers.begin(), std::min_element(_num_workers.begin(), _num_workers.end())); - SCYLLA_ASSERT(_num_workers.size() == smp::count); + SCYLLA_ASSERT(_num_workers.size() == this_smp_shard_count()); ++_num_workers[shard]; auto [it, _] = _workers.emplace(ep, shard); @@ -282,7 +282,7 @@ future<> failure_detector::impl::remove_endpoint(pinger::endpoint_id ep) { auto shard = it->second; co_await _parent.container().invoke_on(shard, [ep] (failure_detector& fd) { return fd._impl->destroy_worker(ep); }); - SCYLLA_ASSERT(_num_workers.size() == smp::count); + SCYLLA_ASSERT(_num_workers.size() == this_smp_shard_count()); SCYLLA_ASSERT(shard < _num_workers.size()); --_num_workers[shard]; _workers.erase(it); diff --git a/service/mapreduce_service.cc b/service/mapreduce_service.cc index 2a04afa029..36b07374b6 100644 --- a/service/mapreduce_service.cc +++ b/service/mapreduce_service.cc @@ -228,7 +228,7 @@ public: std::optional next(const schema& s) { // If forced shard is set and supported, return all ranges for that shard - if (forced_shard.has_value() && forced_shard.value() < seastar::smp::count) { + if (forced_shard.has_value() && forced_shard.value() < seastar::this_smp_shard_count()) { if (forced_shard.value() != this_shard_id() || _range_idx == _partition_ranges.size()) { return std::nullopt; } else { @@ -390,7 +390,7 @@ future mapreduce_service::dispatch_to_shards( std::optional result; std::vector> futures; - for (const auto& s : smp::all_cpus()) { + for (const auto& s : this_smp_all_shards()) { futures.push_back(container().invoke_on(s, [req, tr_info] (auto& fs) { return fs.execute_on_this_shard(req, tr_info); })); diff --git a/service/misc_services.cc b/service/misc_services.cc index ace4d8bb82..acbee22429 100644 --- a/service/misc_services.cc +++ b/service/misc_services.cc @@ -119,7 +119,7 @@ void cache_hitrate_calculator::recalculate_timer() { } else { d = f.get(); } - p->run_on((this_shard_id() + 1) % smp::count, d); + p->run_on((this_shard_id() + 1) % this_smp_shard_count(), d); }); } diff --git a/service/storage_proxy.cc b/service/storage_proxy.cc index 6c6a27fa45..258dd5425f 100644 --- a/service/storage_proxy.cc +++ b/service/storage_proxy.cc @@ -1300,7 +1300,7 @@ static unsigned get_cas_shard(const schema& s, dht::token token, const locator:: if (const auto& rs = erm.get_replication_strategy(); rs.uses_tablets()) { const auto& tablet_map = erm.get_token_metadata().tablets().get_tablet_map(s.id()); const auto tablet_id = tablet_map.get_tablet_id(token); - return tablet_map.get_primary_replica(tablet_id, erm.get_topology()).shard % smp::count; + return tablet_map.get_primary_replica(tablet_id, erm.get_topology()).shard % this_smp_shard_count(); } else { on_internal_error(paxos::paxos_state::logger, format("failed to detect shard for reads for non-tablet-based rs {}, table {}.{}", @@ -7319,8 +7319,8 @@ const db::hints::host_filter& storage_proxy::get_hints_host_filter() const { future storage_proxy::create_hint_sync_point(std::vector target_hosts) const { db::hints::sync_point spoint; - spoint.regular_per_shard_rps.resize(smp::count); - spoint.mv_per_shard_rps.resize(smp::count); + spoint.regular_per_shard_rps.resize(this_smp_shard_count()); + spoint.mv_per_shard_rps.resize(this_smp_shard_count()); spoint.host_id = get_token_metadata_ptr()->get_my_id(); // sharded::invoke_on does not have a const-method version, so we cannot use it here @@ -7341,7 +7341,7 @@ future<> storage_proxy::wait_for_hint_sync_point(const db::hints::sync_point spo } std::vector sources; - sources.resize(smp::count); + sources.resize(this_smp_shard_count()); // If the timer is triggered, it will spawn a discarded future which triggers // abort sources on all shards. We need to make sure that this future diff --git a/service/storage_service.cc b/service/storage_service.cc index ce665e1726..6fecc20e74 100644 --- a/service/storage_service.cc +++ b/service/storage_service.cc @@ -1410,7 +1410,7 @@ future<> storage_service::initialize_done_topology_upgrade_state() { future<> storage_service::update_topology_with_local_metadata(raft::server& raft_server) { // TODO: include more metadata here - auto local_shard_count = smp::count; + auto local_shard_count = this_smp_shard_count(); auto local_ignore_msb = _db.local().get_config().murmur3_partitioner_ignore_msb_bits(); auto local_release_version = version::release(); auto local_supported_features = _feature_service.supported_feature_set() | std::ranges::to>(); @@ -1593,7 +1593,7 @@ future<> storage_service::join_topology(sharded& proxy, app_states.emplace(gms::application_state::STATUS, versioned_value::normal(my_tokens)); } app_states.emplace(gms::application_state::SNITCH_NAME, versioned_value::snitch_name(_snitch.local()->get_name())); - app_states.emplace(gms::application_state::SHARD_COUNT, versioned_value::shard_count(smp::count)); + app_states.emplace(gms::application_state::SHARD_COUNT, versioned_value::shard_count(this_smp_shard_count())); app_states.emplace(gms::application_state::IGNORE_MSB_BITS, versioned_value::ignore_msb_bits(_db.local().get_config().murmur3_partitioner_ignore_msb_bits())); for (auto&& s : _snitch.local()->get_app_states()) { @@ -1628,7 +1628,7 @@ future<> storage_service::join_topology(sharded& proxy, .release_version = version::release(), .num_tokens = _db.local().get_config().join_ring() ? _db.local().get_config().num_tokens() : 0, .tokens_string = _db.local().get_config().join_ring() ? _db.local().get_config().initial_token() : sstring(), - .shard_count = smp::count, + .shard_count = this_smp_shard_count(), .ignore_msb = _db.local().get_config().murmur3_partitioner_ignore_msb_bits(), .supported_features = _feature_service.supported_feature_set() | std::ranges::to>(), .request_id = request_id, @@ -2148,7 +2148,7 @@ future storage_service::prepare_token_metadata_change(mut // and clone to all shards; // // TODO: at the moment create on shard 0 first - // but in the future we may want to use hash() % smp::count + // but in the future we may want to use hash() % this_smp_shard_count() // to evenly distribute the load. auto replications = schema_getter.get_keyspaces_replication(); for (const auto& [ks_name, rs] : replications) { @@ -5757,7 +5757,7 @@ future storage_service::load_stats_for_tablet_based_tables( struct alignas(64) aligned_tablet_size { uint64_t size = 0; }; - std::vector tablet_sizes_per_shard(smp::count); + std::vector tablet_sizes_per_shard(this_smp_shard_count()); // Each node combines a per-table load map from all of its shards and returns it to the coordinator. // So if there are 1k nodes, there will be 1k RPCs in total. @@ -6743,7 +6743,7 @@ future<> storage_service::start_maintenance_mode() { set_mode(mode::MAINTENANCE); return mutate_token_metadata([this] (mutable_token_metadata_ptr token_metadata) -> future<> { - token_metadata->update_topology(my_host_id(), _snitch.local()->get_location(), locator::node::state::normal, smp::count); + token_metadata->update_topology(my_host_id(), _snitch.local()->get_location(), locator::node::state::normal, this_smp_shard_count()); return token_metadata->update_normal_tokens({ dht::token{} }, my_host_id()); }, acquire_merge_lock::yes); } diff --git a/service/storage_service.hh b/service/storage_service.hh index 3729a8c3cc..7b6bac8284 100644 --- a/service/storage_service.hh +++ b/service/storage_service.hh @@ -148,10 +148,10 @@ using start_hint_manager = seastar::bool_class; using loosen_constraints = seastar::bool_class; struct token_metadata_change { - std::vector pending_token_metadata_ptr{smp::count}; - std::vector> pending_effective_replication_maps{smp::count}; - std::vector> pending_table_erms{smp::count}; - std::vector> pending_view_erms{smp::count}; + std::vector pending_token_metadata_ptr{this_smp_shard_count()}; + std::vector> pending_effective_replication_maps{this_smp_shard_count()}; + std::vector> pending_table_erms{this_smp_shard_count()}; + std::vector> pending_view_erms{this_smp_shard_count()}; std::unordered_set open_sessions; future<> destroy(); diff --git a/sstables/compressor.cc b/sstables/compressor.cc index a0c4fda17c..7a0a17401e 100644 --- a/sstables/compressor.cc +++ b/sstables/compressor.cc @@ -993,7 +993,7 @@ default_sstable_compressor_factory::default_sstable_compressor_factory(config cf : _cfg(std::move(cfg)) , _holder(std::make_unique(_cfg)) { - for (shard_id i = 0; i < smp::count; ++i) { + for (shard_id i = 0; i < this_smp_shard_count(); ++i) { auto numa_id = _cfg.numa_config[i]; _numa_groups.resize(std::max(_numa_groups.size(), numa_id + 1)); _numa_groups[numa_id].push_back(i); diff --git a/sstables/generation_type.hh b/sstables/generation_type.hh index 0d97b81372..c427e2a9c7 100644 --- a/sstables/generation_type.hh +++ b/sstables/generation_type.hh @@ -136,7 +136,7 @@ public: } else { hint = gen.as_int(); } - return hint % smp::count == seastar::this_shard_id(); + return hint % this_smp_shard_count() == seastar::this_shard_id(); } }; diff --git a/sstables/sstable_directory.cc b/sstables/sstable_directory.cc index b66e6b0112..ae2303de00 100644 --- a/sstables/sstable_directory.cc +++ b/sstables/sstable_directory.cc @@ -138,7 +138,7 @@ sstable_directory::sstable_directory(replica::table& table, std::move(sstables))) , _sharder_ptr(std::make_unique(table.shared_from_this())) , _sharder(*_sharder_ptr) - , _unshared_remote_sstables(smp::count) + , _unshared_remote_sstables(this_smp_shard_count()) {} sstable_directory::sstable_directory(sstables_manager& manager, @@ -174,7 +174,7 @@ sstable_directory::sstable_directory(sstables_manager& manager, , _lister(make_components_lister()) , _sharder_ptr(std::holds_alternative(sharder) ? std::move(std::get(sharder)) : nullptr) , _sharder(_sharder_ptr ? *_sharder_ptr : *std::get(sharder)) - , _unshared_remote_sstables(smp::count) + , _unshared_remote_sstables(this_smp_shard_count()) {} void sstable_directory::filesystem_components_lister::handle(sstables::entry_descriptor desc, fs::path filename) { @@ -507,7 +507,7 @@ future<> sstable_directory::sstables_registry_components_lister::garbage_collect future<> sstable_directory::move_foreign_sstables(sharded& source_directory) { - return parallel_for_each(std::views::iota(0u, smp::count), [this, &source_directory] (unsigned shard_id) mutable { + return parallel_for_each(std::views::iota(0u, this_smp_shard_count()), [this, &source_directory] (unsigned shard_id) mutable { auto info_vec = std::exchange(_unshared_remote_sstables[shard_id], {}); if (info_vec.empty()) { return make_ready_future<>(); diff --git a/sstables/sstable_directory.hh b/sstables/sstable_directory.hh index 16f2c48c86..ce4e864aed 100644 --- a/sstables/sstable_directory.hh +++ b/sstables/sstable_directory.hh @@ -260,7 +260,7 @@ public: // scans a directory containing SSTables. Every generation that is believed to belong to this // shard is processed, the ones that are not are skipped. Potential pertinence is decided as - // generation % smp::count. + // generation % this_smp_shard_count(). // // Once this method return, every SSTable that this shard processed can be in one of 3 states: // - unshared, local: not a shared SSTable, and indeed belongs to this shard. diff --git a/sstables_loader.cc b/sstables_loader.cc index e19a847259..a8df65a123 100644 --- a/sstables_loader.cc +++ b/sstables_loader.cc @@ -258,7 +258,7 @@ private: } future download_fully_contained_sstables(std::vector sstables) const { - sst_classification_info downloaded_sstables(smp::count); + sst_classification_info downloaded_sstables(this_smp_shard_count()); for (const auto& sstable : sstables) { auto min_info = co_await download_sstable(_db.local(), _table, sstable, llog); downloaded_sstables[min_info.shard].emplace_back(min_info); @@ -832,7 +832,7 @@ future<> sstables_loader::download_task_impl::run() { llog.debug("Loading sstables from {}({}/{})", _endpoint, _bucket, _prefix); auto ep_type = _loader.local()._storage_manager.get_endpoint_type(_endpoint); - std::vector shard_aborts(smp::count); + std::vector shard_aborts(this_smp_shard_count()); auto [ table_id, sstables_on_shards ] = co_await replica::distributed_loader::get_sstables_from_object_store(_loader.local()._db, _ks, _cf, _sstables, _endpoint, ep_type, _bucket, _prefix, cfg, [&] { return &shard_aborts[this_shard_id()]; }); @@ -1012,13 +1012,13 @@ future<> sstables_loader::download_tablet_sstables(locator::global_tablet_id tid std::move(ent.second), restore_cfg.endpoint, ep_type, restore_cfg.bucket, std::move(ent.first), cfg, [&] { return nullptr; }).then_unpack([] (table_id, auto sstables) { return make_ready_future>(std::move(sstables)); }); - }, std::vector(smp::count), [&] (std::vector a, std::vector b) { + }, std::vector(this_smp_shard_count()), [&] (std::vector a, std::vector b) { // We can't move individual elements of b[i], because these // are lw_shared_ptr-s collected on another shard. So we move // the whole sstables_col here so that subsequent code will // walk over it and move the pointers where it wants on proper // shard. - for (unsigned i = 0; i < smp::count; i++) { + for (unsigned i = 0; i < this_smp_shard_count(); i++) { a[i].push_back(std::move(b[i])); } return a; @@ -1032,7 +1032,7 @@ future<> sstables_loader::download_tablet_sstables(locator::global_tablet_id tid sst_chunk.push_back(std::move(sst)); } } - std::vector> local_min_infos(smp::count); + std::vector> local_min_infos(this_smp_shard_count()); co_await max_concurrent_for_each(sst_chunk, 16, [&loader, tid, &local_min_infos](const auto& sst) -> future<> { auto& table = loader._db.local().find_column_family(tid.table); auto min_info = co_await download_sstable(loader._db.local(), table, sst, llog); @@ -1040,7 +1040,7 @@ future<> sstables_loader::download_tablet_sstables(locator::global_tablet_id tid }); co_return local_min_infos; }, - std::vector>(smp::count), + std::vector>(this_smp_shard_count()), [](auto init, auto&& item) -> std::vector> { for (std::size_t i = 0; i < item.size(); ++i) { init[i].append_range(std::move(item[i])); diff --git a/tasks/task_manager.hh b/tasks/task_manager.hh index bca6854e7a..907a910476 100644 --- a/tasks/task_manager.hh +++ b/tasks/task_manager.hh @@ -413,7 +413,7 @@ public: template static future invoke_on_task(sharded& tm, task_id id, std::function (task_manager::task_variant, virtual_task_hint)> func) { std::optional res; - co_await coroutine::parallel_for_each(std::views::iota(0u, smp::count), [&tm, id, &res, &func] (unsigned shard) -> future<> { + co_await coroutine::parallel_for_each(std::views::iota(0u, this_smp_shard_count()), [&tm, id, &res, &func] (unsigned shard) -> future<> { auto local_res = co_await tm.invoke_on(shard, [id, func] (const task_manager& local_tm) -> future> { const auto& all_tasks = local_tm.get_local_tasks(); if (auto it = all_tasks.find(id); it != all_tasks.end()) { diff --git a/test/boost/address_map_test.cc b/test/boost/address_map_test.cc index 6ce4d76aa5..c8a53b1ac1 100644 --- a/test/boost/address_map_test.cc +++ b/test/boost/address_map_test.cc @@ -254,8 +254,8 @@ SEASTAR_THREAD_TEST_CASE(test_address_map_operations) { } SEASTAR_THREAD_TEST_CASE(test_address_map_replication) { - if (smp::count < 2) { - std::cerr << "Cannot run test " << get_name() << " with smp::count < 2" << std::endl; + if (this_smp_shard_count() < 2) { + std::cerr << "Cannot run test " << get_name() << " with this_smp_shard_count() < 2" << std::endl; return; } @@ -353,8 +353,8 @@ SEASTAR_THREAD_TEST_CASE(test_address_map_replication) { } SEASTAR_THREAD_TEST_CASE(test_address_map_replication_efficiency) { - if (smp::count < 2) { - std::cerr << "Cannot run test " << get_name() << " with smp::count < 2" << std::endl; + if (this_smp_shard_count() < 2) { + std::cerr << "Cannot run test " << get_name() << " with this_smp_shard_count() < 2" << std::endl; return; } @@ -397,8 +397,8 @@ SEASTAR_THREAD_TEST_CASE(test_address_map_replication_efficiency) { } SEASTAR_THREAD_TEST_CASE(test_address_map_expiry_change_keeps_addr_mapping) { - if (smp::count < 2) { - std::cerr << "Cannot run test " << get_name() << " with smp::count < 2" << std::endl; + if (this_smp_shard_count() < 2) { + std::cerr << "Cannot run test " << get_name() << " with this_smp_shard_count() < 2" << std::endl; return; } diff --git a/test/boost/commitlog_cleanup_test.cc b/test/boost/commitlog_cleanup_test.cc index 9cb0906463..e6074c355a 100644 --- a/test/boost/commitlog_cleanup_test.cc +++ b/test/boost/commitlog_cleanup_test.cc @@ -169,7 +169,7 @@ SEASTAR_TEST_CASE(test_commitlog_cleanups) { // Test that commitlog cleanup records are deleted when they become irrelevant. SEASTAR_TEST_CASE(test_commitlog_cleanup_record_gc) { - BOOST_REQUIRE_EQUAL(smp::count, 1); + BOOST_REQUIRE_EQUAL(this_smp_shard_count(), 1); auto cfg = cql_test_config(); cfg.db_config->auto_snapshot.set(false); cfg.db_config->commitlog_sync.set("batch"); diff --git a/test/boost/commitlog_test.cc b/test/boost/commitlog_test.cc index a8bfa340b7..20c84092c0 100644 --- a/test/boost/commitlog_test.cc +++ b/test/boost/commitlog_test.cc @@ -573,7 +573,7 @@ SEASTAR_TEST_CASE(test_commitlog_chunk_corruption2){ SEASTAR_TEST_CASE(test_commitlog_chunk_corruption3){ commitlog::config cfg; cfg.commitlog_segment_size_in_mb = 1; - cfg.commitlog_total_space_in_mb = 2 * smp::count; + cfg.commitlog_total_space_in_mb = 2 * this_smp_shard_count(); cfg.allow_going_over_size_limit = false; return cl_test(cfg, [](commitlog& log) -> future<> { @@ -633,7 +633,7 @@ SEASTAR_TEST_CASE(test_commitlog_chunk_corruption3){ SEASTAR_TEST_CASE(test_commitlog_replay_single_large_mutation){ commitlog::config cfg; cfg.commitlog_segment_size_in_mb = 4; - cfg.commitlog_total_space_in_mb = 2 * cfg.commitlog_segment_size_in_mb * smp::count; + cfg.commitlog_total_space_in_mb = 2 * cfg.commitlog_segment_size_in_mb * this_smp_shard_count(); cfg.allow_going_over_size_limit = false; return cl_test(cfg, [](commitlog& log) -> future<> { @@ -696,7 +696,7 @@ SEASTAR_TEST_CASE(test_commitlog_replay_single_large_mutation){ SEASTAR_TEST_CASE(test_commitlog_replay_large_mutations){ commitlog::config cfg; cfg.commitlog_segment_size_in_mb = 14; - cfg.commitlog_total_space_in_mb = 2 * cfg.commitlog_segment_size_in_mb * smp::count; + cfg.commitlog_total_space_in_mb = 2 * cfg.commitlog_segment_size_in_mb * this_smp_shard_count(); cfg.allow_going_over_size_limit = false; return cl_test(cfg, [](commitlog& log) -> future<> { @@ -1115,7 +1115,7 @@ SEASTAR_TEST_CASE(test_commitlog_add_entries) { SEASTAR_TEST_CASE(test_commitlog_entry_offsets) { commitlog::config cfg; cfg.commitlog_segment_size_in_mb = 1; - cfg.commitlog_total_space_in_mb = 2 * smp::count; + cfg.commitlog_total_space_in_mb = 2 * this_smp_shard_count(); cfg.allow_going_over_size_limit = false; return cl_test(cfg, [](commitlog& log) -> future<> { @@ -1157,7 +1157,7 @@ SEASTAR_TEST_CASE(test_commitlog_entry_offsets) { SEASTAR_TEST_CASE(test_commitlog_max_segment_size) { commitlog::config cfg; cfg.commitlog_segment_size_in_mb = 1; - cfg.commitlog_total_space_in_mb = 2 * smp::count; + cfg.commitlog_total_space_in_mb = 2 * this_smp_shard_count(); cfg.allow_going_over_size_limit = false; return cl_test(cfg, [max_size = cfg.commitlog_segment_size_in_mb](commitlog& log) -> future<> { @@ -1236,7 +1236,7 @@ SEASTAR_TEST_CASE(test_commitlog_deadlock_in_recycle) { constexpr auto max_size_mb = 2; cfg.commitlog_segment_size_in_mb = max_size_mb; // ensure total size per shard is not multiple of segment size. - cfg.commitlog_total_space_in_mb = 5 * smp::count; + cfg.commitlog_total_space_in_mb = 5 * this_smp_shard_count(); cfg.commitlog_sync_period_in_ms = 10; cfg.allow_going_over_size_limit = false; cfg.use_o_dsync = true; // make sure we pre-allocate. @@ -1311,7 +1311,7 @@ SEASTAR_TEST_CASE(test_commitlog_shutdown_during_wait) { constexpr auto max_size_mb = 2; cfg.commitlog_segment_size_in_mb = max_size_mb; // ensure total size per shard is not multiple of segment size. - cfg.commitlog_total_space_in_mb = 5 * smp::count; + cfg.commitlog_total_space_in_mb = 5 * this_smp_shard_count(); cfg.commitlog_sync_period_in_ms = 10; cfg.allow_going_over_size_limit = false; cfg.use_o_dsync = true; // make sure we pre-allocate. @@ -1378,7 +1378,7 @@ SEASTAR_TEST_CASE(test_commitlog_deadlock_with_flush_threshold) { constexpr auto max_size_mb = 1; cfg.commitlog_segment_size_in_mb = max_size_mb; - cfg.commitlog_total_space_in_mb = 2 * max_size_mb * smp::count; + cfg.commitlog_total_space_in_mb = 2 * max_size_mb * this_smp_shard_count(); cfg.commitlog_sync_period_in_ms = 10; cfg.allow_going_over_size_limit = false; cfg.use_o_dsync = true; // make sure we pre-allocate. @@ -1427,7 +1427,7 @@ static future<> do_test_exception_in_allocate_ex(bool do_file_delete) { constexpr auto max_size_mb = 1; cfg.commitlog_segment_size_in_mb = max_size_mb; - cfg.commitlog_total_space_in_mb = 2 * max_size_mb * smp::count; + cfg.commitlog_total_space_in_mb = 2 * max_size_mb * this_smp_shard_count(); cfg.commitlog_sync_period_in_ms = 10; cfg.allow_going_over_size_limit = false; // #9348 - now can enforce size limit always cfg.use_o_dsync = true; // make sure we pre-allocate. @@ -1573,7 +1573,7 @@ SEASTAR_TEST_CASE(test_delete_recycled_segment_removes_size) { constexpr auto max_size_mb = 1; cfg.commitlog_segment_size_in_mb = max_size_mb; - cfg.commitlog_total_space_in_mb = 2 * max_size_mb * smp::count; + cfg.commitlog_total_space_in_mb = 2 * max_size_mb * this_smp_shard_count(); cfg.allow_going_over_size_limit = false; // #9348 - now can enforce size limit always cfg.use_o_dsync = true; // make sure we pre-allocate. @@ -1610,7 +1610,7 @@ SEASTAR_TEST_CASE(test_delete_recycled_segment_removes_size) { auto max_file_size_bytes = (max_size_mb * 1024 * 1024); // we might be one segment over disk threshold. - auto max_shard_size_bytes = max_file_size_bytes + (cfg.commitlog_total_space_in_mb * 1024 * 1024) / smp::count; + auto max_shard_size_bytes = max_file_size_bytes + (cfg.commitlog_total_space_in_mb * 1024 * 1024) / this_smp_shard_count(); // Add a bunch of fake segments (pretending replayed). The total footprint will be much // more than above limit. @@ -1648,7 +1648,7 @@ SEASTAR_TEST_CASE(test_wait_for_delete) { constexpr auto max_size_mb = 1; cfg.commitlog_segment_size_in_mb = max_size_mb; - cfg.commitlog_total_space_in_mb = 8 * max_size_mb * smp::count; + cfg.commitlog_total_space_in_mb = 8 * max_size_mb * this_smp_shard_count(); cfg.allow_going_over_size_limit = false; // #9348 - now can enforce size limit always cfg.use_o_dsync = true; // make sure we pre-allocate. @@ -1723,7 +1723,7 @@ SEASTAR_TEST_CASE(test_commitlog_max_data_lifetime) { constexpr auto max_size_mb = 1; cfg.commitlog_segment_size_in_mb = max_size_mb; - cfg.commitlog_total_space_in_mb = 2 * max_size_mb * smp::count; + cfg.commitlog_total_space_in_mb = 2 * max_size_mb * this_smp_shard_count(); cfg.commitlog_sync_period_in_ms = 10; cfg.commitlog_data_max_lifetime_in_seconds = 2; cfg.allow_going_over_size_limit = false; @@ -1777,7 +1777,7 @@ SEASTAR_TEST_CASE(test_commitlog_update_max_data_lifetime) { constexpr auto max_size_mb = 1; cfg.commitlog_segment_size_in_mb = max_size_mb; - cfg.commitlog_total_space_in_mb = 2 * max_size_mb * smp::count; + cfg.commitlog_total_space_in_mb = 2 * max_size_mb * this_smp_shard_count(); cfg.commitlog_sync_period_in_ms = 10; cfg.commitlog_data_max_lifetime_in_seconds = std::nullopt; cfg.allow_going_over_size_limit = false; @@ -1840,7 +1840,7 @@ static future<> do_test_oversized_entry(size_t max_size_mb) { commitlog::config cfg; cfg.commitlog_segment_size_in_mb = max_size_mb; - cfg.commitlog_total_space_in_mb = 8 * max_size_mb * smp::count; + cfg.commitlog_total_space_in_mb = 8 * max_size_mb * this_smp_shard_count(); cfg.allow_going_over_size_limit = false; cfg.allow_fragmented_entries = true; cfg.use_o_dsync = false; @@ -1938,7 +1938,7 @@ static future<> test_oversized(size_t n_entries, size_t max_size_mb, std::functi commitlog::config cfg; cfg.commitlog_segment_size_in_mb = max_size_mb; - cfg.commitlog_total_space_in_mb = 8 * n_entries * max_size_mb * smp::count; + cfg.commitlog_total_space_in_mb = 8 * n_entries * max_size_mb * this_smp_shard_count(); cfg.allow_going_over_size_limit = false; cfg.allow_fragmented_entries = true; cfg.use_o_dsync = false; @@ -2185,7 +2185,7 @@ SEASTAR_TEST_CASE(test_commitlog_handle_replayed_segments) { // easily exceed the CI timeout of 15 minutes (SCYLLADB-1496). constexpr uint64_t max_size_mb = 128; - cfg.commitlog_total_space_in_mb = max_size_mb * smp::count; + cfg.commitlog_total_space_in_mb = max_size_mb * this_smp_shard_count(); cfg.allow_going_over_size_limit = false; cfg.commitlog_sync_period_in_ms = 1; @@ -2239,7 +2239,7 @@ SEASTAR_TEST_CASE(test_commitlog_release_large_mutation_segments) { constexpr uint64_t max_size_mb = 8; cfg.commitlog_segment_size_in_mb = max_size_mb; - cfg.commitlog_total_space_in_mb = 8 * 4 * max_size_mb * smp::count; + cfg.commitlog_total_space_in_mb = 8 * 4 * max_size_mb * this_smp_shard_count(); cfg.allow_going_over_size_limit = false; cfg.allow_fragmented_entries = true; cfg.use_o_dsync = false; diff --git a/test/boost/cql_query_test.cc b/test/boost/cql_query_test.cc index fd439b9910..5ed6a20442 100644 --- a/test/boost/cql_query_test.cc +++ b/test/boost/cql_query_test.cc @@ -3809,7 +3809,7 @@ SEASTAR_TEST_CASE(test_cache_bypass) { auto with_cache = run_and_examine_cache_read_stats_change(e, "t", [] (cql_test_env& e) { e.execute_cql("SELECT * FROM t").get(); }); - BOOST_REQUIRE(with_cache >= smp::count); // scan may make multiple passes per shard + BOOST_REQUIRE(with_cache >= this_smp_shard_count()); // scan may make multiple passes per shard auto without_cache = run_and_examine_cache_read_stats_change(e, "t", [] (cql_test_env& e) { e.execute_cql("SELECT * FROM t BYPASS CACHE").get(); }); @@ -5986,7 +5986,7 @@ bool has_tablet_routing(::shared_ptr re } SEASTAR_TEST_CASE(test_sending_tablet_info_unprepared_insert) { - BOOST_ASSERT(smp::count == 2); + BOOST_ASSERT(this_smp_shard_count() == 2); return do_with_cql_env_thread([](cql_test_env& e) { e.execute_cql("create keyspace ks_tablet with replication = {'class': 'NetworkTopologyStrategy', 'replication_factor': 1 } and tablets = {'initial': 8};").get(); e.execute_cql("create table ks_tablet.test_tablet (pk int, ck int, v int, PRIMARY KEY (pk, ck));").get(); @@ -6073,7 +6073,7 @@ SEASTAR_TEST_CASE(test_sending_tablet_info_insert) { auto pk2 = partition_key::from_singular(*sptr, int32_t(2)); unsigned local_shard2 = sptr->table().shard_for_reads(dht::get_token(*sptr, pk2.view())); - unsigned foreign_shard = (local_shard2 + 1) % smp::count; + unsigned foreign_shard = (local_shard2 + 1) % this_smp_shard_count(); smp::submit_to(foreign_shard, [&] { return seastar::async([&] { @@ -6099,7 +6099,7 @@ SEASTAR_TEST_CASE(test_sending_tablet_info_select) { auto pk = partition_key::from_singular(*sptr, int32_t(1)); unsigned local_shard = sptr->table().shard_for_reads(dht::get_token(*sptr, pk.view())); - unsigned foreign_shard = (local_shard + 1) % smp::count; + unsigned foreign_shard = (local_shard + 1) % this_smp_shard_count(); smp::submit_to(local_shard, [&] { return seastar::async([&] { @@ -6135,7 +6135,7 @@ SEASTAR_TEST_CASE(test_sending_tablet_info_select) { // (not the tablet shard). This way local_client_state() belongs to the current // shard, and move_to_other_shard() is called on the owning shard. SEASTAR_TEST_CASE(test_tablet_routing_info_after_cas_shard_bounce) { - BOOST_REQUIRE_GT(smp::count, 1u); + BOOST_REQUIRE_GT(this_smp_shard_count(), 1u); return do_with_cql_env_thread([](cql_test_env& e) { e.execute_cql("create keyspace ks_tablet with replication = " "{'class': 'NetworkTopologyStrategy', 'replication_factor': 1} " @@ -6143,12 +6143,12 @@ SEASTAR_TEST_CASE(test_tablet_routing_info_after_cas_shard_bounce) { // Create dummy tables until the next table's single tablet lands on // a shard other than ours. Each dummy table occupies one shard in the - // load balancer, so after at most smp::count dummies shard 0 (or + // load balancer, so after at most this_smp_shard_count() dummies shard 0 (or // whichever shard we're on) is no longer the least loaded. schema_ptr schema; unsigned tablet_shard; for (unsigned i = 0; ; ++i) { - BOOST_REQUIRE_MESSAGE(i <= smp::count, "Could not place tablet on a foreign shard"); + BOOST_REQUIRE_MESSAGE(i <= this_smp_shard_count(), "Could not place tablet on a foreign shard"); auto tbl = format("tbl_{}", i); e.execute_cql(format("create table ks_tablet.{} (pk int PRIMARY KEY, v int);", tbl)).get(); schema = e.local_db().find_schema("ks_tablet", tbl); diff --git a/test/boost/database_test.cc b/test/boost/database_test.cc index 39a4b81fae..0e63888381 100644 --- a/test/boost/database_test.cc +++ b/test/boost/database_test.cc @@ -115,8 +115,8 @@ SEASTAR_TEST_CASE(test_safety_after_truncate) { std::vector keys_per_shard; std::vector pranges_per_shard; - keys_per_shard.resize(smp::count); - pranges_per_shard.resize(smp::count); + keys_per_shard.resize(this_smp_shard_count()); + pranges_per_shard.resize(this_smp_shard_count()); for (uint32_t i = 1; i <= 1000; ++i) { auto pkey = partition_key::from_single_value(*s, to_bytes(fmt::format("key{}", i))); mutation m(s, pkey); @@ -204,7 +204,7 @@ SEASTAR_TEST_CASE(test_truncate_saves_replay_position) { auto cfg = make_shared(); cfg->auto_snapshot.set(false); return do_with_cql_env_thread([] (cql_test_env& e) { - BOOST_REQUIRE_GT(smp::count, 1); + BOOST_REQUIRE_GT(this_smp_shard_count(), 1); const sstring ks_name = "ks"; const sstring cf_name = "cf"; e.execute_cql(fmt::format("CREATE TABLE {}.{} (k TEXT PRIMARY KEY, v INT);", ks_name, cf_name)).get(); @@ -216,7 +216,7 @@ SEASTAR_TEST_CASE(test_truncate_saves_replay_position) { auto rows = dynamic_pointer_cast(res); BOOST_REQUIRE(rows); auto row_count = rows->rs().result_set().size(); - BOOST_REQUIRE_EQUAL(row_count, smp::count); + BOOST_REQUIRE_EQUAL(row_count, this_smp_shard_count()); }, cfg); } @@ -230,9 +230,9 @@ SEASTAR_TEST_CASE(test_querying_with_limits) { auto uuid = s->id(); std::vector keys_per_shard; std::vector pranges_per_shard; - keys_per_shard.resize(smp::count); - pranges_per_shard.resize(smp::count); - for (uint32_t i = 1; i <= 3 * smp::count; ++i) { + keys_per_shard.resize(this_smp_shard_count()); + pranges_per_shard.resize(this_smp_shard_count()); + for (uint32_t i = 1; i <= 3 * this_smp_shard_count(); ++i) { auto pkey = partition_key::from_single_value(*s, to_bytes(format("key{:d}", i))); mutation m(s, pkey); m.partition().apply(tombstone(api::timestamp_type(1), gc_clock::now())); @@ -240,7 +240,7 @@ SEASTAR_TEST_CASE(test_querying_with_limits) { auto shard = table.shard_for_reads(m.token()); pranges_per_shard[shard].emplace_back(dht::partition_range::make_singular(dht::decorate_key(*s, std::move(pkey)))); } - for (uint32_t i = 3 * smp::count; i <= 8 * smp::count; ++i) { + for (uint32_t i = 3 * this_smp_shard_count(); i <= 8 * this_smp_shard_count(); ++i) { auto pkey = partition_key::from_single_value(*s, to_bytes(format("key{:d}", i))); mutation m(s, pkey); m.set_clustered_cell(clustering_key_prefix::make_empty(), "v", int32_t(42), 1); @@ -1469,10 +1469,10 @@ SEASTAR_TEST_CASE(populate_from_quarantine_works) { auto& cf = db.find_column_family("ks", "cf"); return cf.flush(); }); - auto shard = tests::random::get_int(0, smp::count); + auto shard = tests::random::get_int(0, this_smp_shard_count()); auto found = false; - for (unsigned i = 0; i < smp::count && !found; i++) { - found = co_await db.invoke_on((shard + i) % smp::count, [] (replica::database& db) -> future { + for (unsigned i = 0; i < this_smp_shard_count() && !found; i++) { + found = co_await db.invoke_on((shard + i) % this_smp_shard_count(), [] (replica::database& db) -> future { auto& cf = db.find_column_family("ks", "cf"); bool found = false; co_await cf.parallel_foreach_compaction_group_view([&] (compaction::compaction_group_view& ts) -> future<> { @@ -1519,10 +1519,10 @@ SEASTAR_TEST_CASE(snapshot_with_quarantine_works) { }; // move a random sstable to quarantine - auto shard = tests::random::get_int(0, smp::count); + auto shard = tests::random::get_int(0, this_smp_shard_count()); auto found = false; - for (unsigned i = 0; i < smp::count; i++) { - co_await db.invoke_on((shard + i) % smp::count, [&] (replica::database& db) -> future<> { + for (unsigned i = 0; i < this_smp_shard_count(); i++) { + co_await db.invoke_on((shard + i) % this_smp_shard_count(), [&] (replica::database& db) -> future<> { auto& cf = db.find_column_family("ks", "cf"); co_await cf.parallel_foreach_compaction_group_view([&] (compaction::compaction_group_view& ts) -> future<> { auto sstables = co_await in_strategy_sstables(ts); @@ -2332,7 +2332,7 @@ SEASTAR_TEST_CASE(replica_read_timeout_no_exception) { // Take all semaphore resources and add an active permit // Ensures that all new subsequent reads will be queued. std::vector>> dummy_permits; - for (shard_id shard = 0; shard < smp::count; ++shard) { + for (shard_id shard = 0; shard < this_smp_shard_count(); ++shard) { dummy_permits.emplace_back(); } e.db().invoke_on_all([&] (replica::database& db) -> future<> { diff --git a/test/boost/gossiping_property_file_snitch_test.cc b/test/boost/gossiping_property_file_snitch_test.cc index 9b30f51717..c9be2b27a4 100644 --- a/test/boost/gossiping_property_file_snitch_test.cc +++ b/test/boost/gossiping_property_file_snitch_test.cc @@ -45,11 +45,11 @@ future<> one_test(const std::string& property_fname, bool exp_result) { if (exp_result) { BOOST_CHECK_NO_THROW(co_await start()); - std::vector> dc_racks(smp::count); + std::vector> dc_racks(this_smp_shard_count()); co_await snitch.invoke_on_all([&] (snitch_ptr& inst) { dc_racks[this_shard_id()] = {inst->get_datacenter(), inst->get_rack()}; }); - for (unsigned i = 1; i < smp::count; ++i) { + for (unsigned i = 1; i < this_smp_shard_count(); ++i) { BOOST_REQUIRE_EQUAL(dc_racks[i], dc_racks[0]); } } else { diff --git a/test/boost/hint_test.cc b/test/boost/hint_test.cc index ae121782ba..dd3599d56d 100644 --- a/test/boost/hint_test.cc +++ b/test/boost/hint_test.cc @@ -163,13 +163,13 @@ SEASTAR_TEST_CASE(test_hint_sync_point_faithful_reserialization) { spoint.regular_per_shard_rps[1][addr2] = db::replay_position(); spoint.mv_per_shard_rps[0][addr2] = db::replay_position(); - // If the sync point contains information about less shards than smp::count, + // If the sync point contains information about less shards than this_smp_shard_count(), // the missing shards are filled with zero. Do it here manually so that // we can compare spoint with decoded_spoint. - const unsigned adjusted_count = std::max(encoded_shard_count, smp::count); + const unsigned adjusted_count = std::max(encoded_shard_count, this_smp_shard_count()); spoint.regular_per_shard_rps.resize(adjusted_count); spoint.mv_per_shard_rps.resize(adjusted_count); - for (unsigned s = encoded_shard_count; s < smp::count; s++) { + for (unsigned s = encoded_shard_count; s < this_smp_shard_count(); s++) { spoint.regular_per_shard_rps[s][addr1] = db::replay_position(); spoint.regular_per_shard_rps[s][addr2] = db::replay_position(); spoint.mv_per_shard_rps[s][addr1] = db::replay_position(); @@ -218,13 +218,13 @@ static future<> test_decode_v1_or_v2(encode_version v) spoint.regular_per_shard_rps[1][addr2] = db::replay_position(); spoint.mv_per_shard_rps[0][addr2] = db::replay_position(); - // If the sync point contains information about less shards than smp::count, + // If the sync point contains information about less shards than this_smp_shard_count(), // the missing shards are filled with zero. Do it here manually so that // we can compare spoint with decoded_spoint. - const unsigned adjusted_count = std::max(encoded_shard_count, smp::count); + const unsigned adjusted_count = std::max(encoded_shard_count, this_smp_shard_count()); spoint.regular_per_shard_rps.resize(adjusted_count); spoint.mv_per_shard_rps.resize(adjusted_count); - for (unsigned s = encoded_shard_count; s < smp::count; s++) { + for (unsigned s = encoded_shard_count; s < this_smp_shard_count(); s++) { spoint.regular_per_shard_rps[s][addr1] = db::replay_position(); spoint.regular_per_shard_rps[s][addr2] = db::replay_position(); spoint.mv_per_shard_rps[s][addr1] = db::replay_position(); diff --git a/test/boost/incremental_compaction_test.cc b/test/boost/incremental_compaction_test.cc index 96b65a28e5..8c156c5426 100644 --- a/test/boost/incremental_compaction_test.cc +++ b/test/boost/incremental_compaction_test.cc @@ -73,7 +73,7 @@ SEASTAR_TEST_CASE(incremental_compaction_test) { .with_column("id", utf8_type, column_kind::partition_key) .with_column("value", int32_type) .with_partitioner("org.apache.cassandra.dht.Murmur3Partitioner") - .with_sharder(smp::count, 0); + .with_sharder(this_smp_shard_count(), 0); auto s = builder.build(); auto tmp = make_lw_shared(); diff --git a/test/boost/memtable_test.cc b/test/boost/memtable_test.cc index dcb669b1f5..d029b15a5e 100644 --- a/test/boost/memtable_test.cc +++ b/test/boost/memtable_test.cc @@ -1214,7 +1214,7 @@ SEASTAR_TEST_CASE(flushing_rate_is_reduced_if_compaction_doesnt_keep_up) { // correctness tests, which do run in debug mode. return make_ready_future<>(); #else - BOOST_ASSERT(smp::count == 2); + BOOST_ASSERT(this_smp_shard_count() == 2); // The test simulates a situation where 2 threads issue flushes to 2 // tables. Both issue small flushes, but one has injected reactor stalls. // This can lead to a situation where lots of small sstables accumulate on @@ -1609,7 +1609,7 @@ SEASTAR_TEST_CASE(memtable_reader_after_tablet_migration) { { const auto src = first_tablet_info.replicas.front(); auto dst = src; - dst.shard = (src.shard + 1) % smp::count; + dst.shard = (src.shard + 1) % this_smp_shard_count(); // Closing the storage-group is done in the background, so it is fine // to wait for this. ss.move_tablet(schema->id(), tablet_map.get_last_token(first_tablet_id), src, dst).get(); diff --git a/test/boost/multishard_combining_reader_as_mutation_source_test.cc b/test/boost/multishard_combining_reader_as_mutation_source_test.cc index f43cd5d06c..c5ed3ac352 100644 --- a/test/boost/multishard_combining_reader_as_mutation_source_test.cc +++ b/test/boost/multishard_combining_reader_as_mutation_source_test.cc @@ -111,8 +111,8 @@ static auto make_populate(bool evict_paused_readers, bool single_fragment_buffer // Best run with SMP >= 2 SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader) { - if (smp::count < 2) { - std::cerr << "Cannot run test " << get_name() << " with smp::count < 2" << std::endl; + if (this_smp_shard_count() < 2) { + std::cerr << "Cannot run test " << get_name() << " with this_smp_shard_count() < 2" << std::endl; return; } @@ -123,8 +123,8 @@ SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader) { } SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader_evict_paused) { - if (smp::count < 2) { - std::cerr << "Cannot run test " << get_name() << " with smp::count < 2" << std::endl; + if (this_smp_shard_count() < 2) { + std::cerr << "Cannot run test " << get_name() << " with this_smp_shard_count() < 2" << std::endl; return; } @@ -138,8 +138,8 @@ SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader_evict_paused) { // run_mutation_source_tests execution is split SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader_with_tiny_buffer) { - if (smp::count < 2) { - std::cerr << "Cannot run test " << get_name() << " with smp::count < 2" << std::endl; + if (this_smp_shard_count() < 2) { + std::cerr << "Cannot run test " << get_name() << " with this_smp_shard_count() < 2" << std::endl; return; } @@ -150,8 +150,8 @@ SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader_with_tiny_buffer) { } SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader_with_tiny_buffer_reverse) { - if (smp::count < 2) { - std::cerr << "Cannot run test " << get_name() << " with smp::count < 2" << std::endl; + if (this_smp_shard_count() < 2) { + std::cerr << "Cannot run test " << get_name() << " with this_smp_shard_count() < 2" << std::endl; return; } diff --git a/test/boost/multishard_query_test.cc b/test/boost/multishard_query_test.cc index 5e8d7f2b6a..4ca07c7e41 100644 --- a/test/boost/multishard_query_test.cc +++ b/test/boost/multishard_query_test.cc @@ -151,7 +151,7 @@ api::timestamp_type no_tombstone_timestamp_generator(std::mt19937& engine, tests } static std::pair> create_test_table(cql_test_env& env, sstring ks_name, - sstring tbl_name, int partition_count = 10 * smp::count, int row_per_partition_count = 10) { + sstring tbl_name, int partition_count = 10 * this_smp_shard_count(), int row_per_partition_count = 10) { auto res = create_test_table( env, tests::random::get_int(), @@ -166,7 +166,7 @@ static std::pair> create_test_table( } static uint64_t aggregate_querier_cache_stat(sharded& db, uint64_t replica::querier_cache::stats::*stat) { - return map_reduce(std::views::iota(0u, smp::count), [stat, &db] (unsigned shard) { + return map_reduce(std::views::iota(0u, this_smp_shard_count()), [stat, &db] (unsigned shard) { return db.invoke_on(shard, [stat] (replica::database& local_db) { auto& stats = local_db.get_querier_cache_stats(); return stats.*stat; @@ -178,7 +178,7 @@ static void check_cache_population(sharded& db, size_t querie std::source_location sl = std::source_location::current()) { testlog.info("{}() called from {}() {}:{:d}", __FUNCTION__, sl.function_name(), sl.file_name(), sl.line()); - parallel_for_each(std::views::iota(0u, smp::count), [queriers, &db] (unsigned shard) { + parallel_for_each(std::views::iota(0u, this_smp_shard_count()), [queriers, &db] (unsigned shard) { return db.invoke_on(shard, [queriers] (replica::database& local_db) { auto& stats = local_db.get_querier_cache_stats(); tests::require_equal(stats.population, queriers); @@ -572,7 +572,7 @@ SEASTAR_THREAD_TEST_CASE(test_read_all) { } tests::require_equal(aggregate_querier_cache_stat(env.db(), &replica::querier_cache::stats::drops), 0u); - tests::require_less_equal(new_misses - misses, smp::count - saved_readers); + tests::require_less_equal(new_misses - misses, this_smp_shard_count() - saved_readers); lookups = new_lookups; misses = new_misses; @@ -708,7 +708,7 @@ SEASTAR_THREAD_TEST_CASE(test_read_with_partition_row_limits) { } tests::require_equal(aggregate_querier_cache_stat(env.db(), &replica::querier_cache::stats::drops), 0u); - tests::require_less_equal(new_misses - misses, smp::count - saved_readers); + tests::require_less_equal(new_misses - misses, this_smp_shard_count() - saved_readers); lookups = new_lookups; misses = new_misses; @@ -754,7 +754,7 @@ SEASTAR_THREAD_TEST_CASE(test_evict_a_shard_reader_on_each_page) { } lookups = new_lookups; - for (unsigned shard = 0; shard < smp::count; ++shard) { + for (unsigned shard = 0; shard < this_smp_shard_count(); ++shard) { auto evicted = smp::submit_to(shard, [&] { return env.local_db().get_querier_cache().evict_one(); }).get(); diff --git a/test/boost/mutation_reader_test.cc b/test/boost/mutation_reader_test.cc index 7c92eae413..9fc7bddf4d 100644 --- a/test/boost/mutation_reader_test.cc +++ b/test/boost/mutation_reader_test.cc @@ -1243,14 +1243,14 @@ SEASTAR_TEST_CASE(test_combined_mutation_source_is_a_mutation_source) { // Best run with SMP >= 2 SEASTAR_THREAD_TEST_CASE(test_foreign_reader_as_mutation_source, *test_label::label("nightly")) { - if (smp::count < 2) { - std::cerr << "Cannot run test " << get_name() << " with smp::count < 2" << std::endl; + if (this_smp_shard_count() < 2) { + std::cerr << "Cannot run test " << get_name() << " with this_smp_shard_count() < 2" << std::endl; return; } do_with_cql_env_thread([] (cql_test_env& env) -> future<> { auto populate = [&env] (schema_ptr s, const utils::chunked_vector& mutations) { - const auto remote_shard = (this_shard_id() + 1) % smp::count; + const auto remote_shard = (this_shard_id() + 1) % this_smp_shard_count(); auto frozen_mutations = mutations | std::views::transform([] (const mutation& m) { return freeze(m); }) @@ -1646,13 +1646,13 @@ SEASTAR_TEST_CASE(test_trim_clustering_row_ranges_to) { // Best run with SMP >= 3 SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader_reading_empty_table) { - if (smp::count < 3) { - std::cerr << "Cannot run test " << get_name() << " with smp::count < 2" << std::endl; + if (this_smp_shard_count() < 3) { + std::cerr << "Cannot run test " << get_name() << " with this_smp_shard_count() < 2" << std::endl; return; } do_with_cql_env_thread([&] (cql_test_env& env) -> future<> { - std::vector> shards_touched(smp::count); + std::vector> shards_touched(this_smp_shard_count()); simple_schema s; env.execute_cql(s.cql()).get(); @@ -1679,7 +1679,7 @@ SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader_reading_empty_table) { s.schema()->full_slice())) .produces_end_of_stream(); - for (unsigned i = 0; i < smp::count; ++i) { + for (unsigned i = 0; i < this_smp_shard_count(); ++i) { BOOST_REQUIRE(shards_touched.at(i)); } @@ -1816,13 +1816,13 @@ public: // // Best run with smp >= 2 SEASTAR_THREAD_TEST_CASE(test_stopping_reader_with_pending_read_ahead) { - if (smp::count < 2) { - std::cerr << "Cannot run test " << get_name() << " with smp::count < 2" << std::endl; + if (this_smp_shard_count() < 2) { + std::cerr << "Cannot run test " << get_name() << " with this_smp_shard_count() < 2" << std::endl; return; } do_with_cql_env_thread([] (cql_test_env& env) -> future<> { - const auto shard_of_interest = (this_shard_id() + 1) % smp::count; + const auto shard_of_interest = (this_shard_id() + 1) % this_smp_shard_count(); auto s = simple_schema(); auto remote_control_remote_reader = smp::submit_to(shard_of_interest, [&env, gs = global_simple_schema(s)] { using control_type = foreign_ptr>; @@ -1888,12 +1888,12 @@ struct multishard_reader_for_read_ahead { multishard_reader_for_read_ahead prepare_multishard_reader_for_read_ahead_test(simple_schema& s, reader_permit permit) { auto remote_controls = std::vector>>(); - remote_controls.reserve(smp::count); - for (unsigned i = 0; i < smp::count; ++i) { + remote_controls.reserve(this_smp_shard_count()); + for (unsigned i = 0; i < this_smp_shard_count(); ++i) { remote_controls.emplace_back(nullptr); } - parallel_for_each(std::views::iota(0u, smp::count), [&remote_controls] (unsigned shard) mutable { + parallel_for_each(std::views::iota(0u, this_smp_shard_count()), [&remote_controls] (unsigned shard) mutable { return smp::submit_to(shard, [] { return make_foreign(std::make_unique()); }).then([shard, &remote_controls] (foreign_ptr>&& ctr) mutable { @@ -1903,18 +1903,18 @@ multishard_reader_for_read_ahead prepare_multishard_reader_for_read_ahead_test(s // We need two tokens for each shard std::map pkeys_by_tokens; - for (unsigned i = 0; i < smp::count * 2; ++i) { + for (unsigned i = 0; i < this_smp_shard_count() * 2; ++i) { pkeys_by_tokens.emplace(s.make_pkey(i).token(), i); } - auto shard_pkeys = std::vector>(smp::count, std::vector{}); + auto shard_pkeys = std::vector>(this_smp_shard_count(), std::vector{}); auto i = unsigned(0); for (auto pkey : pkeys_by_tokens | std::views::values) { - shard_pkeys[i++ % smp::count].push_back(pkey); + shard_pkeys[i++ % this_smp_shard_count()].push_back(pkey); } auto remote_control_refs = std::vector(); - remote_control_refs.reserve(smp::count); + remote_control_refs.reserve(this_smp_shard_count()); for (auto& rc : remote_controls) { remote_control_refs.push_back(rc.get()); } @@ -1951,15 +1951,15 @@ multishard_reader_for_read_ahead prepare_multishard_reader_for_read_ahead_test(s // Regression test for #7945 SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader_custom_shard_number) { - if (smp::count < 2) { - std::cerr << "Cannot run test " << get_name() << " with smp::count < 2" << std::endl; + if (this_smp_shard_count() < 2) { + std::cerr << "Cannot run test " << get_name() << " with this_smp_shard_count() < 2" << std::endl; return; } - auto no_shards = smp::count - 1; + auto no_shards = this_smp_shard_count() - 1; do_with_cql_env_thread([&] (cql_test_env& env) -> future<> { - std::vector> shards_touched(smp::count); + std::vector> shards_touched(this_smp_shard_count()); simple_schema s; auto sharder = std::make_unique(no_shards, 0); auto factory = [&shards_touched] ( @@ -1993,13 +1993,13 @@ SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader_custom_shard_number) { // Regression test for #8161 SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader_only_reads_from_needed_shards) { - if (smp::count < 2) { - std::cerr << "Cannot run test " << get_name() << " with smp::count < 2" << std::endl; + if (this_smp_shard_count() < 2) { + std::cerr << "Cannot run test " << get_name() << " with this_smp_shard_count() < 2" << std::endl; return; } do_with_cql_env_thread([&] (cql_test_env& env) -> future<> { - std::vector> shards_touched(smp::count); + std::vector> shards_touched(this_smp_shard_count()); simple_schema s; auto factory = [&shards_touched] ( schema_ptr s, @@ -2016,18 +2016,18 @@ SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader_only_reads_from_needed auto& table = env.db().local().find_column_family(s.schema()->ks_name(), s.schema()->cf_name()); auto erm = table.get_effective_replication_map(); - std::vector expected_shards_touched(smp::count); + std::vector expected_shards_touched(this_smp_shard_count()); const dht::sharder& sharder = erm->get_sharder(*s.schema()); dht::token start_token(0); dht::token end_token(0); - const auto additional_shards = tests::random::get_int(0, smp::count - 1); + const auto additional_shards = tests::random::get_int(0, this_smp_shard_count() - 1); auto shard = sharder.shard_for_reads(start_token); expected_shards_touched[shard] = true; for (auto i = 0u; i < additional_shards; ++i) { - shard = (shard + 1) % smp::count; + shard = (shard + 1) % this_smp_shard_count(); end_token = sharder.token_for_next_shard_for_reads(end_token, shard); expected_shards_touched[shard] = true; } @@ -2040,7 +2040,7 @@ SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader_only_reads_from_needed expected_shards_touched[shard] = false; } - testlog.info("{}: including {} additional shards out of a total of {}, with an {} end", get_name(), additional_shards, smp::count, + testlog.info("{}: including {} additional shards out of a total of {}, with an {} end", get_name(), additional_shards, this_smp_shard_count(), inclusive_end ? "inclusive" : "exclusive"); assert_that(make_multishard_combining_reader( @@ -2052,7 +2052,7 @@ SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader_only_reads_from_needed s.schema()->full_slice())) .produces_end_of_stream(); - for (unsigned i = 0; i < smp::count; ++i) { + for (unsigned i = 0; i < this_smp_shard_count(); ++i) { testlog.info("[{}]: {} == {}", i, shards_touched[i], expected_shards_touched[i]); BOOST_CHECK(shards_touched[i] == expected_shards_touched[i]); } @@ -2086,8 +2086,8 @@ SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader_only_reads_from_needed // // Best run with smp >= 3 SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader_destroyed_with_pending_read_ahead) { - if (smp::count < multishard_reader_for_read_ahead::min_shards) { - std::cerr << "Cannot run test " << get_name() << " with smp::count < " << multishard_reader_for_read_ahead::min_shards << std::endl; + if (this_smp_shard_count() < multishard_reader_for_read_ahead::min_shards) { + std::cerr << "Cannot run test " << get_name() << " with this_smp_shard_count() < " << multishard_reader_for_read_ahead::min_shards << std::endl; return; } @@ -2119,7 +2119,7 @@ SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader_destroyed_with_pending testlog.debug("Starting to close the reader"); auto fut = reader.close(); - parallel_for_each(std::views::iota(0u, smp::count), [&remote_controls] (unsigned shard) mutable { + parallel_for_each(std::views::iota(0u, this_smp_shard_count()), [&remote_controls] (unsigned shard) mutable { return smp::submit_to(shard, [control = remote_controls.at(shard).get()] { control->buffer_filled.set_value(); }); @@ -2129,7 +2129,7 @@ SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader_destroyed_with_pending testlog.debug("Reader is closed"); BOOST_REQUIRE(eventually_true([&] { - return map_reduce(std::views::iota(0u, smp::count), [&] (unsigned shard) { + return map_reduce(std::views::iota(0u, this_smp_shard_count()), [&] (unsigned shard) { return smp::submit_to(shard, [&remote_controls, shard] { return remote_controls.at(shard)->destroyed; }); @@ -2143,8 +2143,8 @@ SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader_destroyed_with_pending } SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader_fast_forwarded_with_pending_read_ahead) { - if (smp::count < multishard_reader_for_read_ahead::min_shards) { - std::cerr << "Cannot run test " << get_name() << " with smp::count < " << multishard_reader_for_read_ahead::min_shards << std::endl; + if (this_smp_shard_count() < multishard_reader_for_read_ahead::min_shards) { + std::cerr << "Cannot run test " << get_name() << " with this_smp_shard_count() < " << multishard_reader_for_read_ahead::min_shards << std::endl; return; } @@ -2204,7 +2204,7 @@ SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader_fast_forwarded_with_pe reader.close().get(); BOOST_REQUIRE(eventually_true([&] { - return map_reduce(std::views::iota(0u, smp::count), [&] (unsigned shard) { + return map_reduce(std::views::iota(0u, this_smp_shard_count()), [&] (unsigned shard) { return smp::submit_to(shard, [&remote_controls, shard] { return remote_controls.at(shard)->destroyed; }); @@ -2300,8 +2300,8 @@ SEASTAR_THREAD_TEST_CASE(test_multishard_combining_reader_next_partition) { // sharding configuration. // The reference data is provided by a filtering reader. SEASTAR_THREAD_TEST_CASE(test_multishard_streaming_reader) { - if (smp::count < 3) { - std::cerr << "Cannot run test " << get_name() << " with smp::count < 3" << std::endl; + if (this_smp_shard_count() < 3) { + std::cerr << "Cannot run test " << get_name() << " with this_smp_shard_count() < 3" << std::endl; return; } @@ -4320,8 +4320,8 @@ SEASTAR_TEST_CASE(test_multishard_reader_safe_to_create_with_admitted_permit) { simple_schema s; std::vector>> semaphores; - semaphores.resize(smp::count); - parallel_for_each(std::views::iota(0u, smp::count), [&semaphores] (shard_id shard) { + semaphores.resize(this_smp_shard_count()); + parallel_for_each(std::views::iota(0u, this_smp_shard_count()), [&semaphores] (shard_id shard) { return smp::submit_to(shard, [&semaphores] { semaphores[this_shard_id()] = make_foreign(make_lw_shared( reader_concurrency_semaphore::for_tests{}, @@ -4331,7 +4331,7 @@ SEASTAR_TEST_CASE(test_multishard_reader_safe_to_create_with_admitted_permit) { }); }).get(); auto stop_semaphores = defer([&semaphores] { - parallel_for_each(std::views::iota(0u, smp::count), [&semaphores] (shard_id shard) { + parallel_for_each(std::views::iota(0u, this_smp_shard_count()), [&semaphores] (shard_id shard) { return smp::submit_to(shard, [&semaphores] () -> future<> { auto semaphore = semaphores[this_shard_id()].release(); co_await semaphore->stop(); @@ -4340,7 +4340,7 @@ SEASTAR_TEST_CASE(test_multishard_reader_safe_to_create_with_admitted_permit) { }); std::map pkeys_by_tokens; - for (unsigned i = 0; i < smp::count * 2; ++i) { + for (unsigned i = 0; i < this_smp_shard_count() * 2; ++i) { pkeys_by_tokens.emplace(s.make_pkey(i).token(), i); } auto sharder = std::make_unique(s.schema()->get_sharder(), std::move(pkeys_by_tokens)); @@ -4391,11 +4391,11 @@ SEASTAR_TEST_CASE(test_multishard_reader_buffer_hint_large_partitions) { const size_t num_rows = 200; tests::reader_concurrency_semaphore_wrapper semaphore; - const auto pkeys_by_tokens = ss.make_pkeys(2 * smp::count) + const auto pkeys_by_tokens = ss.make_pkeys(2 * this_smp_shard_count()) | std::views::transform([] (const dht::decorated_key& dk) { return std::pair(dk.token(), dk); }) | std::ranges::to>(); - std::vector> frozen_muts(smp::count, utils::chunked_vector{}); - std::vector> semaphore_registry(smp::count, nullptr); + std::vector> frozen_muts(this_smp_shard_count(), utils::chunked_vector{}); + std::vector> semaphore_registry(this_smp_shard_count(), nullptr); unsigned i = 0; for (const auto& [token, dk] : pkeys_by_tokens) { @@ -4405,7 +4405,7 @@ SEASTAR_TEST_CASE(test_multishard_reader_buffer_hint_large_partitions) { ss.add_row(mut, ss.make_ckey(ck), value); } - frozen_muts[i++ % smp::count].emplace_back(mut); + frozen_muts[i++ % this_smp_shard_count()].emplace_back(mut); } size_t partition_size{0}; @@ -4435,9 +4435,9 @@ SEASTAR_TEST_CASE(test_multishard_reader_buffer_hint_large_partitions) { range_tombstone_size = rtc.memory_usage(); } - std::vector> data_per_shard(smp::count, std::vector{}); + std::vector> data_per_shard(this_smp_shard_count(), std::vector{}); size_t total_data{0}; - for (unsigned shard_id = 0; shard_id != smp::count; ++shard_id) { + for (unsigned shard_id = 0; shard_id != this_smp_shard_count(); ++shard_id) { for (const auto& _ : frozen_muts.at(shard_id)) { data_per_shard.at(shard_id).push_back(partition_size); total_data += partition_size; @@ -4480,7 +4480,7 @@ SEASTAR_TEST_CASE(test_multishard_reader_buffer_hint_large_partitions) { reader.fill_buffer().get(); // simulate the expected read algorithm to calculate the amount each shard should have read - std::vector buffer_fill_calls_per_shard(smp::count, 0); + std::vector buffer_fill_calls_per_shard(this_smp_shard_count(), 0); size_t shards_visited{0}; { size_t to_read = buffer_size; @@ -4488,7 +4488,7 @@ SEASTAR_TEST_CASE(test_multishard_reader_buffer_hint_large_partitions) { auto shard_data_left = data_per_shard; const auto shard_reader_buffer_size = buffer_hint ? buffer_size : mutation_reader::default_max_buffer_size_in_bytes(); while (to_read > 0 && data_left > 0) { - for (unsigned shard_id = 0; shard_id != smp::count && to_read > 0 && data_left > 0; ++shard_id) { + for (unsigned shard_id = 0; shard_id != this_smp_shard_count() && to_read > 0 && data_left > 0; ++shard_id) { auto& shard_data = shard_data_left[shard_id]; BOOST_REQUIRE(!shard_data.empty()); @@ -4540,7 +4540,7 @@ SEASTAR_TEST_CASE(test_multishard_reader_buffer_hint_large_partitions) { } } - for (unsigned shard_id = 0; shard_id != smp::count; ++shard_id) { + for (unsigned shard_id = 0; shard_id != this_smp_shard_count(); ++shard_id) { testlog.trace("shard#{}", shard_id); if (shards_visited > shard_id) { @@ -4574,11 +4574,11 @@ SEASTAR_TEST_CASE(test_multishard_reader_buffer_hint_small_partitions) { const size_t num_rows = 2; tests::reader_concurrency_semaphore_wrapper semaphore; - const auto pkeys_by_tokens = ss.make_pkeys(64 * smp::count) + const auto pkeys_by_tokens = ss.make_pkeys(64 * this_smp_shard_count()) | std::views::transform([] (const dht::decorated_key& dk) { return std::pair(dk.token(), dk); }) | std::ranges::to>(); - std::vector> frozen_muts(smp::count, utils::chunked_vector{}); - std::vector> semaphore_registry(smp::count, nullptr); + std::vector> frozen_muts(this_smp_shard_count(), utils::chunked_vector{}); + std::vector> semaphore_registry(this_smp_shard_count(), nullptr); unsigned i = 0; for (const auto& [token, dk] : pkeys_by_tokens) { @@ -4587,7 +4587,7 @@ SEASTAR_TEST_CASE(test_multishard_reader_buffer_hint_small_partitions) { for (uint32_t ck = 0; ck < num_rows; ++ck) { ss.add_row(mut, ss.make_ckey(ck), value); } - frozen_muts[i++ % smp::count].emplace_back(mut); + frozen_muts[i++ % this_smp_shard_count()].emplace_back(mut); } auto sharder = std::make_unique(schema->get_sharder(), std::move(pkeys_by_tokens)); @@ -4620,7 +4620,7 @@ SEASTAR_TEST_CASE(test_multishard_reader_buffer_hint_small_partitions) { reader.fill_buffer().get(); - for (unsigned shard_id = 0; shard_id != smp::count; ++shard_id) { + for (unsigned shard_id = 0; shard_id != this_smp_shard_count(); ++shard_id) { const auto reads_from_shard = 1; auto& shard_semaphore = semaphore_registry.at(shard_id); diff --git a/test/boost/mutation_writer_test.cc b/test/boost/mutation_writer_test.cc index 1b6229d083..44d7a7d1e5 100644 --- a/test/boost/mutation_writer_test.cc +++ b/test/boost/mutation_writer_test.cc @@ -59,8 +59,8 @@ SEASTAR_TEST_CASE(test_multishard_writer) { auto test_random_streams = [&e] (random_mutation_generator&& gen, size_t partition_nr, generate_error error = generate_error::no) { for (auto i = 0; i < 3; i++) { auto muts = gen(partition_nr); - std::vector shards_before(smp::count, 0); - std::vector shards_after(smp::count, 0); + std::vector shards_before(this_smp_shard_count(), 0); + std::vector shards_after(this_smp_shard_count(), 0); schema_ptr s = gen.schema(); for (auto& m : muts) { diff --git a/test/boost/per_partition_rate_limit_test.cc b/test/boost/per_partition_rate_limit_test.cc index 6371371b61..5f6fe91cd6 100644 --- a/test/boost/per_partition_rate_limit_test.cc +++ b/test/boost/per_partition_rate_limit_test.cc @@ -16,7 +16,7 @@ SEASTAR_TEST_CASE(test_internal_operation_filtering) { return do_with_cql_env_thread([] (cql_test_env& e) -> future<> { // The test requires at least two shards // so that it can test the shard!=coordinator case - BOOST_REQUIRE_GT(smp::count, 1); + BOOST_REQUIRE_GT(this_smp_shard_count(), 1); cquery_nofail(e, "CREATE TABLE ks.tbl (pk int PRIMARY KEY) \ WITH per_partition_rate_limit = {'max_reads_per_second': 1, 'max_writes_per_second': 1}"); @@ -28,7 +28,7 @@ SEASTAR_TEST_CASE(test_internal_operation_filtering) { auto pk = partition_key::from_singular(*sptr, int32_t(0)); unsigned local_shard = sptr->table().shard_for_reads(dht::get_token(*sptr, pk.view())); - unsigned foreign_shard = (local_shard + 1) % smp::count; + unsigned foreign_shard = (local_shard + 1) % this_smp_shard_count(); auto run_writes = [&qp, &db, pk] (db::allow_per_partition_rate_limit allow_limit) -> future<> { BOOST_TEST_MESSAGE("Testing writes"); diff --git a/test/boost/replicator_test.cc b/test/boost/replicator_test.cc index 639f3d533d..5de18a58d5 100644 --- a/test/boost/replicator_test.cc +++ b/test/boost/replicator_test.cc @@ -32,7 +32,7 @@ using map_type = std::map>; using key_setter = std::pair; static void require_multishard() { - tests::require_greater(smp::count, 1); + tests::require_greater(this_smp_shard_count(), 1); } // last-write-wins semantics for mutations. diff --git a/test/boost/schema_registry_test.cc b/test/boost/schema_registry_test.cc index ba6fd3a79e..2b7118d2be 100644 --- a/test/boost/schema_registry_test.cc +++ b/test/boost/schema_registry_test.cc @@ -209,7 +209,7 @@ SEASTAR_THREAD_TEST_CASE(test_table_is_attached) { }); BOOST_REQUIRE(learned_s2->maybe_table() == s0->maybe_table()); - if (smp::count > 1) { + if (this_smp_shard_count() > 1) { smp::submit_to(1, [&e, gs = global_schema_ptr(learned_s2)] { schema_ptr s0 = e.local_db().find_column_family("ks", "cf").schema(); BOOST_REQUIRE(gs.get()->maybe_table()); diff --git a/test/boost/sstable_3_x_test.cc b/test/boost/sstable_3_x_test.cc index d49e0ae071..74a2d14f49 100644 --- a/test/boost/sstable_3_x_test.cc +++ b/test/boost/sstable_3_x_test.cc @@ -3016,7 +3016,7 @@ static mutation_reader compacted_sstable_reader(test_env& env, schema_ptr s, SEASTAR_TEST_CASE(compact_deleted_row) { return test_env::do_with_async([] (test_env& env) { - BOOST_REQUIRE(smp::count == 1); + BOOST_REQUIRE(this_smp_shard_count() == 1); sstring table_name = "compact_deleted_row"; // CREATE TABLE test_deleted_row (pk text, ck text, rc1 text, rc2 text, PRIMARY KEY (pk, ck)) WITH compression = {'sstable_compression': ''}; schema_builder builder(this_smp_shard_count(), "sst3", table_name); @@ -3087,7 +3087,7 @@ SEASTAR_TEST_CASE(compact_deleted_row) { SEASTAR_TEST_CASE(compact_deleted_cell) { return test_env::do_with_async([] (test_env& env) { - BOOST_REQUIRE(smp::count == 1); + BOOST_REQUIRE(this_smp_shard_count() == 1); sstring table_name = "compact_deleted_cell"; // CREATE TABLE compact_deleted_cell (pk text, ck text, rc text, PRIMARY KEY (pk, ck)) WITH compression = {'sstable_compression': ''}; schema_builder builder(this_smp_shard_count(), "sst3", table_name); diff --git a/test/boost/sstable_compaction_test.cc b/test/boost/sstable_compaction_test.cc index ce407ac5ff..d09589492a 100644 --- a/test/boost/sstable_compaction_test.cc +++ b/test/boost/sstable_compaction_test.cc @@ -172,7 +172,7 @@ static void corrupt_sstable(sstables::shared_sstable sst, component_type type = } void compaction_manager_basic(test_env& env) { - BOOST_REQUIRE(smp::count == 1); + BOOST_REQUIRE(this_smp_shard_count() == 1); auto s = schema_builder(this_smp_shard_count(), some_keyspace, some_column_family) .with_column("p1", utf8_type, column_kind::partition_key) .with_column("c1", utf8_type, column_kind::clustering_key) @@ -239,7 +239,7 @@ SEASTAR_FIXTURE_TEST_CASE(compaction_manager_basic_gcs_test, gcs_fixture, *tests } void compact(test_env& env) { - BOOST_REQUIRE(smp::count == 1); + BOOST_REQUIRE(this_smp_shard_count() == 1); // The "compaction" sstable was created with the following schema: // CREATE TABLE compaction ( // name text, @@ -376,7 +376,7 @@ struct compact_sstables_result { // Return vector of sstables generated by compaction. Only relevant for leveled one. static future compact_sstables(test_env& env, std::vector sstables_to_compact, size_t create_sstables, uint64_t min_sstable_size, compaction::compaction_strategy_type strategy) { - BOOST_REQUIRE(smp::count == 1); + BOOST_REQUIRE(this_smp_shard_count() == 1); return seastar::async( [&env, sstables = std::move(sstables_to_compact), create_sstables, min_sstable_size, strategy] () mutable { schema_builder builder(this_smp_shard_count(), some_keyspace, some_column_family); @@ -806,7 +806,7 @@ static bool sstable_overlaps(const lw_shared_ptr& cf, ss } void leveled_01_fn(test_env& env) { - BOOST_REQUIRE_EQUAL(smp::count, 1); + BOOST_REQUIRE_EQUAL(this_smp_shard_count(), 1); auto schema = table_for_tests::make_default_schema(); auto cf = env.make_table_for_tests(schema); auto stop_cf = deferred_stop(cf); @@ -858,7 +858,7 @@ SEASTAR_FIXTURE_TEST_CASE(leveled_01_gcs, gcs_fixture, *tests::check_run_test_de } void leveled_02_fn(test_env& env) { - BOOST_REQUIRE_EQUAL(smp::count, 1); + BOOST_REQUIRE_EQUAL(this_smp_shard_count(), 1); auto schema = table_for_tests::make_default_schema(); auto cf = env.make_table_for_tests(schema); auto stop_cf = deferred_stop(cf); @@ -920,7 +920,7 @@ SEASTAR_FIXTURE_TEST_CASE(leveled_02_gcs, gcs_fixture, *tests::check_run_test_de } void leveled_03_fn(test_env& env) { - BOOST_REQUIRE_EQUAL(smp::count, 1); + BOOST_REQUIRE_EQUAL(this_smp_shard_count(), 1); auto schema = table_for_tests::make_default_schema(); auto cf = env.make_table_for_tests(schema); auto stop_cf = deferred_stop(cf); @@ -983,7 +983,7 @@ SEASTAR_FIXTURE_TEST_CASE(leveled_03_gcs, gcs_fixture, *tests::check_run_test_de } void leveled_04_fn(test_env& env) { - BOOST_REQUIRE_EQUAL(smp::count, 1); + BOOST_REQUIRE_EQUAL(this_smp_shard_count(), 1); auto schema = table_for_tests::make_default_schema(); auto cf = env.make_table_for_tests(schema); auto stop_cf = deferred_stop(cf); @@ -1352,7 +1352,7 @@ SEASTAR_FIXTURE_TEST_CASE(check_overlapping_gcs, gcs_fixture, *tests::check_run_ } future<> tombstone_purge(test_env& env) { - BOOST_REQUIRE(smp::count == 1); + BOOST_REQUIRE(this_smp_shard_count() == 1); // In a column family with gc_grace_seconds set to 0, check that a tombstone // is purged after compaction. auto builder = schema_builder(this_smp_shard_count(), "tests", "tombstone_purge") @@ -1654,7 +1654,7 @@ SEASTAR_FIXTURE_TEST_CASE(tombstone_purge_gcs_test, gcs_fixture, *tests::check_r } future<> mv_tombstone_purge(test_env& env) { - BOOST_REQUIRE(smp::count == 1); + BOOST_REQUIRE(this_smp_shard_count() == 1); // In a column family with gc_grace_seconds set to 0, check that a tombstone // is purged after compaction. auto builder = schema_builder(this_smp_shard_count(), "tests", "tombstone_purge") @@ -1762,7 +1762,7 @@ SEASTAR_FIXTURE_TEST_CASE(mv_tombstone_purge_gcs_test, gcs_fixture, *tests::chec } future<> sstable_rewrite(test_env& env) { - BOOST_REQUIRE(smp::count == 1); + BOOST_REQUIRE(this_smp_shard_count() == 1); auto s = schema_builder(this_smp_shard_count(), some_keyspace, some_column_family) .with_column("p1", utf8_type, column_kind::partition_key) .with_column("c1", utf8_type, column_kind::clustering_key) @@ -4313,7 +4313,7 @@ SEASTAR_FIXTURE_TEST_CASE(backlog_tracker_correctness_after_changing_compaction_ } void partial_sstable_run_filtered_out_fn(test_env& env) { - BOOST_REQUIRE(smp::count == 1); + BOOST_REQUIRE(this_smp_shard_count() == 1); auto s = schema_builder(this_smp_shard_count(), "tests", "partial_sstable_run_filtered_out_test") .with_column("id", utf8_type, column_kind::partition_key) .with_column("value", int32_type).build(); @@ -4366,7 +4366,7 @@ SEASTAR_FIXTURE_TEST_CASE(partial_sstable_run_filtered_out_test_gcs, gcs_fixture // Make sure that a custom tombstone-gced-only writer will be fed with gc'able tombstone // from the regular compaction's input sstable. void purged_tombstone_consumer_sstable_fn(test_env& env) { - BOOST_REQUIRE(smp::count == 1); + BOOST_REQUIRE(this_smp_shard_count() == 1); auto builder = schema_builder(this_smp_shard_count(), "tests", "purged_tombstone_consumer_sstable_test") .with_column("id", utf8_type, column_kind::partition_key) .with_column("value", int32_type); @@ -5630,7 +5630,7 @@ SEASTAR_FIXTURE_TEST_CASE(test_twcs_single_key_reader_filtering_gcs, gcs_fixture } void max_ongoing_compaction_fn(test_env& env) { - BOOST_REQUIRE(smp::count == 1); + BOOST_REQUIRE(this_smp_shard_count() == 1); auto make_schema = [] (auto idx) { auto builder = schema_builder(this_smp_shard_count(), "tests", std::to_string(idx)) @@ -7295,7 +7295,7 @@ SEASTAR_FIXTURE_TEST_CASE(splitting_compaction_test_gcs, gcs_fixture, *tests::ch } void unsealed_sstable_compaction_fn(test_env& env) { - BOOST_REQUIRE(smp::count == 1); + BOOST_REQUIRE(this_smp_shard_count() == 1); auto s = schema_builder(this_smp_shard_count(), "tests", "unsealed_sstable_compaction_test") .with_column("id", utf8_type, column_kind::partition_key) .with_column("value", int32_type).build(); diff --git a/test/boost/sstable_compressor_factory_test.cc b/test/boost/sstable_compressor_factory_test.cc index 431535942e..39304f4c9a 100644 --- a/test/boost/sstable_compressor_factory_test.cc +++ b/test/boost/sstable_compressor_factory_test.cc @@ -28,7 +28,7 @@ void test_one_numa_topology(std::span shard_to_numa_mapping) { testlog.info("Testing NUMA topology {}", shard_to_numa_mapping); // Create a compressor factory. - tests::require(shard_to_numa_mapping.size() == smp::count); + tests::require(shard_to_numa_mapping.size() == this_smp_shard_count()); auto config = default_sstable_compressor_factory::config{ .numa_config = std::vector(shard_to_numa_mapping.begin(), shard_to_numa_mapping.end()), }; @@ -48,8 +48,8 @@ void test_one_numa_topology(std::span shard_to_numa_mapping) { sstable_compressor_factory.local().set_recommended_dict(table, dict_view).get(); // We'll put the owners here to check that the number of owners matches the number of NUMA nodes. - std::vector compressor_numa_nodes(smp::count); - std::vector decompressor_numa_nodes(smp::count); + std::vector compressor_numa_nodes(this_smp_shard_count()); + std::vector decompressor_numa_nodes(this_smp_shard_count()); // Try for both algorithms, just in case there are some differences in how dictionary // distribution over shards is implemented between them. @@ -116,18 +116,18 @@ void test_one_numa_topology(std::span shard_to_numa_mapping) { SEASTAR_THREAD_TEST_CASE(test_numa_awareness) { { - std::vector one_numa_node(smp::count); + std::vector one_numa_node(this_smp_shard_count()); test_one_numa_topology(one_numa_node); } { - std::vector two_numa_nodes(smp::count); + std::vector two_numa_nodes(this_smp_shard_count()); for (size_t i = 0; i < two_numa_nodes.size(); ++i) { two_numa_nodes[i] = i % 2; } test_one_numa_topology(two_numa_nodes); } { - std::vector n_numa_nodes(smp::count); + std::vector n_numa_nodes(this_smp_shard_count()); for (size_t i = 0; i < n_numa_nodes.size(); ++i) { n_numa_nodes[i] = i; } diff --git a/test/boost/sstable_datafile_test.cc b/test/boost/sstable_datafile_test.cc index afcdc8ad9a..6279b21e89 100644 --- a/test/boost/sstable_datafile_test.cc +++ b/test/boost/sstable_datafile_test.cc @@ -2373,7 +2373,7 @@ SEASTAR_TEST_CASE(sstable_partition_estimation_sanity_test) { } SEASTAR_TEST_CASE(sstable_timestamp_metadata_correcness_with_negative) { - BOOST_REQUIRE(smp::count == 1); + BOOST_REQUIRE(this_smp_shard_count() == 1); return test_env::do_with_async([] (test_env& env) { for (auto version : writable_sstable_versions) { auto s = schema_builder(this_smp_shard_count(), "tests", "ts_correcness_test") @@ -2401,7 +2401,7 @@ SEASTAR_TEST_CASE(sstable_timestamp_metadata_correcness_with_negative) { } SEASTAR_TEST_CASE(sstable_run_identifier_correctness) { - BOOST_REQUIRE(smp::count == 1); + BOOST_REQUIRE(this_smp_shard_count() == 1); return test_env::do_with_async([] (test_env& env) { auto s = schema_builder(this_smp_shard_count(), "tests", "ts_correcness_test") .with_column("id", utf8_type, column_kind::partition_key) @@ -3278,7 +3278,7 @@ SEASTAR_TEST_CASE(test_sstable_set_predicate) { } SEASTAR_TEST_CASE(sstable_identifier_correctness) { - BOOST_REQUIRE(smp::count == 1); + BOOST_REQUIRE(this_smp_shard_count() == 1); return test_env::do_with_async([] (test_env& env) { simple_schema ss; auto s = ss.schema(); diff --git a/test/boost/sstable_directory_test.cc b/test/boost/sstable_directory_test.cc index 20165c6baa..66fe4ac21a 100644 --- a/test/boost/sstable_directory_test.cc +++ b/test/boost/sstable_directory_test.cc @@ -74,7 +74,7 @@ make_sstable_for_this_shard(std::function sst_factor /// Arguments passed to the function are passed to table::make_sstable template sstables::shared_sstable -make_sstable_for_all_shards(replica::table& table, sstables::sstable_state state, sstables::generation_type generation, unsigned num_shards = smp::count) { +make_sstable_for_all_shards(replica::table& table, sstables::sstable_state state, sstables::generation_type generation, unsigned num_shards = this_smp_shard_count()) { // Unlike the previous helper, we'll assume we're in a thread here. It's less flexible // but the users are usually in a thread, and rewrite_toc_without_component requires // a thread. We could fix that, but deferring that for now. @@ -328,7 +328,7 @@ SEASTAR_THREAD_TEST_CASE(sstable_directory_test_generation_sanity) { rename_file(test(sst2).filename(sstables::component_type::TOC).native(), test(sst2).filename(sstables::component_type::TemporaryTOC).native()).get(); std::vector gen1_seen; - gen1_seen.resize(smp::count); + gen1_seen.resize(this_smp_shard_count()); with_sstable_directory(env, [&] (sharded& sstdir) { distributed_loader_for_tests::process_sstable_dir(sstdir, { .throw_on_missing_toc = true }).get(); sstdir.invoke_on_all([&] (sstables::sstable_directory& sstdir) { @@ -389,7 +389,7 @@ SEASTAR_THREAD_TEST_CASE(sstable_directory_unshared_sstables_sanity_matched_gene sharded_gen.start().get(); auto stop_generator = deferred_stop(sharded_gen); - for (shard_id i = 0; i < smp::count; ++i) { + for (shard_id i = 0; i < this_smp_shard_count(); ++i) { env.invoke_on(i, [&sharded_gen] (sstables::test_env& env) { auto generation = std::invoke(sharded_gen.local()); // this is why it is annoying for the internal functions in the test infrastructure to @@ -402,7 +402,7 @@ SEASTAR_THREAD_TEST_CASE(sstable_directory_unshared_sstables_sanity_matched_gene with_sstable_directory(env, [] (sharded& sstdir) { distributed_loader_for_tests::process_sstable_dir(sstdir, { .throw_on_missing_toc = true }).get(); - verify_that_all_sstables_are_local(sstdir, smp::count).get(); + verify_that_all_sstables_are_local(sstdir, this_smp_shard_count()).get(); }); }).get(); } @@ -415,10 +415,10 @@ SEASTAR_THREAD_TEST_CASE(sstable_directory_unshared_sstables_sanity_unmatched_ge sharded_gen.start().get(); auto stop_generator = deferred_stop(sharded_gen); - for (shard_id i = 0; i < smp::count; ++i) { + for (shard_id i = 0; i < this_smp_shard_count(); ++i) { env.invoke_on(i, [&sharded_gen] (sstables::test_env& env) -> future<> { // intentionally generate the generation on a different shard - auto generation = co_await sharded_gen.invoke_on((this_shard_id() + 1) % smp::count, [] (auto& gen) { + auto generation = co_await sharded_gen.invoke_on((this_shard_id() + 1) % this_smp_shard_count(), [] (auto& gen) { return gen(); }); // this is why it is annoying for the internal functions in the test infrastructure to @@ -431,13 +431,13 @@ SEASTAR_THREAD_TEST_CASE(sstable_directory_unshared_sstables_sanity_unmatched_ge with_sstable_directory(env, [] (sharded& sstdir) { distributed_loader_for_tests::process_sstable_dir(sstdir, { .throw_on_missing_toc = true }).get(); - verify_that_all_sstables_are_local(sstdir, smp::count).get(); + verify_that_all_sstables_are_local(sstdir, this_smp_shard_count()).get(); }); }).get(); } SEASTAR_THREAD_TEST_CASE(sstable_directory_foreign_sstable_should_not_load_locally) { - if (smp::count == 1) { + if (this_smp_shard_count() == 1) { fmt::print("Skipping sstable_directory_shared_sstables_reshard_correctly, smp == 1\n"); return; } @@ -447,10 +447,10 @@ SEASTAR_THREAD_TEST_CASE(sstable_directory_foreign_sstable_should_not_load_local return sstables_stats::get_shard_stats().open_for_reading; }, 0, [] (auto res, auto gen) {return res + gen;}).get(); }; - for (shard_id i = 0; i < smp::count; ++i) { + for (shard_id i = 0; i < this_smp_shard_count(); ++i) { env.invoke_on(i, [] (sstables::test_env& env) -> future<> { co_return co_await seastar::async([&env] { - make_sstable_for_this_shard(std::bind(new_sstable, std::ref(env), generation_type((this_shard_id() + 1) % smp::count))); + make_sstable_for_this_shard(std::bind(new_sstable, std::ref(env), generation_type((this_shard_id() + 1) % this_smp_shard_count()))); }); }).get(); } @@ -461,7 +461,7 @@ SEASTAR_THREAD_TEST_CASE(sstable_directory_foreign_sstable_should_not_load_local }); // verify that all the sstables were loaded only once - BOOST_REQUIRE_EQUAL(sstables_opened_for_reading(), sstables_open_before_process + smp::count); + BOOST_REQUIRE_EQUAL(sstables_opened_for_reading(), sstables_open_before_process + this_smp_shard_count()); }).get(); } @@ -543,7 +543,7 @@ SEASTAR_TEST_CASE(sstable_directory_test_table_lock_works) { } SEASTAR_TEST_CASE(sstable_directory_shared_sstables_reshard_correctly) { - if (smp::count == 1) { + if (this_smp_shard_count() == 1) { fmt::print("Skipping sstable_directory_shared_sstables_reshard_correctly, smp == 1\n"); return make_ready_future<>(); } @@ -557,14 +557,14 @@ SEASTAR_TEST_CASE(sstable_directory_shared_sstables_reshard_correctly) { return cf.disable_auto_compaction(); }).get(); - unsigned num_sstables = 10 * smp::count; + unsigned num_sstables = 10 * this_smp_shard_count(); sharded sharded_gen; sharded_gen.start().get(); auto stop_generator = deferred_stop(sharded_gen); for (unsigned nr = 0; nr < num_sstables; ++nr) { - auto generation = sharded_gen.invoke_on(nr % smp::count, [] (auto& gen) { + auto generation = sharded_gen.invoke_on(nr % this_smp_shard_count(), [] (auto& gen) { return gen(); }).get(); make_sstable_for_all_shards(cf, sstables::sstable_state::upload, generation); @@ -586,14 +586,14 @@ SEASTAR_TEST_CASE(sstable_directory_shared_sstables_reshard_correctly) { return cf.get_sstables_manager().make_sstable(cf.schema(), cf.get_storage_options(), generation, sstables::sstable_state::upload); }; distributed_loader_for_tests::reshard(sstdir, e.db(), "ks", "cf", std::move(make_sstable)).get(); - verify_that_all_sstables_are_local(sstdir, smp::count * smp::count).get(); + verify_that_all_sstables_are_local(sstdir, this_smp_shard_count() * this_smp_shard_count()).get(); }); }); } // Regression test for #14618 - resharding with non-empty owned_ranges_ptr. SEASTAR_TEST_CASE(sstable_directory_shared_sstables_reshard_correctly_with_owned_ranges) { - if (smp::count == 1) { + if (this_smp_shard_count() == 1) { fmt::print("Skipping sstable_directory_shared_sstables_reshard_correctly, smp == 1\n"); return make_ready_future<>(); } @@ -607,14 +607,14 @@ SEASTAR_TEST_CASE(sstable_directory_shared_sstables_reshard_correctly_with_owned return cf.disable_auto_compaction(); }).get(); - unsigned num_sstables = 10 * smp::count; + unsigned num_sstables = 10 * this_smp_shard_count(); sharded sharded_gen; sharded_gen.start().get(); auto stop_generator = deferred_stop(sharded_gen); for (unsigned nr = 0; nr < num_sstables; ++nr) { - auto generation = sharded_gen.invoke_on(nr % smp::count, [] (auto& gen) { + auto generation = sharded_gen.invoke_on(nr % this_smp_shard_count(), [] (auto& gen) { return gen(); }).get(); make_sstable_for_all_shards(cf, sstables::sstable_state::upload, generation); @@ -638,13 +638,13 @@ SEASTAR_TEST_CASE(sstable_directory_shared_sstables_reshard_correctly_with_owned const auto& erm = e.db().local().find_keyspace("ks").get_static_effective_replication_map(); auto owned_ranges_ptr = compaction::make_owned_ranges_ptr(e.db().local().get_keyspace_local_ranges(erm).get()); distributed_loader_for_tests::reshard(sstdir, e.db(), "ks", "cf", std::move(make_sstable), std::move(owned_ranges_ptr)).get(); - verify_that_all_sstables_are_local(sstdir, smp::count * smp::count).get(); + verify_that_all_sstables_are_local(sstdir, this_smp_shard_count() * this_smp_shard_count()).get(); }); }); } SEASTAR_TEST_CASE(sstable_directory_shared_sstables_reshard_distributes_well_even_if_files_are_not_well_distributed) { - if (smp::count == 1) { + if (this_smp_shard_count() == 1) { fmt::print("Skipping sstable_directory_shared_sstables_reshard_correctly, smp == 1\n"); return make_ready_future<>(); } @@ -658,7 +658,7 @@ SEASTAR_TEST_CASE(sstable_directory_shared_sstables_reshard_distributes_well_eve return cf.disable_auto_compaction(); }).get(); - unsigned num_sstables = 10 * smp::count; + unsigned num_sstables = 10 * this_smp_shard_count(); sharded sharded_gen; sharded_gen.start().get(); @@ -688,13 +688,13 @@ SEASTAR_TEST_CASE(sstable_directory_shared_sstables_reshard_distributes_well_eve return cf.get_sstables_manager().make_sstable(cf.schema(), cf.get_storage_options(), generation, sstables::sstable_state::upload); }; distributed_loader_for_tests::reshard(sstdir, e.db(), "ks", "cf", std::move(make_sstable)).get(); - verify_that_all_sstables_are_local(sstdir, smp::count * smp::count).get(); + verify_that_all_sstables_are_local(sstdir, this_smp_shard_count() * this_smp_shard_count()).get(); }); }); } SEASTAR_TEST_CASE(sstable_directory_shared_sstables_reshard_respect_max_threshold) { - if (smp::count == 1) { + if (this_smp_shard_count() == 1) { fmt::print("Skipping sstable_directory_shared_sstables_reshard_correctly, smp == 1\n"); return make_ready_future<>(); } @@ -708,14 +708,14 @@ SEASTAR_TEST_CASE(sstable_directory_shared_sstables_reshard_respect_max_threshol return cf.disable_auto_compaction(); }).get(); - unsigned num_sstables = (cf.schema()->max_compaction_threshold() + 1) * smp::count; + unsigned num_sstables = (cf.schema()->max_compaction_threshold() + 1) * this_smp_shard_count(); sharded sharded_gen; sharded_gen.start().get(); auto stop_generator = deferred_stop(sharded_gen); for (unsigned nr = 0; nr < num_sstables; ++nr) { - auto generation = sharded_gen.invoke_on(nr % smp::count, [] (auto& gen) { + auto generation = sharded_gen.invoke_on(nr % this_smp_shard_count(), [] (auto& gen) { return gen(); }).get(); make_sstable_for_all_shards(cf, sstables::sstable_state::upload, generation); @@ -737,7 +737,7 @@ SEASTAR_TEST_CASE(sstable_directory_shared_sstables_reshard_respect_max_threshol return cf.get_sstables_manager().make_sstable(cf.schema(), cf.get_storage_options(), generation, sstables::sstable_state::upload); }; distributed_loader_for_tests::reshard(sstdir, e.db(), "ks", "cf", std::move(make_sstable)).get(); - verify_that_all_sstables_are_local(sstdir, 2 * smp::count * smp::count).get(); + verify_that_all_sstables_are_local(sstdir, 2 * this_smp_shard_count() * this_smp_shard_count()).get(); }); }); } @@ -925,17 +925,17 @@ SEASTAR_TEST_CASE(sstable_directory_test_reshard_vnodes) { return cf.disable_auto_compaction(); }).get(); - unsigned num_sstables = 10 * smp::count; + unsigned num_sstables = 10 * this_smp_shard_count(); sharded sharded_gen; sharded_gen.start().get(); auto stop_generator = deferred_stop(sharded_gen); for (unsigned nr = 0; nr < num_sstables; ++nr) { - auto generation = sharded_gen.invoke_on(nr % smp::count, [] (auto& gen) { + auto generation = sharded_gen.invoke_on(nr % this_smp_shard_count(), [] (auto& gen) { return gen(); }).get(); - make_sstable_for_all_shards(cf, sstables::sstable_state::upload, generation, smp::count); + make_sstable_for_all_shards(cf, sstables::sstable_state::upload, generation, this_smp_shard_count()); } with_sstable_directory(e.db(), "ks", "cf", sstables::sstable_state::upload, [&] (sharded& sstdir) { diff --git a/test/boost/sstable_resharding_test.cc b/test/boost/sstable_resharding_test.cc index 66e58ea7b0..32aa94fe5e 100644 --- a/test/boost/sstable_resharding_test.cc +++ b/test/boost/sstable_resharding_test.cc @@ -64,7 +64,7 @@ void run_sstable_resharding_test(sstables::test_env& env) { return m; }; auto cfg = std::make_unique(); - for (auto i : std::views::iota(0u, smp::count)) { + for (auto i : std::views::iota(0u, this_smp_shard_count())) { const auto keys = tests::generate_partition_keys(keys_per_shard, s, i); BOOST_REQUIRE(keys.size() == keys_per_shard); muts[i].reserve(keys_per_shard); @@ -81,7 +81,7 @@ void run_sstable_resharding_test(sstables::test_env& env) { // for a single shard. workaround that by setting shards manually. from this test perspective, // it doesn't matter because we check each partition individually of each sstable created // for a shard that owns the shared input sstable. - sstables::test(sst).set_shards(std::views::iota(0u, smp::count) | std::ranges::to>()); + sstables::test(sst).set_shards(std::views::iota(0u, this_smp_shard_count()) | std::ranges::to>()); auto filter_size = [&env] (shared_sstable sst) -> uint64_t { if (!env.get_storage_options().is_local_type()) { @@ -115,7 +115,7 @@ void run_sstable_resharding_test(sstables::test_env& env) { sst->destroy().get(); auto new_sstables = std::move(res.new_sstables); - BOOST_REQUIRE(new_sstables.size() == smp::count); + BOOST_REQUIRE(new_sstables.size() == this_smp_shard_count()); uint64_t bloom_filter_size_after = 0; std::unordered_set processed_shards; @@ -179,7 +179,7 @@ SEASTAR_TEST_CASE(sstable_is_shared_correctness) { auto s = get_schema(); auto sst_gen = env.make_sst_factory(s, version); - const auto keys = tests::generate_partition_keys(smp::count * 10, s); + const auto keys = tests::generate_partition_keys(this_smp_shard_count() * 10, s); utils::chunked_vector muts; for (auto& k : keys) { muts.push_back(get_mutation(s, k, 0)); @@ -198,7 +198,7 @@ SEASTAR_TEST_CASE(sstable_is_shared_correctness) { auto sst_gen = env.make_sst_factory(single_sharded_s, version); utils::chunked_vector muts; - for (shard_id shard : std::views::iota(0u, smp::count)) { + for (shard_id shard : std::views::iota(0u, this_smp_shard_count())) { const auto keys = tests::generate_partition_keys(10, key_s, shard); for (auto& k : keys) { muts.push_back(get_mutation(single_sharded_s, k, shard)); @@ -208,10 +208,10 @@ SEASTAR_TEST_CASE(sstable_is_shared_correctness) { auto sst = make_sstable_containing(sst_gen, muts).get(); BOOST_REQUIRE(!sst->is_shared()); - auto all_shards_s = get_schema(smp::count, cfg->murmur3_partitioner_ignore_msb_bits()); + auto all_shards_s = get_schema(this_smp_shard_count(), cfg->murmur3_partitioner_ignore_msb_bits()); sst = env.reusable_sst(all_shards_s, sst->generation(), version).get(); - BOOST_REQUIRE(smp::count == 1 || sst->is_shared()); - BOOST_REQUIRE(sst->get_shards_for_this_sstable().size() == smp::count); + BOOST_REQUIRE(this_smp_shard_count() == 1 || sst->is_shared()); + BOOST_REQUIRE(sst->get_shards_for_this_sstable().size() == this_smp_shard_count()); assert_sstable_computes_correct_owners(env, sst).get(); } } diff --git a/test/boost/stall_free_test.cc b/test/boost/stall_free_test.cc index 053b50a095..5c60c7223f 100644 --- a/test/boost/stall_free_test.cc +++ b/test/boost/stall_free_test.cc @@ -221,7 +221,7 @@ SEASTAR_THREAD_TEST_CASE(test_dispose_gently_vector_of_unique_ptrs) { SEASTAR_THREAD_TEST_CASE(test_clear_gently_foreign_unique_ptr) { int cleared_gently = 0; auto make_foreign_ptr = [&cleared_gently] () { - return smp::submit_to((this_shard_id() + 1) % smp::count, [&cleared_gently] { + return smp::submit_to((this_shard_id() + 1) % this_smp_shard_count(), [&cleared_gently] { auto p = std::make_unique>(0, [&cleared_gently, owner_shard = this_shard_id()] (int) { BOOST_REQUIRE_EQUAL(owner_shard, this_shard_id()); cleared_gently++; @@ -246,7 +246,7 @@ SEASTAR_THREAD_TEST_CASE(test_clear_gently_foreign_unique_ptr) { SEASTAR_THREAD_TEST_CASE(test_clear_gently_foreign_unique_ptr_const_payload) { int cleared_gently = 0; auto make_foreign_ptr = [&cleared_gently] () { - return smp::submit_to((this_shard_id() + 1) % smp::count, [&cleared_gently] { + return smp::submit_to((this_shard_id() + 1) % this_smp_shard_count(), [&cleared_gently] { auto p = std::make_unique>(0, [&cleared_gently, owner_shard = this_shard_id()] (int) { BOOST_REQUIRE_EQUAL(owner_shard, this_shard_id()); cleared_gently++; @@ -271,7 +271,7 @@ SEASTAR_THREAD_TEST_CASE(test_clear_gently_foreign_unique_ptr_const_payload) { SEASTAR_THREAD_TEST_CASE(test_dispose_gently_foreign_unique_ptr) { int cleared_gently = 0; auto make_foreign_ptr = [&cleared_gently] () { - return smp::submit_to((this_shard_id() + 1) % smp::count, [&cleared_gently] { + return smp::submit_to((this_shard_id() + 1) % this_smp_shard_count(), [&cleared_gently] { auto p = std::make_unique>(0, [&cleared_gently, owner_shard = this_shard_id()] (int) { BOOST_REQUIRE_EQUAL(owner_shard, this_shard_id()); cleared_gently++; @@ -290,7 +290,7 @@ SEASTAR_THREAD_TEST_CASE(test_dispose_gently_foreign_unique_ptr) { SEASTAR_THREAD_TEST_CASE(test_clear_gently_foreign_shared_ptr) { int cleared_gently = 0; auto make_foreign_ptr = [&cleared_gently] () { - return smp::submit_to((this_shard_id() + 1) % smp::count, [&cleared_gently] { + return smp::submit_to((this_shard_id() + 1) % this_smp_shard_count(), [&cleared_gently] { auto p = make_lw_shared>(0, [&cleared_gently, owner_shard = this_shard_id()] (int) { BOOST_REQUIRE_EQUAL(owner_shard, this_shard_id()); cleared_gently++; @@ -333,7 +333,7 @@ SEASTAR_THREAD_TEST_CASE(test_clear_gently_foreign_shared_ptr) { SEASTAR_THREAD_TEST_CASE(test_clear_gently_foreign_shared_ptr_const_payload) { int cleared_gently = 0; auto make_foreign_ptr = [&cleared_gently] () { - return smp::submit_to((this_shard_id() + 1) % smp::count, [&cleared_gently] { + return smp::submit_to((this_shard_id() + 1) % this_smp_shard_count(), [&cleared_gently] { auto p = make_lw_shared>(0, [&cleared_gently, owner_shard = this_shard_id()] (int) { BOOST_REQUIRE_EQUAL(owner_shard, this_shard_id()); cleared_gently++; @@ -376,7 +376,7 @@ SEASTAR_THREAD_TEST_CASE(test_clear_gently_foreign_shared_ptr_const_payload) { SEASTAR_THREAD_TEST_CASE(test_dispose_gently_foreign_shared_ptr) { int cleared_gently = 0; auto make_foreign_ptr = [&cleared_gently] () { - return smp::submit_to((this_shard_id() + 1) % smp::count, [&cleared_gently] { + return smp::submit_to((this_shard_id() + 1) % this_smp_shard_count(), [&cleared_gently] { auto p = make_lw_shared>(0, [&cleared_gently, owner_shard = this_shard_id()] (int) { BOOST_REQUIRE_EQUAL(owner_shard, this_shard_id()); cleared_gently++; diff --git a/test/boost/tablets_test.cc b/test/boost/tablets_test.cc index 637b18d546..9bfd821e43 100644 --- a/test/boost/tablets_test.cc +++ b/test/boost/tablets_test.cc @@ -5509,12 +5509,12 @@ SEASTAR_THREAD_TEST_CASE(test_get_split_token_is_compatible_with_old_behavior) { SEASTAR_THREAD_TEST_CASE(basic_tablet_storage_splitting_test) { auto cfg = tablet_cql_test_config(); - cfg.initial_tablets = std::bit_floor(smp::count); + cfg.initial_tablets = std::bit_floor(this_smp_shard_count()); do_with_cql_env_thread([] (cql_test_env& e) { e.execute_cql( "CREATE TABLE cf (pk int, ck int, v int, PRIMARY KEY (pk, ck))").get(); - for (unsigned i = 0; i < smp::count * 20; i++) { + for (unsigned i = 0; i < this_smp_shard_count() * 20; i++) { e.execute_cql(format("INSERT INTO cf (pk, ck, v) VALUES ({}, 0, 0)", i)).get(); } @@ -6561,7 +6561,7 @@ SEASTAR_THREAD_TEST_CASE(test_calculate_tablet_replicas_for_new_rf_default_rf_up SEASTAR_TEST_CASE(test_tablet_count_metric) { auto cfg = tablet_cql_test_config(); - for (unsigned n = 1; n <= smp::count; n *= 2) { + for (unsigned n = 1; n <= this_smp_shard_count(); n *= 2) { cfg.initial_tablets = n; } return do_with_cql_env_thread([cfg] (cql_test_env& e) { diff --git a/test/boost/view_schema_test.cc b/test/boost/view_schema_test.cc index c5493a3b1d..14c20d4cf6 100644 --- a/test/boost/view_schema_test.cc +++ b/test/boost/view_schema_test.cc @@ -2602,7 +2602,7 @@ SEASTAR_THREAD_TEST_CASE(node_view_update_backlog) { // This test was originally written assuming we have (at least) two // shards and the test doesn't run on shard 1... BOOST_ASSERT(this_shard_id() != 1); - BOOST_ASSERT(smp::count >= 2); + BOOST_ASSERT(this_smp_shard_count() >= 2); // First, check that a db::view::node_update_backlog object doesn't // recalculate the backlog if the interval hasn't yet passed (we use diff --git a/test/boost/virtual_table_test.cc b/test/boost/virtual_table_test.cc index 1bcd578eda..c37af6e71c 100644 --- a/test/boost/virtual_table_test.cc +++ b/test/boost/virtual_table_test.cc @@ -76,7 +76,7 @@ SEASTAR_THREAD_TEST_CASE(test_system_config_table_read) { } SEASTAR_THREAD_TEST_CASE(test_system_config_table_update) { - if (smp::count < 2) { + if (this_smp_shard_count() < 2) { fmt::print("This test should be run with at least 2 CPUs\n"); return; } diff --git a/test/lib/cql_test_env.cc b/test/lib/cql_test_env.cc index de2ab7ff21..150def3bce 100644 --- a/test/lib/cql_test_env.cc +++ b/test/lib/cql_test_env.cc @@ -567,7 +567,7 @@ private: create_directories(cfg->logstor_directory().c_str()); create_directories(cfg->hints_directory().c_str()); create_directories(cfg->view_hints_directory().c_str()); - for (unsigned i = 0; i < smp::count; ++i) { + for (unsigned i = 0; i < this_smp_shard_count(); ++i) { create_directories((cfg->hints_directory() + "/" + std::to_string(i)).c_str()); create_directories((cfg->view_hints_directory() + "/" + std::to_string(i)).c_str()); } @@ -741,7 +741,7 @@ private: .hints_directory_initializer = db::hints::directory_initializer::make_dummy(), }; spcfg.available_memory = memory::stats().total_memory(); - db::view::node_update_backlog b(smp::count, 10ms); + db::view::node_update_backlog b(this_smp_shard_count(), 10ms); _timeout_config.start(std::ref(*cfg)).get(); auto stop_timeout_config = defer_verbose_shutdown("updateable timeout config", [this] { _timeout_config.stop().get(); }); @@ -811,7 +811,7 @@ private: topo.add_or_update_endpoint(hostid, std::nullopt, locator::node::state::normal, - smp::count); + this_smp_shard_count()); return make_ready_future<>(); }).get(); diff --git a/test/lib/reader_lifecycle_policy.hh b/test/lib/reader_lifecycle_policy.hh index 0519073f56..bcb291de45 100644 --- a/test/lib/reader_lifecycle_policy.hh +++ b/test/lib/reader_lifecycle_policy.hh @@ -56,7 +56,7 @@ public: explicit test_reader_lifecycle_policy(reader_factory_function reader_factory, std::unique_ptr semaphore_factory_object = std::make_unique()) : _reader_factory_function(std::move(reader_factory)) , _semaphore_factory(std::move(semaphore_factory_object)) - , _contexts(smp::count) { + , _contexts(this_smp_shard_count()) { } virtual mutation_reader create_reader( schema_ptr schema, diff --git a/test/perf/memory_footprint_test.cc b/test/perf/memory_footprint_test.cc index 1a6dfcbaac..3409452b77 100644 --- a/test/perf/memory_footprint_test.cc +++ b/test/perf/memory_footprint_test.cc @@ -231,7 +231,7 @@ int main(int argc, char** argv) { ("data-size", bpo::value()->default_value(32), "cell data size"); return app.run(argc, argv, [&] { - if (smp::count != 1) { + if (this_smp_shard_count() != 1) { throw std::runtime_error("This test has to be run with -c1"); } diff --git a/test/perf/perf_alternator.cc b/test/perf/perf_alternator.cc index e54d80565c..9e4bc004c1 100644 --- a/test/perf/perf_alternator.cc +++ b/test/perf/perf_alternator.cc @@ -459,7 +459,7 @@ void workload_main(const test_config& c, sharded* as) { params["remote_host"] = c.remote_host; params["flush"] = c.flush; params["scan_total_segments"] = c.scan_total_segments; - params["cpus"] = smp::count; + params["cpus"] = this_smp_shard_count(); perf::write_json_result(c.json_result_file, agg, params, c.workload); } diff --git a/test/perf/perf_cache_eviction.cc b/test/perf/perf_cache_eviction.cc index dea45cacfb..229686fe28 100644 --- a/test/perf/perf_cache_eviction.cc +++ b/test/perf/perf_cache_eviction.cc @@ -51,7 +51,7 @@ int main(int argc, char** argv) { ; return app.run(argc, argv, [&app] { - if (smp::count != 1) { + if (this_smp_shard_count() != 1) { throw std::runtime_error("This test has to be run with --smp=1"); } diff --git a/test/perf/perf_commitlog.cc b/test/perf/perf_commitlog.cc index 42b38038f6..188f25929f 100644 --- a/test/perf/perf_commitlog.cc +++ b/test/perf/perf_commitlog.cc @@ -51,7 +51,7 @@ static void write_json_result(std::string result_file, const test_config& cfg, c Json::Value params; params["concurrency"] = cfg.concurrency; - params["cpus"] = smp::count; + params["cpus"] = this_smp_shard_count(); params["duration"] = cfg.duration_in_seconds; params["min-data-size"] = cfg.min_data_size; @@ -59,7 +59,7 @@ static void write_json_result(std::string result_file, const test_config& cfg, c params["min-flush-delay-in-ms"] = cfg.min_flush_delay_in_ms; params["max-flush-delay-in-ms"] = cfg.max_flush_delay_in_ms; - params["concurrency,cpus,duration"] = fmt::format("{},{},{}", cfg.concurrency, smp::count, cfg.duration_in_seconds); + params["concurrency,cpus,duration"] = fmt::format("{},{},{}", cfg.concurrency, this_smp_shard_count(), cfg.duration_in_seconds); results["parameters"] = std::move(params); Json::Value stats; diff --git a/test/perf/perf_cql_raw.cc b/test/perf/perf_cql_raw.cc index 406b5b4721..0106917684 100644 --- a/test/perf/perf_cql_raw.cc +++ b/test/perf/perf_cql_raw.cc @@ -763,7 +763,7 @@ static void workload_main(const raw_cql_test_config& cfg, sharded* params["connection_per_request"] = cfg.connection_per_request; params["use_prepared"] = cfg.use_prepared; params["create_non_superuser"] = cfg.create_non_superuser; - params["cpus"] = smp::count; + params["cpus"] = this_smp_shard_count(); perf::write_json_result(cfg.json_result_file, agg, params, cfg.workload); } diff --git a/test/perf/perf_fast_forward.cc b/test/perf/perf_fast_forward.cc index 018d5350fa..d282753791 100644 --- a/test/perf/perf_fast_forward.cc +++ b/test/perf/perf_fast_forward.cc @@ -2085,7 +2085,7 @@ int scylla_fast_forward_main(int argc, char** argv) { table_config cfg{name, n_rows, value_size, compressor}; populate(enabled_datasets, env, cfg, flush_threshold); } else { - if (smp::count != 1) { + if (this_smp_shard_count() != 1) { throw std::runtime_error("The test must be run with one shard"); } diff --git a/test/perf/perf_simple_query.cc b/test/perf/perf_simple_query.cc index 6409ec08ad..389361252f 100644 --- a/test/perf/perf_simple_query.cc +++ b/test/perf/perf_simple_query.cc @@ -284,9 +284,9 @@ void write_json_result(std::string result_file, const test_config& cfg, const ag Json::Value params; params["concurrency"] = cfg.concurrency; params["partitions"] = cfg.partitions; - params["cpus"] = smp::count; + params["cpus"] = this_smp_shard_count(); params["duration"] = cfg.duration_in_seconds; - params["concurrency,partitions,cpus,duration"] = fmt::format("{},{},{},{}", cfg.concurrency, cfg.partitions, smp::count, cfg.duration_in_seconds); + params["concurrency,partitions,cpus,duration"] = fmt::format("{},{},{},{}", cfg.concurrency, cfg.partitions, this_smp_shard_count(), cfg.duration_in_seconds); if (cfg.initial_tablets) { params["initial_tablets"] = cfg.initial_tablets.value(); } diff --git a/test/raft/failure_detector_test.cc b/test/raft/failure_detector_test.cc index aa802f2f9e..fc7d74f2c2 100644 --- a/test/raft/failure_detector_test.cc +++ b/test/raft/failure_detector_test.cc @@ -17,11 +17,11 @@ #include "test/raft/helpers.hh" future<> ping_shards() { - if (smp::count == 1) { + if (this_smp_shard_count() == 1) { return seastar::yield(); } - return parallel_for_each(std::views::iota(0u, smp::count), [] (shard_id s) { + return parallel_for_each(std::views::iota(0u, this_smp_shard_count()), [] (shard_id s) { return smp::submit_to(s, [](){}); }); } diff --git a/test/raft/randomized_nemesis_test.cc b/test/raft/randomized_nemesis_test.cc index abeb51e0a5..98f292cfa5 100644 --- a/test/raft/randomized_nemesis_test.cc +++ b/test/raft/randomized_nemesis_test.cc @@ -2133,11 +2133,11 @@ struct wait_for_leader { }; future<> ping_shards() { - if (smp::count == 1) { + if (this_smp_shard_count() == 1) { return seastar::yield(); } - return parallel_for_each(std::views::iota(0u, smp::count), [] (shard_id s) { + return parallel_for_each(std::views::iota(0u, this_smp_shard_count()), [] (shard_id s) { return smp::submit_to(s, [](){}); }); } diff --git a/test/unit/cross_shard_barrier_test.cc b/test/unit/cross_shard_barrier_test.cc index 093e8b8e15..d895d30dc8 100644 --- a/test/unit/cross_shard_barrier_test.cc +++ b/test/unit/cross_shard_barrier_test.cc @@ -44,17 +44,17 @@ public: , _last_wdog_phase(0) { // Give each shard a good chance to sleep for up to 100ms - auto period = std::chrono::seconds(smp::count * 100); + auto period = std::chrono::seconds(this_smp_shard_count() * 100); // Don't make them fire all at once - auto first = period + this_shard_id() * period / smp::count; + auto first = period + this_shard_id() * period / this_smp_shard_count(); _watchdog.arm(std::chrono::steady_clock::now() + first, {period}); } future<> loop() { - for (unsigned i = 0; i < smp::count * phases_scale; i++) { + for (unsigned i = 0; i < this_smp_shard_count() * phases_scale; i++) { unsigned phase = _phase.fetch_add(1); co_await _barrier.arrive_and_wait(); - if (this_shard_id() == (i % smp::count)) { + if (this_shard_id() == (i % this_smp_shard_count())) { co_await container().invoke_on_all([phase] (auto& w) { auto this_phase = w._phase.load(); if (this_phase != phase + 1) { @@ -92,8 +92,8 @@ public: int main(int argc, char **argv) { app_template app; return app.run(argc, argv, [] { - if (smp::count < 2) { - std::cerr << "Cannot run test with smp::count < 2"; + if (this_smp_shard_count() < 2) { + std::cerr << "Cannot run test with this_smp_shard_count() < 2"; return make_ready_future<>(); } @@ -103,14 +103,14 @@ int main(int argc, char **argv) { w.invoke_on_all(&worker::loop).get(); w.stop().get(); - for (size_t i = 0; i < smp::count * phases_scale; i++) { + for (size_t i = 0; i < this_smp_shard_count() * phases_scale; i++) { sharded w; w.start(utils::cross_shard_barrier()).get(); try { w.invoke_on_all(&worker::loop_with_error).get(); } catch (...) { auto ph = w.invoke_on(0, [] (auto& w) { return w.get_phase(); }).get(); - for (size_t c = 1; c < smp::count; c++) { + for (size_t c = 1; c < this_smp_shard_count(); c++) { auto ph_2 = w.invoke_on(c, [] (auto& w) { return w.get_phase(); }).get(); if (ph_2 != ph) { fmt::print("aborted barrier passed shard through\n"); diff --git a/tools/scylla-sstable.cc b/tools/scylla-sstable.cc index ec25305063..449d9dd69a 100644 --- a/tools/scylla-sstable.cc +++ b/tools/scylla-sstable.cc @@ -1966,7 +1966,7 @@ void shard_of_with_vnodes(const std::vector& sstables, json_writer writer; writer.StartStream(); for (auto& sst : sstables) { - // sst was loaded with the smp::count as its shard_count but that's not + // sst was loaded with the this_smp_shard_count() as its shard_count but that's not // necessarily identical to the "shards" specified in the command line. // reload the sst with the specified shard_count and ignore_msb_bits auto schema = schema_builder(sst->get_schema()).with_sharder( @@ -2091,7 +2091,7 @@ void query_operation(schema_ptr sstable_schema, reader_permit permit, const std: throw std::invalid_argument("cannot provide both -q|--query and --query-file"); } - if (smp::count > 1) { + if (this_smp_shard_count() > 1) { // Assuming smp==1 allows simplifying the code below. throw std::runtime_error("query operation cannot run with --smp > 1"); } diff --git a/transport/server.cc b/transport/server.cc index 167fa12a27..2794bf9e6a 100644 --- a/transport/server.cc +++ b/transport/server.cc @@ -2016,7 +2016,7 @@ std::unique_ptr cql_server::connection::make_supported(int opts.insert({"SCYLLA_HOST_ID", _server._gossiper.my_host_id().to_sstring()}); if (_server._config.allow_shard_aware_drivers) { opts.insert({"SCYLLA_SHARD", format("{:d}", this_shard_id())}); - opts.insert({"SCYLLA_NR_SHARDS", format("{:d}", smp::count)}); + opts.insert({"SCYLLA_NR_SHARDS", format("{:d}", this_smp_shard_count())}); opts.insert({"SCYLLA_SHARDING_ALGORITHM", dht::cpu_sharding_algorithm_name()}); if (_server._config.shard_aware_transport_port) { opts.insert({"SCYLLA_SHARD_AWARE_PORT", format("{:d}", *_server._config.shard_aware_transport_port)}); diff --git a/utils/config_file.cc b/utils/config_file.cc index 08a949f73b..fadc71e4ae 100644 --- a/utils/config_file.cc +++ b/utils/config_file.cc @@ -382,8 +382,8 @@ future<> utils::config_file::read_from_file(const sstring& filename, error_handl future<> utils::config_file::broadcast_to_all_shards() { return async([this] { - if (_per_shard_values.size() != smp::count) { - _per_shard_values.resize(smp::count); + if (_per_shard_values.size() != this_smp_shard_count()) { + _per_shard_values.resize(this_smp_shard_count()); smp::invoke_on_all([this] { auto cpu = this_shard_id(); if (cpu != 0) { diff --git a/utils/cross-shard-barrier.hh b/utils/cross-shard-barrier.hh index e40b7c9968..57af49f202 100644 --- a/utils/cross-shard-barrier.hh +++ b/utils/cross-shard-barrier.hh @@ -69,9 +69,9 @@ class cross_shard_barrier { std::atomic alive; std::vector>> wakeup; - barrier() : counter(smp::count), alive(true) { - wakeup.reserve(smp::count); - for (unsigned i = 0; i < smp::count; i++) { + barrier() : counter(this_smp_shard_count()), alive(true) { + wakeup.reserve(this_smp_shard_count()); + for (unsigned i = 0; i < this_smp_shard_count(); i++) { wakeup.emplace_back(); } } @@ -114,7 +114,7 @@ public: void abort() noexcept { // We can get here from shards that had already visited the // arrive_and_wait() and got the exceptional future. In this - // case the counter would be set to smp::count and none of the + // case the counter would be set to this_smp_shard_count() and none of the // fetch_add(-1)s below will make it call complete() _b->alive.store(false); auto i = _b->counter.fetch_add(-1); @@ -125,7 +125,7 @@ public: private: future<> complete() { - _b->counter.fetch_add(smp::count); + _b->counter.fetch_add(this_smp_shard_count()); bool alive = _b->alive.load(std::memory_order_relaxed); return smp::invoke_on_all([b = _b, sid = this_shard_id(), alive] { if (this_shard_id() != sid) { diff --git a/utils/directories.cc b/utils/directories.cc index fb7259299d..3780cc9983 100644 --- a/utils/directories.cc +++ b/utils/directories.cc @@ -70,7 +70,7 @@ void directories::set::add(std::vector paths) { void directories::set::add_sharded(sstring p) { fs::path path(p); - for (unsigned i = 0; i < smp::count; i++) { + for (unsigned i = 0; i < this_smp_shard_count(); i++) { add(path / seastar::to_sstring(i).c_str()); } }