23 if ((election == NULL) || (config == NULL))
28 election->own_id = config->
own_id;
30 election->winner_id = 0U;
31 election->have_winner =
false;
37 uint32_t candidate_count)
40 uint32_t winner_index;
50 if ((candidates == NULL) && (candidate_count > 0U))
55 if (!
find_own_index(candidates, candidate_count, election->own_id, &own_index))
63 winner_index = find_winner_index(candidates, candidate_count);
64 election->winner_id = candidates[winner_index].
id;
65 election->have_winner =
true;
67 if (winner_index == own_index)
71 else if (candidates[winner_index].degraded)
89 return election->own_last_state;
94 if ((election == NULL) || (out_id == NULL))
98 if (!election->have_winner)
102 *out_id = election->winner_id;
113 for (i = 0U; i < candidate_count; i++)
115 if (candidates[i].
id == own_id)
129 uint32_t winner = 0U;
132 for (i = 1U; i < candidate_count; i++)
134 if ((candidates[i].startup_timestamp_ms < candidates[winner].startup_timestamp_ms) ||
135 ((candidates[i].startup_timestamp_ms == candidates[winner].startup_timestamp_ms) &&
136 (candidates[i].
id < candidates[winner].
id)))
rte_dual_state_t
State of one instance in a dual (two-redundant-instance) relationship, as decided by rte_dual_negotia...
@ RTE_DUAL_STATE_HOTSTANDBY
@ RTE_DUAL_STATE_COLDSTANDBY
rte_dual_state_t rte_election_get_own_state(const rte_election_t *election)
Returns this instance's own current rte_dual_state_t, as of the last rte_election_execute() call.
rte_status_t rte_election_init(rte_election_t *election, const rte_election_config_t *config)
Initializes a rte_election_t. own_last_state starts at RTE_DUAL_STATE_IDLE (never yet evaluated).
rte_status_t rte_election_get_winner_id(const rte_election_t *election, uint32_t *out_id)
Returns the last-elected winner's id.
rte_status_t rte_election_execute(rte_election_t *election, const rte_election_candidate_t *candidates, uint32_t candidate_count)
Evaluates one round of election against the caller-supplied candidate snapshot (REQ-ELECTION-002 thro...
rte_status_t
Common result/status codes.
@ RTE_STATUS_INVALID_PARAM
@ RTE_STATUS_NOT_INITIALIZED
#define RTE_REDUNDANCY_CONFIG_MAX_REPLICAS
static bool find_own_index(const rte_election_candidate_t *candidates, uint32_t candidate_count, uint32_t own_id, uint32_t *out_index)
N-way election primitive (ADR-039): generalizes rte_dual_negotiator's pairwise older-startup-timestam...
One candidate's info for one rte_election_execute() call. The caller builds this array fresh each cal...
Configuration for rte_election_init().
One rte_election_t instance's state. Caller-owned storage; every field is private - reach it only thr...