snitch: Introduce container() method
Some snitch drivers want the peering_sharded_service::container() functionality, but they can't directly use it, because the driver class is in fact the pimplification behind the sharded<snitch_ptr> service. To overcome this there's a _my_distributed pointer on the driver base class that points back to sharded<snitch_ptr> object. This patch replaces the direct _my_distributed usage with the container() method that does it and also asserts that the pointer in question is initialized (some drivers already do it, some don't). Other than making the code more peering_sharded_service-like, this patch allows changing _my_distributed into _backreference that points to this shard's snitch_ptr, see next patch. Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
This commit is contained in:
@@ -46,7 +46,7 @@ future<> azure_snitch::load_config() {
|
||||
_my_rack = azure_zone;
|
||||
_my_dc = azure_region;
|
||||
|
||||
co_return co_await _my_distributed->invoke_on_all([this] (snitch_ptr& local_s) {
|
||||
co_return co_await container().invoke_on_all([this] (snitch_ptr& local_s) {
|
||||
// Distribute the new values on all CPUs but the current one
|
||||
if (this_shard_id() != io_cpu_id()) {
|
||||
local_s->set_my_dc(_my_dc);
|
||||
|
||||
@@ -74,7 +74,7 @@ future<> ec2_multi_region_snitch::start() {
|
||||
// set on the shard0 so that it may be used when Gossiper is
|
||||
// going to invoke gossiper_starting() method.
|
||||
//
|
||||
_my_distributed->invoke_on(0, [this] (snitch_ptr& local_s) {
|
||||
container().invoke_on(0, [this] (snitch_ptr& local_s) {
|
||||
if (this_shard_id() != io_cpu_id()) {
|
||||
local_s->set_local_private_addr(_local_private_address);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ future<> ec2_snitch::load_config() {
|
||||
_my_dc += datacenter_suffix;
|
||||
logger().info("Ec2Snitch using region: {}, zone: {}.", _my_dc, _my_rack);
|
||||
|
||||
return _my_distributed->invoke_on_all(
|
||||
return container().invoke_on_all(
|
||||
[this] (snitch_ptr& local_s) {
|
||||
|
||||
// Distribute the new values on all CPUs but the current one
|
||||
|
||||
@@ -61,7 +61,7 @@ future<> gce_snitch::load_config() {
|
||||
_my_dc += datacenter_suffix;
|
||||
logger().info("GCESnitch using region: {}, zone: {}.", _my_dc, _my_rack);
|
||||
|
||||
return _my_distributed->invoke_on_all([this] (snitch_ptr& local_s) {
|
||||
return container().invoke_on_all([this] (snitch_ptr& local_s) {
|
||||
// Distribute the new values on all CPUs but the current one
|
||||
if (this_shard_id() != io_cpu_id()) {
|
||||
local_s->set_my_dc(_my_dc);
|
||||
|
||||
@@ -168,9 +168,7 @@ future<> gossiping_property_file_snitch::reload_configuration() {
|
||||
_my_rack = new_rack;
|
||||
_prefer_local = new_prefer_local;
|
||||
|
||||
assert(_my_distributed);
|
||||
|
||||
return _my_distributed->invoke_on_all(
|
||||
return container().invoke_on_all(
|
||||
[this] (snitch_ptr& local_s) {
|
||||
|
||||
// Distribute the new values on all CPUs but the current one
|
||||
@@ -187,14 +185,14 @@ future<> gossiping_property_file_snitch::reload_configuration() {
|
||||
|
||||
return seastar::async([this] {
|
||||
// reload Gossiper state (executed on CPU0 only)
|
||||
_my_distributed->invoke_on(0, [] (snitch_ptr& local_snitch_ptr) {
|
||||
container().invoke_on(0, [] (snitch_ptr& local_snitch_ptr) {
|
||||
return local_snitch_ptr->reload_gossiper_state();
|
||||
}).get();
|
||||
|
||||
_reconfigured();
|
||||
|
||||
// spread the word...
|
||||
_my_distributed->invoke_on(0, [] (snitch_ptr& local_snitch_ptr) {
|
||||
container().invoke_on(0, [] (snitch_ptr& local_snitch_ptr) {
|
||||
auto& gossiper = gms::get_local_gossiper();
|
||||
if (gossiper.is_enabled()) {
|
||||
return gossiper.add_local_application_state(local_snitch_ptr->get_app_states());
|
||||
|
||||
@@ -76,12 +76,17 @@ protected:
|
||||
protected:
|
||||
promise<> _io_is_stopped;
|
||||
std::optional<addr2dc_rack_map> _saved_endpoints;
|
||||
distributed<snitch_ptr>* _my_distributed = nullptr;
|
||||
std::string _prop_file_contents;
|
||||
sstring _prop_file_name;
|
||||
std::unordered_map<sstring, sstring> _prop_values;
|
||||
|
||||
sharded<snitch_ptr>& container() noexcept {
|
||||
assert(_my_distributed != nullptr);
|
||||
return *_my_distributed;
|
||||
}
|
||||
|
||||
private:
|
||||
size_t _prop_file_size;
|
||||
distributed<snitch_ptr>* _my_distributed = nullptr;
|
||||
};
|
||||
} // namespace locator
|
||||
|
||||
Reference in New Issue
Block a user