storage_service, topology: Track excluded state in locator::topology

Will be used by tablet load balancer to avoid excluded nodes in
scheduling.
This commit is contained in:
Tomasz Grabiec
2024-01-21 00:20:01 +01:00
parent d59db94f3c
commit 5fccee3a13
3 changed files with 26 additions and 0 deletions

View File

@@ -423,6 +423,12 @@ const node* topology::find_node(host_id id) const noexcept {
return nullptr; return nullptr;
} }
// Finds a node by its host_id
// Returns nullptr if not found
node* topology::find_node(host_id id) noexcept {
return make_mutable(const_cast<const topology*>(this)->find_node(id));
}
// Finds a node by its endpoint // Finds a node by its endpoint
// Returns nullptr if not found // Returns nullptr if not found
const node* topology::find_node(const inet_address& ep) const noexcept { const node* topology::find_node(const inet_address& ep) const noexcept {

View File

@@ -63,6 +63,7 @@ private:
endpoint_dc_rack _dc_rack; endpoint_dc_rack _dc_rack;
state _state; state _state;
shard_id _shard_count = 0; shard_id _shard_count = 0;
bool _excluded = false;
// Is this node the `localhost` instance // Is this node the `localhost` instance
this_node _is_this_node; this_node _is_this_node;
@@ -119,6 +120,16 @@ public:
return _state == state::normal; return _state == state::normal;
} }
// Excluded nodes are still part of topology, possibly present in replica sets, but
// are not going to be up again and can be ignored in barriers.
bool is_excluded() const {
return _excluded;
}
void set_excluded(bool excluded) {
_excluded = excluded;
}
bool is_leaving() const noexcept { bool is_leaving() const noexcept {
switch (_state) { switch (_state) {
case state::being_decommissioned: case state::being_decommissioned:
@@ -208,6 +219,7 @@ public:
// Looks up a node by its host_id. // Looks up a node by its host_id.
// Returns a pointer to the node if found, or nullptr otherwise. // Returns a pointer to the node if found, or nullptr otherwise.
const node* find_node(host_id id) const noexcept; const node* find_node(host_id id) const noexcept;
node* find_node(host_id id) noexcept;
const node& get_node(host_id id) const { const node& get_node(host_id id) const {
auto n = find_node(id); auto n = find_node(id);

View File

@@ -534,6 +534,12 @@ future<> storage_service::sync_raft_topology_nodes(mutable_token_metadata_ptr tm
for (const auto& [id, rs]: t.transition_nodes) { for (const auto& [id, rs]: t.transition_nodes) {
co_await process_transition_node(id, rs); co_await process_transition_node(id, rs);
} }
for (auto id : t.get_excluded_nodes()) {
locator::node* n = tmptr->get_topology().find_node(locator::host_id(id.uuid()));
if (n) {
n->set_excluded(true);
}
}
} }
future<> storage_service::topology_state_load() { future<> storage_service::topology_state_load() {
@@ -634,6 +640,8 @@ future<> storage_service::topology_state_load() {
rtlogger.debug("topology_state_load: current CDC generation ID: {}", *gen_id); rtlogger.debug("topology_state_load: current CDC generation ID: {}", *gen_id);
co_await _cdc_gens.local().handle_cdc_generation(*gen_id); co_await _cdc_gens.local().handle_cdc_generation(*gen_id);
} }
slogger.debug("topology_state_load: excluded nodes: {}", _topology_state_machine._topology.get_excluded_nodes());
} }
future<> storage_service::topology_transition() { future<> storage_service::topology_transition() {