diff --git a/service/storage_service.cc b/service/storage_service.cc index 7d16d7d1ef..cc3b925564 100644 --- a/service/storage_service.cc +++ b/service/storage_service.cc @@ -1351,12 +1351,7 @@ class topology_coordinator : public endpoint_lifecycle_subscriber { } std::optional get_request_param(raft::server_id id) { - std::optional req_param; - auto rit = _topo_sm._topology.req_param.find(id); - if (rit != _topo_sm._topology.req_param.end()) { - req_param = rit->second; - } - return req_param; + return _topo_sm._topology.get_request_param(id); }; // Returns: @@ -1482,27 +1477,11 @@ class topology_coordinator : public endpoint_lifecycle_subscriber { }; raft::server_id parse_replaced_node(const std::optional& req_param) { - if (req_param) { - auto *param = std::get_if(&*req_param); - if (param) { - return param->replaced_id; - } - } - return {}; + return service::topology::parse_replaced_node(req_param); } std::unordered_set parse_ignore_nodes(const std::optional& req_param) { - if (req_param) { - auto* remove_param = std::get_if(&*req_param); - if (remove_param) { - return remove_param->ignored_ids; - } - auto* rep_param = std::get_if(&*req_param); - if (rep_param) { - return rep_param->ignored_ids; - } - } - return {}; + return service::topology::parse_ignore_nodes(req_param); } inet_address id2ip(locator::host_id id) { @@ -1577,14 +1556,7 @@ class topology_coordinator : public endpoint_lifecycle_subscriber { } std::unordered_set get_excluded_nodes(raft::server_id id, const std::optional& req, const std::optional& req_param) { - auto exclude_nodes = parse_ignore_nodes(req_param); - if (auto replaced_node = parse_replaced_node(req_param)) { - exclude_nodes.insert(replaced_node); - } - if (req && *req == topology_request::remove) { - exclude_nodes.insert(id); - } - return exclude_nodes; + return service::topology::get_excluded_nodes(id, req, req_param); } std::unordered_set get_excluded_nodes(const node_to_work_on& node) { diff --git a/service/topology_state_machine.cc b/service/topology_state_machine.cc index 3d7c1d776d..43e3d94578 100644 --- a/service/topology_state_machine.cc +++ b/service/topology_state_machine.cc @@ -43,6 +43,51 @@ bool topology::is_busy() const { return tstate.has_value(); } +raft::server_id topology::parse_replaced_node(const std::optional& req_param) { + if (req_param) { + auto *param = std::get_if(&*req_param); + if (param) { + return param->replaced_id; + } + } + return {}; +} + +std::unordered_set topology::parse_ignore_nodes(const std::optional& req_param) { + if (req_param) { + auto* remove_param = std::get_if(&*req_param); + if (remove_param) { + return remove_param->ignored_ids; + } + auto* rep_param = std::get_if(&*req_param); + if (rep_param) { + return rep_param->ignored_ids; + } + } + return {}; +} + +std::unordered_set topology::get_excluded_nodes(raft::server_id id, + const std::optional& req, + const std::optional& req_param) { + auto exclude_nodes = parse_ignore_nodes(req_param); + if (auto replaced_node = parse_replaced_node(req_param)) { + exclude_nodes.insert(replaced_node); + } + if (req && *req == topology_request::remove) { + exclude_nodes.insert(id); + } + return exclude_nodes; +} + +std::optional topology::get_request_param(raft::server_id id) const { + auto rit = req_param.find(id); + if (rit != req_param.end()) { + return rit->second; + } + return std::nullopt; +}; + std::set calculate_not_yet_enabled_features(const std::set& enabled_features, const auto& supported_features) { std::set to_enable; bool first = true; diff --git a/service/topology_state_machine.hh b/service/topology_state_machine.hh index 9fe1d29c6a..d0ea7ad626 100644 --- a/service/topology_state_machine.hh +++ b/service/topology_state_machine.hh @@ -177,6 +177,11 @@ struct topology { // Returns false iff we can safely start a new topology change. bool is_busy() const; + std::optional get_request_param(raft::server_id) const; + static raft::server_id parse_replaced_node(const std::optional&); + static std::unordered_set parse_ignore_nodes(const std::optional&); + static std::unordered_set get_excluded_nodes(raft::server_id id, const std::optional& req, const std::optional& req_param); + // Calculates a set of features that are supported by all normal nodes but not yet enabled. std::set calculate_not_yet_enabled_features() const; };