locator: topology: Preserve config when cloning
Config is separate from state of the topology (nodes it contains). Preserving the config will make it easier in later patches to maintain invariants for cloned instances.
This commit is contained in:
@@ -65,14 +65,9 @@ future<> topology::clear_gently() noexcept {
|
||||
co_await utils::clear_gently(_nodes);
|
||||
}
|
||||
|
||||
topology::topology() noexcept
|
||||
: _shard(this_shard_id())
|
||||
{
|
||||
tlogger.trace("topology[{}]: default-constructed", fmt::ptr(this));
|
||||
}
|
||||
|
||||
topology::topology(config cfg)
|
||||
: _shard(this_shard_id())
|
||||
, _cfg(cfg)
|
||||
, _sort_by_proximity(!cfg.disable_proximity_sorting)
|
||||
{
|
||||
tlogger.trace("topology[{}]: constructing using config: host_id={} endpoint={} dc={} rack={}", fmt::ptr(this),
|
||||
@@ -84,6 +79,7 @@ topology::topology(config cfg)
|
||||
|
||||
topology::topology(topology&& o) noexcept
|
||||
: _shard(o._shard)
|
||||
, _cfg(std::move(o._cfg))
|
||||
, _nodes(std::move(o._nodes))
|
||||
, _nodes_by_host_id(std::move(o._nodes_by_host_id))
|
||||
, _nodes_by_endpoint(std::move(o._nodes_by_endpoint))
|
||||
@@ -105,7 +101,7 @@ topology::topology(topology&& o) noexcept
|
||||
}
|
||||
|
||||
future<topology> topology::clone_gently() const {
|
||||
topology ret;
|
||||
topology ret(_cfg);
|
||||
tlogger.debug("topology[{}]: clone_gently to {} from shard {}", fmt::ptr(this), fmt::ptr(&ret), _shard);
|
||||
for (const auto& nptr : _nodes) {
|
||||
if (nptr) {
|
||||
|
||||
@@ -115,6 +115,8 @@ public:
|
||||
future<> clear_gently() noexcept;
|
||||
|
||||
public:
|
||||
const config& get_config() const noexcept { return _cfg; }
|
||||
|
||||
const node* this_node() const noexcept {
|
||||
return _nodes.size() ? _nodes.front().get() : nullptr;
|
||||
}
|
||||
@@ -253,9 +255,6 @@ public:
|
||||
void for_each_node(std::function<void(const node*)> func) const;
|
||||
|
||||
private:
|
||||
// default constructor for cloning purposes
|
||||
topology() noexcept;
|
||||
|
||||
const node* add_node(node_holder node);
|
||||
void remove_node(const node* node);
|
||||
|
||||
@@ -281,6 +280,7 @@ private:
|
||||
std::weak_ordering compare_endpoints(const inet_address& address, const inet_address& a1, const inet_address& a2) const;
|
||||
|
||||
unsigned _shard;
|
||||
config _cfg;
|
||||
std::vector<node_holder> _nodes;
|
||||
std::unordered_map<host_id, const node*> _nodes_by_host_id;
|
||||
std::unordered_map<inet_address, const node*> _nodes_by_endpoint;
|
||||
|
||||
Reference in New Issue
Block a user