Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions simplyblock_core/arbitration/arbiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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]

Expand Down
12 changes: 6 additions & 6 deletions simplyblock_core/rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/rpc/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

from pydantic import SecretStr

from simplyblock_core import constants
from simplyblock_core.rpc_client import (
RPCClient,
RPCConnectionError,
RPCErrorCode,
RPCException,
RPCRemoteError,
Expand Down Expand Up @@ -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()

32 changes: 30 additions & 2 deletions tests/unit/test_two_node_arbiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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")
Expand All @@ -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,
Expand Down Expand Up @@ -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")
Loading