Files
scylla/locator/gossiping_property_file_snitch.hh
Pavel Emelyanov 66bc84d217 snitch: Get local address to gossip via config
The property-file snitch gossips listen_address as internal-IP state. To
get this value it gets it from snitch->gossiper->messaging_service
chain. This change provides the needed value via config thus cutting yet
another snitch->gossiper dependency and allowing gossiper not to export
messaging service in the future

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
2022-10-11 05:17:08 +03:00

105 lines
2.7 KiB
C++

/*
*
* Modified by ScyllaDB
* Copyright (C) 2015-present ScyllaDB
*/
/*
* SPDX-License-Identifier: (AGPL-3.0-or-later and Apache-2.0)
*/
#pragma once
#include <sstream>
#include <string>
#include <chrono>
#include <optional>
#include "production_snitch_base.hh"
#include "exceptions/exceptions.hh"
#include <seastar/core/file.hh>
#include "log.hh"
namespace locator {
/**
* cassandra-rackdc.properties file has the following format:
*
* dc=<Data Center name>
* rack=<Rack name>
* prefer_local=<true|false>
*/
class gossiping_property_file_snitch : public production_snitch_base {
public:
// Check the property file for changes every 60s.
static constexpr timer<lowres_clock>::duration reload_property_file_period() {
return std::chrono::seconds(60);
}
virtual std::list<std::pair<gms::application_state, gms::versioned_value>> get_app_states() const override;
virtual future<> stop() override;
virtual future<> start() override;
virtual future<> pause_io() override;
virtual void resume_io() override;
virtual sstring get_name() const override {
return "org.apache.cassandra.locator.GossipingPropertyFileSnitch";
}
gossiping_property_file_snitch(const snitch_config&);
virtual snitch_signal_connection_t when_reconfigured(snitch_signal_slot_t& slot) override {
return _reconfigured.connect([slot = std::move(slot)] () mutable {
// the signal is fired inside thread context
slot().get();
});
}
private:
void periodic_reader_callback();
/**
* Parse the property file and indicate the StorageService and a Gossiper if
* there was a configuration change.
*
* @return a ready-future when we are done
*/
future<> reload_configuration();
/**
* Check if the property file has been modified since the last time we
* parsed it.
*
* @return TRUE if property file has been modified
*/
future<bool> property_file_was_modified();
/**
* Read the propery file if it has changed since the last time we read it.
*/
future<> read_property_file();
/**
* Indicate that the snitch has stopped its I/O.
*/
void set_stopped();
future<> stop_io();
void start_io();
private:
timer<lowres_clock> _file_reader;
std::optional<timespec> _last_file_mod;
std::istringstream _istrm;
bool _file_reader_runs = false;
unsigned _file_reader_cpu_id;
snitch_signal_t _reconfigured;
promise<> _io_is_stopped;
gms::inet_address _listen_address;
void reset_io_state() {
// Reset the promise to allow repeating
// start()+stop()/pause_io()+resume_io() call sequences.
_io_is_stopped = promise<>();
}
};
} // namespace locator