MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / decide_join

Function decide_join

nodedb-cluster/src/raft_loop/handle_rpc.rs:52–64  ·  view source on GitHub ↗

Pure decision: given the observed group-0 leader, this node's id, and the leader's address (as known to the local topology), should we admit the join or redirect? - `group0_leader == 0` means "no elected leader yet". On a freshly bootstrapped single-seed cluster this is normal — the founding node is the only possible leader, so we accept. - `group0_leader == self_node_id` means we are the leader

(
    group0_leader: u64,
    self_node_id: u64,
    leader_addr: Option<String>,
)

Source from the content-addressed store, hash-verified

50/// redirect with an empty string so the client at least sees the
51/// `"not leader"` prefix and can decide to try the next seed.
52pub(super) fn decide_join(
53 group0_leader: u64,
54 self_node_id: u64,
55 leader_addr: Option<String>,
56) -> JoinDecision {
57 if group0_leader == 0 || group0_leader == self_node_id {
58 JoinDecision::Admit
59 } else {
60 JoinDecision::Redirect {
61 leader_addr: leader_addr.unwrap_or_default(),
62 }
63 }
64}
65
66impl<A: CommitApplier, P: PlanExecutor> RaftRpcHandler for RaftLoop<A, P> {
67 async fn handle_rpc(&self, rpc: RaftRpc) -> Result<RaftRpc> {

Callers 1

join_flowMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected