diff --git a/locator/ec2_multi_region_snitch.cc b/locator/ec2_multi_region_snitch.cc index 682e0cbb9f..61ae2aed13 100644 --- a/locator/ec2_multi_region_snitch.cc +++ b/locator/ec2_multi_region_snitch.cc @@ -30,7 +30,7 @@ future<> ec2_multi_region_snitch::start() { auto token = co_await aws_api_call(AWS_QUERY_SERVER_ADDR, AWS_QUERY_SERVER_PORT, TOKEN_REQ_ENDPOINT, std::nullopt); try { - auto broadcast = utils::fb_utilities::get_broadcast_address(); + auto broadcast = _cfg.broadcast_address; if (broadcast.addr().is_ipv6()) { auto macs = co_await aws_api_call(AWS_QUERY_SERVER_ADDR, AWS_QUERY_SERVER_PORT, PRIVATE_MAC_QUERY, token); // we should just get a single line, ending in '/'. If there are more than one mac, we should diff --git a/locator/production_snitch_base.cc b/locator/production_snitch_base.cc index 3f954ce9b0..f1e8b18c4e 100644 --- a/locator/production_snitch_base.cc +++ b/locator/production_snitch_base.cc @@ -10,7 +10,6 @@ #include "db/system_keyspace.hh" #include "gms/gossiper.hh" #include "message/messaging_service.hh" -#include "utils/fb_utilities.hh" #include "db/config.hh" #include @@ -21,7 +20,8 @@ namespace locator { production_snitch_base::production_snitch_base(snitch_config cfg) - : allowed_property_keys({ dc_property_key, + : snitch_base(cfg) + , allowed_property_keys({ dc_property_key, rack_property_key, prefer_local_property_key, dc_suffix_property_key }) { diff --git a/locator/rack_inferring_snitch.hh b/locator/rack_inferring_snitch.hh index 0497a7d245..c6dbbe78ef 100644 --- a/locator/rack_inferring_snitch.hh +++ b/locator/rack_inferring_snitch.hh @@ -13,7 +13,6 @@ #include #include "gms/inet_address.hh" #include "snitch_base.hh" -#include "utils/fb_utilities.hh" namespace locator { @@ -24,7 +23,9 @@ using inet_address = gms::inet_address; * in the 2nd and 3rd octets of the ip address, respectively. */ struct rack_inferring_snitch : public snitch_base { - rack_inferring_snitch(const snitch_config& cfg) { + rack_inferring_snitch(const snitch_config& cfg) + : snitch_base(cfg) + { _my_dc = get_datacenter(); _my_rack = get_rack(); @@ -33,12 +34,12 @@ struct rack_inferring_snitch : public snitch_base { } virtual sstring get_rack() const override { - auto endpoint = utils::fb_utilities::get_broadcast_address(); + auto& endpoint = _cfg.broadcast_address; return std::to_string(uint8_t(endpoint.bytes()[2])); } virtual sstring get_datacenter() const override { - auto endpoint = utils::fb_utilities::get_broadcast_address(); + auto& endpoint = _cfg.broadcast_address; return std::to_string(uint8_t(endpoint.bytes()[1])); } diff --git a/locator/simple_snitch.hh b/locator/simple_snitch.hh index 1e2954b48b..bbcd60e90f 100644 --- a/locator/simple_snitch.hh +++ b/locator/simple_snitch.hh @@ -10,7 +10,6 @@ #pragma once #include "snitch_base.hh" -#include "utils/fb_utilities.hh" #include namespace locator { @@ -21,7 +20,9 @@ namespace locator { * which improves cache locality. */ struct simple_snitch : public snitch_base { - simple_snitch(const snitch_config& cfg) { + simple_snitch(const snitch_config& cfg) + : snitch_base(cfg) + { _my_dc = get_datacenter(); _my_rack = get_rack(); diff --git a/locator/snitch_base.hh b/locator/snitch_base.hh index 7ff98b9a60..3fe01c8c2d 100644 --- a/locator/snitch_base.hh +++ b/locator/snitch_base.hh @@ -49,6 +49,7 @@ struct snitch_config { // Gossiping-property-file specific gms::inet_address listen_address; + gms::inet_address broadcast_address; // GCE-specific sstring gce_meta_server_url = ""; @@ -286,6 +287,8 @@ inline future<> i_endpoint_snitch::reset_snitch(sharded& snitch, sni class snitch_base : public i_endpoint_snitch { public: + snitch_base(const snitch_config& cfg) : _cfg(cfg) {} + // // Sons have to implement: // virtual sstring get_rack() = 0; @@ -297,6 +300,7 @@ public: protected: sstring _my_dc; sstring _my_rack; + snitch_config _cfg; }; } // namespace locator diff --git a/main.cc b/main.cc index 5ddbe5e5e0..8b230cc32e 100644 --- a/main.cc +++ b/main.cc @@ -874,6 +874,7 @@ To start the scylla server proper, simply invoke as: scylla server (or just scyl snitch_config snitch_cfg; snitch_cfg.name = cfg->endpoint_snitch(); snitch_cfg.listen_address = utils::resolve(cfg->listen_address, family).get0(); + snitch_cfg.broadcast_address = broadcast_addr; snitch.start(snitch_cfg).get(); auto stop_snitch = defer_verbose_shutdown("snitch", [&snitch] { snitch.stop().get(); diff --git a/test/boost/gossiping_property_file_snitch_test.cc b/test/boost/gossiping_property_file_snitch_test.cc index 3fab0e7c16..fa4cdd6f84 100644 --- a/test/boost/gossiping_property_file_snitch_test.cc +++ b/test/boost/gossiping_property_file_snitch_test.cc @@ -9,7 +9,6 @@ #include #include "locator/gossiping_property_file_snitch.hh" -#include "utils/fb_utilities.hh" #include "test/lib/scylla_test_case.hh" #include #include @@ -32,14 +31,15 @@ future<> one_test(const std::string& property_fname, bool exp_result) { path fname(test_files_subdir); fname /= path(property_fname); - utils::fb_utilities::set_broadcast_address(gms::inet_address("localhost")); - utils::fb_utilities::set_broadcast_rpc_address(gms::inet_address("localhost")); - engine().set_strict_dma(false); + auto my_address = gms::inet_address("localhost"); + snitch_config cfg; cfg.name = "org.apache.cassandra.locator.GossipingPropertyFileSnitch"; cfg.properties_file_name = fname.string(); + cfg.listen_address = my_address; + cfg.broadcast_address = my_address; auto snitch_i = std::make_unique>(); auto& snitch = *snitch_i; diff --git a/test/boost/network_topology_strategy_test.cc b/test/boost/network_topology_strategy_test.cc index 99b5233926..240ea70272 100644 --- a/test/boost/network_topology_strategy_test.cc +++ b/test/boost/network_topology_strategy_test.cc @@ -225,19 +225,20 @@ locator::endpoint_dc_rack make_endpoint_dc_rack(gms::inet_address endpoint) { // Run in a seastar thread. void simple_test() { - utils::fb_utilities::set_broadcast_address(gms::inet_address("localhost")); - utils::fb_utilities::set_broadcast_rpc_address(gms::inet_address("localhost")); + auto my_address = gms::inet_address("localhost"); // Create the RackInferringSnitch snitch_config cfg; cfg.name = "RackInferringSnitch"; + cfg.listen_address = my_address; + cfg.broadcast_address = my_address; sharded snitch; snitch.start(cfg).get(); auto stop_snitch = defer([&snitch] { snitch.stop().get(); }); snitch.invoke_on_all(&snitch_ptr::start).get(); locator::token_metadata::config tm_cfg; - tm_cfg.topo_cfg.this_endpoint = utils::fb_utilities::get_broadcast_address(); + tm_cfg.topo_cfg.this_endpoint = my_address; tm_cfg.topo_cfg.local_dc_rack = { snitch.local()->get_datacenter(), snitch.local()->get_rack() }; locator::shared_token_metadata stm([] () noexcept { return db::schema_tables::hold_merge_lock(); }, tm_cfg); @@ -307,12 +308,13 @@ void simple_test() { // Run in a seastar thread. void heavy_origin_test() { - utils::fb_utilities::set_broadcast_address(gms::inet_address("localhost")); - utils::fb_utilities::set_broadcast_rpc_address(gms::inet_address("localhost")); + auto my_address = gms::inet_address("localhost"); // Create the RackInferringSnitch snitch_config cfg; cfg.name = "RackInferringSnitch"; + cfg.listen_address = my_address; + cfg.broadcast_address = my_address; sharded snitch; snitch.start(cfg).get(); auto stop_snitch = defer([&snitch] { snitch.stop().get(); }); @@ -386,11 +388,12 @@ SEASTAR_THREAD_TEST_CASE(NetworkTopologyStrategy_heavy) { } SEASTAR_THREAD_TEST_CASE(NetworkTopologyStrategy_tablets_test) { - utils::fb_utilities::set_broadcast_address(gms::inet_address("localhost")); - utils::fb_utilities::set_broadcast_rpc_address(gms::inet_address("localhost")); + auto my_address = gms::inet_address("localhost"); // Create the RackInferringSnitch snitch_config cfg; + cfg.listen_address = my_address; + cfg.broadcast_address = my_address; cfg.name = "RackInferringSnitch"; sharded snitch; snitch.start(cfg).get(); @@ -398,7 +401,7 @@ SEASTAR_THREAD_TEST_CASE(NetworkTopologyStrategy_tablets_test) { snitch.invoke_on_all(&snitch_ptr::start).get(); locator::token_metadata::config tm_cfg; - tm_cfg.topo_cfg.this_endpoint = utils::fb_utilities::get_broadcast_address(); + tm_cfg.topo_cfg.this_endpoint = my_address; tm_cfg.topo_cfg.local_dc_rack = { snitch.local()->get_datacenter(), snitch.local()->get_rack() }; locator::shared_token_metadata stm([] () noexcept { return db::schema_tables::hold_merge_lock(); }, tm_cfg); diff --git a/test/boost/snitch_reset_test.cc b/test/boost/snitch_reset_test.cc index ac8dd31e53..4e8ae0dc23 100644 --- a/test/boost/snitch_reset_test.cc +++ b/test/boost/snitch_reset_test.cc @@ -9,7 +9,6 @@ #include #include "locator/gossiping_property_file_snitch.hh" -#include "utils/fb_utilities.hh" #include "test/lib/scylla_test_case.hh" #include #include @@ -26,9 +25,6 @@ future<> one_test(const std::string& property_fname1, using namespace locator; using namespace std::filesystem; - utils::fb_utilities::set_broadcast_address(gms::inet_address("localhost")); - utils::fb_utilities::set_broadcast_rpc_address(gms::inet_address("localhost")); - printf("Testing %s and %s property files. Expected result is %s\n", property_fname1.c_str(), property_fname2.c_str(), (exp_result ? "success" : "failure")); @@ -39,6 +35,7 @@ future<> one_test(const std::string& property_fname1, auto cpu0_dc_new = make_lw_shared(); auto cpu0_rack_new = make_lw_shared(); sharded snitch; + auto my_address = gms::inet_address("localhost"); try { path fname1(test_files_subdir); @@ -51,6 +48,8 @@ future<> one_test(const std::string& property_fname1, snitch_config cfg; cfg.name = "org.apache.cassandra.locator.GossipingPropertyFileSnitch"; cfg.properties_file_name = fname1.string(); + cfg.listen_address = my_address; + cfg.broadcast_address = my_address; snitch.start(cfg).get(); snitch.invoke_on_all(&snitch_ptr::start).get(); } catch (std::exception& e) { diff --git a/test/manual/ec2_snitch_test.cc b/test/manual/ec2_snitch_test.cc index 4a2a2a5d26..4b287ae468 100644 --- a/test/manual/ec2_snitch_test.cc +++ b/test/manual/ec2_snitch_test.cc @@ -9,7 +9,6 @@ #include #include "locator/ec2_snitch.hh" -#include "utils/fb_utilities.hh" #include #include #include @@ -31,12 +30,13 @@ future<> one_test(const std::string& property_fname, bool exp_result) { path fname(test_files_subdir); fname /= path(property_fname); - utils::fb_utilities::set_broadcast_address(gms::inet_address("localhost")); - utils::fb_utilities::set_broadcast_rpc_address(gms::inet_address("localhost")); + auto my_address = gms::inet_address("localhost"); snitch_config cfg; cfg.name = "Ec2Snitch"; cfg.properties_file_name = fname.string(); + cfg.listen_address = my_address; + cfg.broadcast_address = my_address; auto snitch_i = std::make_unique>(); auto& snitch = *snitch_i; return snitch.start(cfg).then([&snitch] () { diff --git a/test/manual/gce_snitch_test.cc b/test/manual/gce_snitch_test.cc index 6e5713b033..042c6198a5 100644 --- a/test/manual/gce_snitch_test.cc +++ b/test/manual/gce_snitch_test.cc @@ -21,7 +21,6 @@ #include #include "locator/gce_snitch.hh" -#include "utils/fb_utilities.hh" #include #include #include @@ -54,8 +53,7 @@ future<> one_test(const std::string& property_fname, bool exp_result) { fs::path fname(test_files_subdir); fname /= fs::path(property_fname); - utils::fb_utilities::set_broadcast_address(gms::inet_address("localhost")); - utils::fb_utilities::set_broadcast_rpc_address(gms::inet_address("localhost")); + auto my_address = gms::inet_address("localhost"); char* meta_url_env = std::getenv(DUMMY_META_SERVER_IP); char* use_gce_server = std::getenv(USE_GCE_META_SERVER); @@ -84,6 +82,8 @@ future<> one_test(const std::string& property_fname, bool exp_result) { cfg.name = "GoogleCloudSnitch"; cfg.properties_file_name = fname.string(); cfg.gce_meta_server_url = meta_url; + cfg.listen_address = my_address; + cfg.broadcast_address = my_address; sharded snitch; snitch.start(cfg).get(); snitch.invoke_on_all(&snitch_ptr::start).get();