locator: topology: node::state: make fine grained
Currently the node::state is coarse grained so one cannot distinguish between e.g. a leaving node due to decommission (where the node is used for reading) vs. due to remove node (where the node is not used for reading). Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
This commit is contained in:
@@ -47,11 +47,14 @@ node_holder node::clone() const {
|
||||
|
||||
std::string node::to_string(node::state s) {
|
||||
switch (s) {
|
||||
case state::none: return "none";
|
||||
case state::joining: return "joining";
|
||||
case state::normal: return "normal";
|
||||
case state::leaving: return "leaving";
|
||||
case state::left: return "left";
|
||||
case state::none: return "none";
|
||||
case state::bootstrapping: return "bootstrapping";
|
||||
case state::replacing: return "replacing";
|
||||
case state::normal: return "normal";
|
||||
case state::being_decommissioned: return "being_decommissioned";
|
||||
case state::being_removed: return "being_removed";
|
||||
case state::being_replaced: return "being_replaced";
|
||||
case state::left: return "left";
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}
|
||||
@@ -311,9 +314,9 @@ void topology::index_node(const node* node) {
|
||||
if (node->endpoint() != inet_address{}) {
|
||||
auto eit = _nodes_by_endpoint.find(node->endpoint());
|
||||
if (eit != _nodes_by_endpoint.end()) {
|
||||
if (eit->second->get_state() == node::state::leaving || eit->second->get_state() == node::state::left) {
|
||||
if (eit->second->is_leaving() || eit->second->left()) {
|
||||
_nodes_by_endpoint.erase(node->endpoint());
|
||||
} else if (node->get_state() != node::state::leaving && node->get_state() != node::state::left) {
|
||||
} else if (!node->is_leaving() && !node->left()) {
|
||||
if (node->host_id()) {
|
||||
_nodes_by_host_id.erase(node->host_id());
|
||||
}
|
||||
|
||||
@@ -47,9 +47,12 @@ public:
|
||||
|
||||
enum class state {
|
||||
none = 0,
|
||||
joining, // while bootstrapping, replacing
|
||||
bootstrapping, // (joining)
|
||||
replacing, // (joining)
|
||||
normal,
|
||||
leaving, // while decommissioned, removed, replaced
|
||||
being_decommissioned, // (leaving)
|
||||
being_removed, // (leaving)
|
||||
being_replaced, // (leaving)
|
||||
left // after decommissioned, removed, replaced
|
||||
};
|
||||
|
||||
@@ -102,6 +105,35 @@ public:
|
||||
|
||||
state get_state() const noexcept { return _state; }
|
||||
|
||||
bool is_joining() const noexcept {
|
||||
switch (_state) {
|
||||
case state::bootstrapping:
|
||||
case state::replacing:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool is_normal() const noexcept {
|
||||
return _state == state::normal;
|
||||
}
|
||||
|
||||
bool is_leaving() const noexcept {
|
||||
switch (_state) {
|
||||
case state::being_decommissioned:
|
||||
case state::being_removed:
|
||||
case state::being_replaced:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool left() const noexcept {
|
||||
return _state == state::left;
|
||||
}
|
||||
|
||||
shard_id get_shard_count() const noexcept { return _shard_count; }
|
||||
|
||||
static std::string to_string(state);
|
||||
|
||||
Reference in New Issue
Block a user