pacemaker
2.1.0-7c3f660
Scalable High-Availability cluster resource manager
|
Functions for conducting elections. More...
Go to the source code of this file.
Typedefs | |
typedef struct election_s | election_t |
Enumerations | |
enum | election_result { election_start = 0, election_in_progress, election_lost, election_won, election_error } |
Functions | |
void | election_fini (election_t *e) |
Free an election object. More... | |
void | election_reset (election_t *e) |
Stop election timer and disregard all votes. More... | |
election_t * | election_init (const char *name, const char *uname, guint period_ms, GSourceFunc cb) |
Create a new election object. More... | |
void | election_timeout_set_period (election_t *e, guint period_ms) |
Change an election's timeout (restarting timer if running) More... | |
void | election_timeout_stop (election_t *e) |
Stop an election's timer, if running. More... | |
void | election_vote (election_t *e) |
Start a new election by offering local node's candidacy. More... | |
bool | election_check (election_t *e) |
Check whether local node has won an election. More... | |
void | election_remove (election_t *e, const char *uname) |
Disregard any previous vote by specified peer. More... | |
enum election_result | election_state (election_t *e) |
Get current state of an election. More... | |
enum election_result | election_count_vote (election_t *e, xmlNode *vote, bool can_win) |
Process an election message (vote or no-vote) from a peer. More... | |
void | election_clear_dampening (election_t *e) |
Reset any election dampening currently in effect. More... | |
Functions for conducting elections.
An election is useful for a daemon that runs on all nodes but needs any one instance to perform a special role.
Elections are closely tied to the cluster peer cache. Peers in the cache that are active members are eligible to vote. Elections are named for logging purposes, but only one election may exist at any time, so typically an election would be created at daemon start-up and freed at shutdown.
Pacemaker's election procedure has been heavily adapted from the Invitation Algorithm variant of the Garcia-Molina Bully Algorithm:
https://en.wikipedia.org/wiki/Bully_algorithm
Elections are conducted via cluster messages. There are two types of messages: a "vote" is a declaration of the voting node's candidacy, and is always broadcast; a "no-vote" is a concession by the responding node, and is always a reply to the preferred node's vote. (These correspond to "invite" and "accept" in the traditional algorithm.)
A vote together with any no-vote replies to it is considered an election round. Rounds are numbered with a simple counter unique to each node (this would be the group number in the traditional algorithm). Concurrent election rounds are possible.
An election round is started when any node broadcasts a vote. When a node receives another node's vote, it compares itself against the sending node according to certain metrics, and either starts a new round (if it prefers itself) or replies to the other node with a no-vote (if it prefers that node).
If a node receives no-votes from all other active nodes, it declares itself the winner. The library API does not notify other nodes of this; callers must implement that if desired.
Definition in file election_internal.h.
typedef struct election_s election_t |
Definition at line 56 of file election_internal.h.
enum election_result |
Possible election states
Definition at line 59 of file election_internal.h.
bool election_check | ( | election_t * | e | ) |
Check whether local node has won an election.
If all known peers have sent no-vote messages, stop the election timer, set the election state to won, and call any registered win callback.
[in] | e | Election object |
election_in_progress
. Definition at line 342 of file election.c.
void election_clear_dampening | ( | election_t * | e | ) |
Reset any election dampening currently in effect.
[in] | e | Election object to clear |
Definition at line 722 of file election.c.
enum election_result election_count_vote | ( | election_t * | e, |
xmlNode * | message, | ||
bool | can_win | ||
) |
Process an election message (vote or no-vote) from a peer.
[in] | e | Election object |
[in] | vote | Election message XML from peer |
[in] | can_win | Whether to consider the local node eligible for winning |
Definition at line 532 of file election.c.
void election_fini | ( | election_t * | e | ) |
Free an election object.
Free all memory associated with an election object, stopping its election timer (if running).
[in] | e | Election object |
Definition at line 165 of file election.c.
election_t* election_init | ( | const char * | name, |
const char * | uname, | ||
guint | period_ms, | ||
GSourceFunc | cb | ||
) |
Create a new election object.
Every node that wishes to participate in an election must create an election object. Typically, this should be done once, at start-up. A caller should only create a single election object.
[in] | name | Label for election (for logging) |
[in] | uname | Local node's name |
[in] | period_ms | How long to wait for all peers to vote |
[in] | cb | Function to call if local node wins election |
Definition at line 89 of file election.c.
void election_remove | ( | election_t * | e, |
const char * | uname | ||
) |
Disregard any previous vote by specified peer.
This discards any recorded vote from a specified peer. Election users should call this whenever a voting peer becomes inactive.
[in] | e | Election object |
[in] | uname | Name of peer to disregard |
Definition at line 129 of file election.c.
void election_reset | ( | election_t * | e | ) |
Stop election timer and disregard all votes.
[in] | e | Election object |
Definition at line 143 of file election.c.
enum election_result election_state | ( | election_t * | e | ) |
Get current state of an election.
[in] | e | Election object |
Definition at line 67 of file election.c.
void election_timeout_set_period | ( | election_t * | e, |
guint | period | ||
) |
Change an election's timeout (restarting timer if running)
[in] | e | Election object |
[in] | period | New timeout |
Definition at line 205 of file election.c.
void election_timeout_stop | ( | election_t * | e | ) |
Stop an election's timer, if running.
[in] | e | Election object |
Definition at line 191 of file election.c.
void election_vote | ( | election_t * | e | ) |
Start a new election by offering local node's candidacy.
Broadcast a "vote" election message containing the local node's ID, (incremented) election counter, and uptime, and start the election timer.
[in] | e | Election object |
Definition at line 289 of file election.c.