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:
Benny Halevy
2023-11-29 17:03:20 +02:00
parent 94fc8e2a9a
commit 52412087b7
11 changed files with 40 additions and 31 deletions

View File

@@ -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

View File

@@ -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 }) {

View File

@@ -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]));
}

View File

@@ -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();

View File

@@ -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