pacemaker  2.1.0-7c3f660
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions | Variables
election.c File Reference
#include <crm_internal.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <crm/msg_xml.h>
#include <crm/common/xml.h>
#include <crm/common/mainloop.h>
#include <crm/cluster/internal.h>
#include <crm/cluster/election_internal.h>
#include <crm/crm.h>
Include dependency graph for election.c:

Go to the source code of this file.

Macros

#define STORM_INTERVAL   2 /* in seconds */
 
#define LOSS_DAMPEN   2 /* in seconds */
 

Functions

enum election_result election_state (election_t *e)
 Get current state of an election. More...
 
election_telection_init (const char *name, const char *uname, guint period_ms, GSourceFunc cb)
 Create a new election object. More...
 
void election_remove (election_t *e, const char *uname)
 Disregard any previous vote by specified peer. More...
 
void election_reset (election_t *e)
 Stop election timer and disregard all votes. More...
 
void election_fini (election_t *e)
 Free an election object. More...
 
void election_timeout_stop (election_t *e)
 Stop an election's timer, if running. More...
 
void election_timeout_set_period (election_t *e, guint period)
 Change an election's timeout (restarting 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...
 
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. More...
 
void election_clear_dampening (election_t *e)
 Reset any election dampening currently in effect. More...
 

Variables

struct election_s __attribute__
 

Macro Definition Documentation

#define LOSS_DAMPEN   2 /* in seconds */

Definition at line 398 of file election.c.

#define STORM_INTERVAL   2 /* in seconds */

Definition at line 23 of file election.c.

Function Documentation

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.

Parameters
[in]eElection object
Returns
TRUE if local node has won, FALSE otherwise
Note
If all known peers have sent no-vote messages, but the election owner does not call this function, the election will not be won (and the callback will not be called) until the election times out.
This should be called when election_count_vote() returns 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.

Parameters
[in]eElection 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.

Parameters
[in]eElection object
[in]voteElection message XML from peer
[in]can_winWhether to consider the local node eligible for winning
Returns
Election state after new vote is considered
Note
If the peer message is a vote, and we prefer the peer to win, this will send a no-vote reply to the peer.
The situations "we lost to this vote" from "this is a late no-vote after we've already lost" both return election_lost. If a caller needs to distinguish them, it should save the current state before calling this function, and then compare the result.

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).

Parameters
[in]eElection 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.

Parameters
[in]nameLabel for election (for logging)
[in]unameLocal node's name
[in]period_msHow long to wait for all peers to vote
[in]cbFunction to call if local node wins election
Returns
Newly allocated election object on success, NULL on error
Note
The caller is responsible for freeing the returned value using election_fini().

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.

Parameters
[in]eElection object
[in]unameName 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.

Parameters
[in]eElection object

Definition at line 143 of file election.c.

enum election_result election_state ( election_t e)

Get current state of an election.

Parameters
[in]eElection object
Returns
Current state of

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)

Parameters
[in]eElection object
[in]periodNew timeout

Definition at line 205 of file election.c.

void election_timeout_stop ( election_t e)

Stop an election's timer, if running.

Parameters
[in]eElection 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.

Parameters
[in]eElection object
Note
Any nodes agreeing to the candidacy will send a "no-vote" reply, and if all active peers do so, or if the election times out, the local node wins the election. (If we lose to any peer vote, we will stop the timer, so a timeout means we did not lose – either some peer did not vote, or we did not call election_check() in time.)

Definition at line 289 of file election.c.

Variable Documentation

struct pcmk__cpg_msg_s __attribute__