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 <xemul@scylladb.com>
This commit is contained in:
@@ -58,8 +58,8 @@ sstring production_snitch_base::get_datacenter(inet_address endpoint) {
|
||||
default_dc);
|
||||
}
|
||||
|
||||
void production_snitch_base::set_my_distributed(distributed<snitch_ptr>* d) {
|
||||
_my_distributed = d;
|
||||
void production_snitch_base::set_backreference(snitch_ptr& d) {
|
||||
_backreference = &d;
|
||||
}
|
||||
|
||||
void production_snitch_base::reset_io_state() {
|
||||
|
||||
@@ -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<snitch_ptr>* d) override;
|
||||
virtual void set_backreference(snitch_ptr& d) override;
|
||||
|
||||
void reset_io_state();
|
||||
|
||||
@@ -81,12 +81,12 @@ protected:
|
||||
std::unordered_map<sstring, sstring> _prop_values;
|
||||
|
||||
sharded<snitch_ptr>& container() noexcept {
|
||||
assert(_my_distributed != nullptr);
|
||||
return *_my_distributed;
|
||||
assert(_backreference != nullptr);
|
||||
return _backreference->container();
|
||||
}
|
||||
|
||||
private:
|
||||
size_t _prop_file_size;
|
||||
distributed<snitch_ptr>* _my_distributed = nullptr;
|
||||
snitch_ptr* _backreference = nullptr;
|
||||
};
|
||||
} // namespace locator
|
||||
|
||||
@@ -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<snitch_ptr>* 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<snitch_ptr> {
|
||||
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>(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<i_endpoint_snitch>(snitch_name, std::forward<A>(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<>();
|
||||
|
||||
Reference in New Issue
Block a user