snitch: Export prefer-local
The boolean bit says whether "the system" should prefer connecting to the address gossiper around via INTERNAL_IP. Currently only gossiping property file snitch allows to tune it and ec2-multiregion snitch prefers internal IP unconditionally. So exporting consists of 2 pieces: - add prefer_local() snitch method that's false by default or returns the (existing) _prefer_local bit for production snitch base - set the _prefer_local to true by ec2-multiregion snitch While at it the _prefer_local is moved to production_snitch_base for uniformity with the new prefer_local() call Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
This commit is contained in:
@@ -27,7 +27,7 @@ future<> ec2_multi_region_snitch::start() {
|
||||
_state = snitch_state::initializing;
|
||||
|
||||
return seastar::async([this] {
|
||||
ec2_snitch::load_config().get();
|
||||
ec2_snitch::load_config(true).get();
|
||||
if (this_shard_id() == io_cpu_id()) {
|
||||
inet_address local_public_address;
|
||||
|
||||
|
||||
@@ -17,11 +17,11 @@ ec2_snitch::ec2_snitch(const snitch_config& cfg) : production_snitch_base(cfg) {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
future<> ec2_snitch::load_config() {
|
||||
future<> ec2_snitch::load_config(bool prefer_local) {
|
||||
using namespace boost::algorithm;
|
||||
|
||||
if (this_shard_id() == io_cpu_id()) {
|
||||
return aws_api_call(AWS_QUERY_SERVER_ADDR, AWS_QUERY_SERVER_PORT, ZONE_NAME_QUERY_REQ).then([this](sstring az) {
|
||||
return aws_api_call(AWS_QUERY_SERVER_ADDR, AWS_QUERY_SERVER_PORT, ZONE_NAME_QUERY_REQ).then([this, prefer_local](sstring az) {
|
||||
assert(az.size());
|
||||
|
||||
std::vector<std::string> splits;
|
||||
@@ -38,12 +38,15 @@ future<> ec2_snitch::load_config() {
|
||||
_my_dc = az.substr(0, az.size() - 3);
|
||||
}
|
||||
|
||||
return read_property_file().then([this] (sstring datacenter_suffix) {
|
||||
_prefer_local = prefer_local;
|
||||
|
||||
return read_property_file().then([this, prefer_local] (sstring datacenter_suffix) {
|
||||
_my_dc += datacenter_suffix;
|
||||
logger().info("Ec2Snitch using region: {}, zone: {}.", _my_dc, _my_rack);
|
||||
|
||||
return container().invoke_on_others([this] (snitch_ptr& local_s) {
|
||||
return container().invoke_on_others([this, prefer_local] (snitch_ptr& local_s) {
|
||||
local_s->set_my_dc_and_rack(_my_dc, _my_rack);
|
||||
local_s->set_prefer_local(prefer_local);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -55,7 +58,7 @@ future<> ec2_snitch::load_config() {
|
||||
future<> ec2_snitch::start() {
|
||||
_state = snitch_state::initializing;
|
||||
|
||||
return load_config().then([this] {
|
||||
return load_config(false).then([this] {
|
||||
set_snitch_ready();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
return "org.apache.cassandra.locator.Ec2Snitch";
|
||||
}
|
||||
protected:
|
||||
future<> load_config();
|
||||
future<> load_config(bool prefer_local);
|
||||
future<sstring> aws_api_call(sstring addr, uint16_t port, const sstring cmd);
|
||||
future<sstring> read_property_file();
|
||||
private:
|
||||
|
||||
@@ -54,6 +54,10 @@ private:
|
||||
virtual void set_prefer_local(bool prefer_local) override;
|
||||
void parse_property_file();
|
||||
|
||||
virtual bool prefer_local() const noexcept override {
|
||||
return _prefer_local;
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Loads the contents of the property file into the map
|
||||
@@ -95,5 +99,7 @@ protected:
|
||||
private:
|
||||
size_t _prop_file_size;
|
||||
snitch_ptr* _backreference = nullptr;
|
||||
protected:
|
||||
bool _prefer_local = false;
|
||||
};
|
||||
} // namespace locator
|
||||
|
||||
@@ -169,6 +169,11 @@ public:
|
||||
return snitch_signal_connection_t();
|
||||
}
|
||||
|
||||
// tells wheter the INTERNAL_IP address should be preferred over endpoint address
|
||||
virtual bool prefer_local() const noexcept {
|
||||
return false;
|
||||
}
|
||||
|
||||
static logging::logger& logger() {
|
||||
static logging::logger snitch_logger("snitch_logger");
|
||||
return snitch_logger;
|
||||
@@ -348,7 +353,6 @@ private:
|
||||
protected:
|
||||
sstring _my_dc;
|
||||
sstring _my_rack;
|
||||
bool _prefer_local = false;
|
||||
};
|
||||
|
||||
} // namespace locator
|
||||
|
||||
Reference in New Issue
Block a user