From fa59ccb89d06755b6ed1200debe6046417c8daf6 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Thu, 7 Apr 2022 19:53:01 +0300 Subject: [PATCH] snitch: Declare snitch_ptr peering and rework container() method This patch makes the snitch base class reference local snitch_ptr, not its sharded<> container and, respectively, makes the base container() method return _backreference->container() instead. The motivation of this change is, again, in the next patch, which will move snitch_ptr<->driver_object linkage into snitch_ptr constructor. Signed-off-by: Pavel Emelyanov --- locator/production_snitch_base.cc | 4 ++-- locator/production_snitch_base.hh | 8 ++++---- locator/snitch_base.hh | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/locator/production_snitch_base.cc b/locator/production_snitch_base.cc index 5644fb922a..9f852622f3 100644 --- a/locator/production_snitch_base.cc +++ b/locator/production_snitch_base.cc @@ -58,8 +58,8 @@ sstring production_snitch_base::get_datacenter(inet_address endpoint) { default_dc); } -void production_snitch_base::set_my_distributed(distributed* d) { - _my_distributed = d; +void production_snitch_base::set_backreference(snitch_ptr& d) { + _backreference = &d; } void production_snitch_base::reset_io_state() { diff --git a/locator/production_snitch_base.hh b/locator/production_snitch_base.hh index 707730b4bf..8d7c398a89 100644 --- a/locator/production_snitch_base.hh +++ b/locator/production_snitch_base.hh @@ -44,7 +44,7 @@ public: virtual sstring get_rack(inet_address endpoint) override; virtual sstring get_datacenter(inet_address endpoint) override; - virtual void set_my_distributed(distributed* d) override; + virtual void set_backreference(snitch_ptr& d) override; void reset_io_state(); @@ -81,12 +81,12 @@ protected: std::unordered_map _prop_values; sharded& container() noexcept { - assert(_my_distributed != nullptr); - return *_my_distributed; + assert(_backreference != nullptr); + return _backreference->container(); } private: size_t _prop_file_size; - distributed* _my_distributed = nullptr; + snitch_ptr* _backreference = nullptr; }; } // namespace locator diff --git a/locator/snitch_base.hh b/locator/snitch_base.hh index 7161fba839..9cbfa703b1 100644 --- a/locator/snitch_base.hh +++ b/locator/snitch_base.hh @@ -155,7 +155,7 @@ public: virtual sstring get_name() const = 0; // should be called for production snitches before calling start() - virtual void set_my_distributed(distributed* d) { + virtual void set_backreference(snitch_ptr& d) { //noop by default } @@ -191,7 +191,7 @@ protected: } _state = snitch_state::initializing; }; -struct snitch_ptr { +struct snitch_ptr : public peering_sharded_service { using ptr_type = i_endpoint_snitch::ptr_type; future<> stop() { if (_ptr) { @@ -253,13 +253,13 @@ future<> i_endpoint_snitch::init_snitch_obj( [&snitch_obj, snitch_name = std::move(snitch_name), a = std::make_tuple(std::forward(a)...)] () { // ...then, create the snitches... return snitch_obj.invoke_on_all( - [snitch_name, a, &snitch_obj] (snitch_ptr& local_inst) { + [snitch_name, a] (snitch_ptr& local_inst) { try { auto s(std::move(apply([snitch_name] (A&&... a) { return create_object(snitch_name, std::forward(a)...); }, std::move(a)))); - s->set_my_distributed(&snitch_obj); + s->set_backreference(local_inst); local_inst = std::move(s); } catch (no_such_class& e) { logger().error("Can't create snitch {}: not supported", snitch_name); @@ -370,7 +370,7 @@ future<> i_endpoint_snitch::reset_snitch( // per-shard level (since users are holding snitch_ptr objects only) // tmp_snitch.invoke_on_all([] (snitch_ptr& local_inst) { - local_inst->set_my_distributed(&snitch_instance()); + local_inst->set_backreference(snitch_instance().local()); snitch_instance().local() = std::move(local_inst); return make_ready_future<>();