From 0ec700cd00556ce7ddb272800d9922bd62cbd4ee Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Thu, 20 Apr 2023 23:38:21 +0200 Subject: [PATCH] locator: topology: Fix move assignment Defaulted assignment doesn't update node::_topology. --- locator/topology.cc | 8 ++++++++ locator/topology.hh | 4 +++- test/boost/locator_topology_test.cc | 27 +++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/locator/topology.cc b/locator/topology.cc index dfc6e432c2..07a2dbca56 100644 --- a/locator/topology.cc +++ b/locator/topology.cc @@ -99,6 +99,14 @@ topology::topology(topology&& o) noexcept } } +topology& topology::operator=(topology&& o) noexcept { + if (this != &o) { + this->~topology(); + new (this) topology(std::move(o)); + } + return *this; +} + future topology::clone_gently() const { topology ret(_cfg); tlogger.debug("topology[{}]: clone_gently to {} from shard {}", fmt::ptr(this), fmt::ptr(&ret), _shard); diff --git a/locator/topology.hh b/locator/topology.hh index 40366cb693..ad826d5840 100644 --- a/locator/topology.hh +++ b/locator/topology.hh @@ -111,11 +111,13 @@ public: inet_address this_endpoint; endpoint_dc_rack local_dc_rack; bool disable_proximity_sorting = false; + + bool operator==(const config&) const = default; }; topology(config cfg); topology(topology&&) noexcept; - topology& operator=(topology&&) = default; + topology& operator=(topology&&) noexcept; future clone_gently() const; future<> clear_gently() noexcept; diff --git a/test/boost/locator_topology_test.cc b/test/boost/locator_topology_test.cc index 204e34ee56..55bd898139 100644 --- a/test/boost/locator_topology_test.cc +++ b/test/boost/locator_topology_test.cc @@ -66,6 +66,33 @@ SEASTAR_THREAD_TEST_CASE(test_add_node) { topo.clear_gently().get(); } +SEASTAR_THREAD_TEST_CASE(test_moving) { + auto id1 = host_id::create_random_id(); + auto ep1 = gms::inet_address("127.0.0.1"); + + utils::fb_utilities::set_broadcast_address(ep1); + topology::config cfg = { + .this_host_id = id1, + .this_endpoint = ep1, + .local_dc_rack = endpoint_dc_rack::default_location, + }; + + auto topo = topology(cfg); + + topo.add_node(id1, ep1, endpoint_dc_rack::default_location, node::state::normal); + + BOOST_REQUIRE(topo.this_node()->topology() == &topo); + + topology topo2(std::move(topo)); + BOOST_REQUIRE(topo2.this_node()->topology() == &topo2); + BOOST_REQUIRE(!topo.this_node()); + BOOST_REQUIRE(topo2.get_config() == cfg); + + topo = std::move(topo2); + BOOST_REQUIRE(topo.this_node()->topology() == &topo); + BOOST_REQUIRE(!topo2.this_node()); + BOOST_REQUIRE(topo.get_config() == cfg); +} SEASTAR_THREAD_TEST_CASE(test_update_node) { auto id1 = host_id::create_random_id();