From a4e8bea679970059974388e9fdebee72ef6610bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Botond=20D=C3=A9nes?= Date: Mon, 18 Mar 2024 03:07:35 -0400 Subject: [PATCH] tools/scylla-nodetool: status: handle missing host_id Newly joining nodes may not have a host id yet. Handle this and print a "?" for these nodes, instead of the host-id. Extend the existing test for joining node case (also rename it and add comment). Closes scylladb/scylladb#17853 --- test/nodetool/test_status.py | 23 +++++++++++++++-------- tools/scylla-nodetool.cc | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/test/nodetool/test_status.py b/test/nodetool/test_status.py index c204b5c1e0..ff7c555557 100644 --- a/test/nodetool/test_status.py +++ b/test/nodetool/test_status.py @@ -107,7 +107,10 @@ def validate_status_output(res, keyspace, nodes, ownership, resolve): assert owns == "?" else: assert owns == "{:.1f}%".format(float(ownership[ep]) * 100) - assert host_id == node.host_id + if node.host_id is not None: + assert host_id == node.host_id + else: + assert host_id == "?" assert rack == node.rack assert len(dc_eps) == 0 @@ -178,7 +181,7 @@ def _do_test_status(nodetool, keyspace, node_list, resolve=None): load_map = [{"key": ep, "value": node.load} for ep, node in nodes.items() if node.load is not None] - host_id_map = [{"key": ep, "value": node.host_id} for ep, node in nodes.items()] + host_id_map = [{"key": ep, "value": node.host_id} for ep, node in nodes.items() if node.host_id is not None] tokens_endpoint = [] for ep, node in nodes.items(): @@ -402,7 +405,11 @@ def test_status_keyspace_multi_dc(nodetool): _do_test_status(nodetool, "ks", nodes) -def test_status_keyspace_no_load(nodetool): +def test_status_keyspace_joining_node(nodetool): + """ Joining nodes do not have some attributes available yet: + * load + * host_id + """ nodes = [ Node( endpoint="127.0.0.1", @@ -411,18 +418,18 @@ def test_status_keyspace_no_load(nodetool): tokens=["-9175818098208185248", "-3983536194780899528"], datacenter="datacenter1", rack="rack1", - status=NodeStatus.Unknown, - state=NodeState.Joining, + status=NodeStatus.Up, + state=NodeState.Normal, ), Node( endpoint="127.0.0.2", - host_id="ed341f60-b12a-4fd4-9917-e80977ded0f9", + host_id=None, load=None, tokens=["-1810801828328238220", "2983536194780899528"], datacenter="datacenter1", rack="rack2", - status=NodeStatus.Down, - state=NodeState.Normal, + status=NodeStatus.Up, + state=NodeState.Joining, ), ] diff --git a/tools/scylla-nodetool.cc b/tools/scylla-nodetool.cc index 908899befb..c697aea32d 100644 --- a/tools/scylla-nodetool.cc +++ b/tools/scylla-nodetool.cc @@ -1851,7 +1851,7 @@ void status_operation(scylla_rest_client& client, const bpo::variables_map& vm) load, endpoint_tokens.at(ep), keyspace ? format("{:.1f}%", endpoint_ownership.at(ep) * 100) : "?", - endpoint_host_id.at(ep), + endpoint_host_id.contains(ep) ? endpoint_host_id.at(ep) : "?", endpoint_rack.at(ep)); } table.print();