snitch: pass broadcast_address in snitch_config
To untangle snitch from fb_utilities. Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 <boost/algorithm/string/trim.hpp>
|
||||
@@ -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 }) {
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include <seastar/core/sstring.hh>
|
||||
#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]));
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
#pragma once
|
||||
#include "snitch_base.hh"
|
||||
#include "utils/fb_utilities.hh"
|
||||
#include <memory>
|
||||
|
||||
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();
|
||||
|
||||
|
||||
@@ -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_ptr>& 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
|
||||
|
||||
1
main.cc
1
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();
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "locator/gossiping_property_file_snitch.hh"
|
||||
#include "utils/fb_utilities.hh"
|
||||
#include "test/lib/scylla_test_case.hh"
|
||||
#include <seastar/util/std-compat.hh>
|
||||
#include <seastar/core/reactor.hh>
|
||||
@@ -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<sharded<locator::snitch_ptr>>();
|
||||
auto& snitch = *snitch_i;
|
||||
|
||||
|
||||
@@ -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_ptr> 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_ptr> 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_ptr> 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);
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "locator/gossiping_property_file_snitch.hh"
|
||||
#include "utils/fb_utilities.hh"
|
||||
#include "test/lib/scylla_test_case.hh"
|
||||
#include <seastar/util/std-compat.hh>
|
||||
#include <vector>
|
||||
@@ -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<sstring>();
|
||||
auto cpu0_rack_new = make_lw_shared<sstring>();
|
||||
sharded<snitch_ptr> 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) {
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "locator/ec2_snitch.hh"
|
||||
#include "utils/fb_utilities.hh"
|
||||
#include <seastar/testing/test_case.hh>
|
||||
#include <seastar/util/std-compat.hh>
|
||||
#include <vector>
|
||||
@@ -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<sharded<locator::snitch_ptr>>();
|
||||
auto& snitch = *snitch_i;
|
||||
return snitch.start(cfg).then([&snitch] () {
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "locator/gce_snitch.hh"
|
||||
#include "utils/fb_utilities.hh"
|
||||
#include <seastar/testing/test_case.hh>
|
||||
#include <seastar/http/httpd.hh>
|
||||
#include <seastar/net/inet_address.hh>
|
||||
@@ -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_ptr> snitch;
|
||||
snitch.start(cfg).get();
|
||||
snitch.invoke_on_all(&snitch_ptr::start).get();
|
||||
|
||||
Reference in New Issue
Block a user