feat(raft-library): reject even n_peers in raft_init; add test_raft_init_even_peers_returns_einval
This commit is contained in:
parent
fd9933c9d0
commit
becf6ee765
2 changed files with 48 additions and 6 deletions
|
|
@ -15,6 +15,11 @@ int raft_init(raft_state_t *s, const raft_config_t *cfg)
|
|||
/* Validate required callbacks and n_peers before touching *s */
|
||||
if (cfg->n_peers < 1)
|
||||
return -EINVAL;
|
||||
/* Even cluster sizes (>1) have no fault-tolerance advantage over the next
|
||||
* smaller odd size and can mislead operators into thinking split-brain is
|
||||
* impossible. Reject to prevent misconfiguration. */
|
||||
if (cfg->n_peers > 1 && cfg->n_peers % 2 == 0)
|
||||
return -EINVAL;
|
||||
if (!cfg->cbs)
|
||||
return -EINVAL;
|
||||
if (!cfg->cbs->on_send_vote_request)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue