From c08ba4f027450bee610cd75bc29dae2029143a72 Mon Sep 17 00:00:00 2001 From: Max Schettler Date: Mon, 23 Nov 2026 15:27:12 +0100 Subject: [PATCH] fix(two-node): a failed capability probe is not an answer supports_two_node_arbitration() turned every error into False, and the arbiter stored that result for the life of its process. A node probed while its SPDK was still starting was therefore never arbitrated: no jc_set_dual_node, no lease, until the arbiter restarted. Seen on a fresh two-node cluster, where the arbiter probed the second node the moment its record appeared, still in_creation. supports_two_node_arbitration() now only checks the method list and lets every error propagate. probe() stores only the node's answer and treats any RPC error as intermittent: the node stays undecided and is probed again on the next renewal. --- simplyblock_core/arbitration/arbiter.py | 15 +++++++++--- simplyblock_core/rpc_client.py | 12 +++++----- tests/unit/rpc/test_client.py | 22 +++++++++++++++++ tests/unit/test_two_node_arbiter.py | 32 +++++++++++++++++++++++-- 4 files changed, 70 insertions(+), 11 deletions(-) diff --git a/simplyblock_core/arbitration/arbiter.py b/simplyblock_core/arbitration/arbiter.py index 9adecd5f64..71f611281a 100644 --- a/simplyblock_core/arbitration/arbiter.py +++ b/simplyblock_core/arbitration/arbiter.py @@ -39,7 +39,7 @@ ClusterArbitration, ) from simplyblock_core.models.storage_node import StorageNode -from simplyblock_core.rpc_client import RPCHTTPError, RPCRemoteError +from simplyblock_core.rpc_client import RPCException, RPCHTTPError, RPCRemoteError logger = logging.getLogger(__name__) @@ -327,10 +327,19 @@ def snapshot(self, rec: ClusterArbitration, nodes: list, cluster=None) -> dec.Sn # ---- node configuration and leases --------------------------------------- def probe(self, node: StorageNode) -> bool: + """Whether the node exposes the arbitration RPCs. Only the node's + answer is kept: an error is intermittent (a node still starting, a + transient outage), so the node stays undecided and is probed again on + the next renewal.""" nid = node.get_id() if nid not in self.capable: - self.capable[nid] = node.rpc_client(timeout=3, retry=0).supports_two_node_arbitration() - if not self.capable[nid]: + try: + capable = node.rpc_client(timeout=3, retry=0).supports_two_node_arbitration() + except RPCException as e: + logger.debug("Capability probe of %s failed, probing again: %s", nid, e) + return False + self.capable[nid] = capable + if not capable: logger.warning("Node %s lacks the two-node arbitration RPCs; not arbitrated", nid) return self.capable[nid] diff --git a/simplyblock_core/rpc_client.py b/simplyblock_core/rpc_client.py index 467434496f..cb6b04d336 100644 --- a/simplyblock_core/rpc_client.py +++ b/simplyblock_core/rpc_client.py @@ -2015,12 +2015,12 @@ def jc_wait_events(self, instance, after_seq, timeout_ms=20000, max_events=256): def supports_two_node_arbitration(self): """True when the node exposes every RPC the arbiter drives - (constants.TWO_NODE_ARBITRATION_RPCS). Any error means no.""" - try: - methods = set(self.rpc_get_methods() or []) - except Exception: # noqa: BLE001 - probe only - return False - return all(m in methods for m in constants.TWO_NODE_ARBITRATION_RPCS) + (constants.TWO_NODE_ARBITRATION_RPCS). + + Raises: + RPCException: the node's method list could not be read. + """ + return set(constants.TWO_NODE_ARBITRATION_RPCS) <= set(self.rpc_get_methods()) def bdev_lvol_snapshot_group(self, lvs_name, snapshots): """One crash-consistent snapshot per consistency-group member. diff --git a/tests/unit/rpc/test_client.py b/tests/unit/rpc/test_client.py index e54cc501ed..5ff9c7fda9 100644 --- a/tests/unit/rpc/test_client.py +++ b/tests/unit/rpc/test_client.py @@ -7,8 +7,10 @@ from pydantic import SecretStr +from simplyblock_core import constants from simplyblock_core.rpc_client import ( RPCClient, + RPCConnectionError, RPCErrorCode, RPCException, RPCRemoteError, @@ -485,6 +487,26 @@ def test_merge_stat_calls_request_with_ids(self, mock_req): mock_req.assert_called_once_with("bdev_lvol_s3_merge_stat", s3_id=1, old_s3_id=2) +class TestSupportsTwoNodeArbitration(unittest.TestCase): + + @patch.object(RPCClient, "_request") + def test_true_when_every_rpc_is_exposed(self, mock_req): + mock_req.return_value = [*constants.TWO_NODE_ARBITRATION_RPCS, "bdev_get_bdevs"] + self.assertTrue(_make_client().supports_two_node_arbitration()) + + @patch.object(RPCClient, "_request") + def test_false_when_one_rpc_is_missing(self, mock_req): + mock_req.return_value = list(constants.TWO_NODE_ARBITRATION_RPCS[1:]) + self.assertFalse(_make_client().supports_two_node_arbitration()) + + @patch.object(RPCClient, "_request") + def test_error_propagates(self, mock_req): + # Not an answer: the caller tells "unreachable" from "not capable". + mock_req.side_effect = RPCConnectionError("Could not reach remote") + with self.assertRaises(RPCConnectionError): + _make_client().supports_two_node_arbitration() + + if __name__ == "__main__": unittest.main() diff --git a/tests/unit/test_two_node_arbiter.py b/tests/unit/test_two_node_arbiter.py index c6e417c4a4..d2434c5da6 100644 --- a/tests/unit/test_two_node_arbiter.py +++ b/tests/unit/test_two_node_arbiter.py @@ -9,7 +9,7 @@ from simplyblock_core.arbitration import arbiter as arb from simplyblock_core.models.arbitration import ArbitrationEvent, ClusterArbitration from simplyblock_core.models.storage_node import StorageNode -from simplyblock_core.rpc_client import RPCHTTPError, RPCRemoteError +from simplyblock_core.rpc_client import RPCConnectionError, RPCHTTPError, RPCRemoteError A, B, CL = "node-a", "node-b", "cl-1" @@ -42,7 +42,7 @@ def call(*args, **kwargs): if err: raise err if name == "supports_two_node_arbitration": - return True + return self.node.arbitration_rpcs if name == "jc_ha_status": if self.node.ha is None: raise RuntimeError("no status in this test") @@ -68,6 +68,8 @@ def __init__(self, nid, jm_vuid): #: event-driven view stays), else {jm_vuid: (state, remote_jm_health)} self.ha = None self.instance, self.seq, self.arbitration = "i-" + nid, 0, True + #: the node's answer to the capability probe + self.arbitration_rpcs = True def ha_status(self): return {"instance": self.instance, "seq": self.seq, "arbitration": self.arbitration, @@ -542,3 +544,29 @@ def test_ha_status_without_a_preferred_field_is_reconciled(env): assert "preferred" not in status a.tick_cluster(CL, [nodes[A], nodes[B]]) assert a.signals[A].lvs_state == {3: "solo"} + + +def test_probe_error_leaves_the_node_undecided_until_it_answers(env): + # A node probed while its SPDK still starts (cluster111, 2026-11-23): the + # error is not an answer, the node is arbitrated once it answers. + a, db, nodes, clock, _ = env + nodes[B].errors["supports_two_node_arbitration"] = RPCConnectionError("Could not reach remote") + a.renew_all() + a.tick_cluster(CL, [nodes[A], nodes[B]]) + assert B not in a.capable + assert not calls(nodes[B], "jc_lease_renew") and not calls(nodes[B], "jc_set_dual_node") + del nodes[B].errors["supports_two_node_arbitration"] + a.renew_all() + a.tick_cluster(CL, [nodes[A], nodes[B]]) + assert a.capable[B] is True + assert calls(nodes[B], "jc_lease_renew") and calls(nodes[B], "jc_set_dual_node") + + +def test_probe_answer_is_kept(env): + a, db, nodes, clock, _ = env + nodes[B].arbitration_rpcs = False + a.renew_all() + a.renew_all() + assert a.capable[B] is False + assert len(calls(nodes[B], "supports_two_node_arbitration")) == 1 + assert not calls(nodes[B], "jc_lease_renew")