1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <title>Holding Elections</title>
7 <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
9 <link rel="start" href="index.html" title="Getting Started with Replicated Berkeley DB Applications" />
10 <link rel="up" href="introduction.html" title="Chapter 1. Introduction" />
11 <link rel="prev" href="apioverview.html" title="The Replication APIs" />
12 <link rel="next" href="permmessages.html" title="Permanent Message Handling" />
15 <div xmlns="" class="navheader">
17 <p>Library Version 11.2.5.3</p>
19 <table width="100%" summary="Navigation header">
21 <th colspan="3" align="center">Holding Elections</th>
24 <td width="20%" align="left"><a accesskey="p" href="apioverview.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 1. Introduction</th>
26 <td width="20%" align="right"> <a accesskey="n" href="permmessages.html">Next</a></td>
31 <div class="sect1" lang="en" xml:lang="en">
32 <div class="titlepage">
35 <h2 class="title" style="clear: both"><a id="elections"></a>Holding Elections</h2>
43 <a href="elections.html#influencingelections">Influencing Elections</a>
48 <a href="elections.html#winningelections">Winning Elections</a>
53 <a href="elections.html#switchingmasters">Switching Masters</a>
59 Finding a master environment is one of the fundamental activities that
60 every replication replica must perform. Upon startup, the
61 underlying DB replication code will attempt to
62 locate a master. If a master cannot be found, then the
63 environment should initiate an election.
65 <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
66 <h3 class="title">Note</h3>
68 In some rare situations, it is desireable for the
69 application to manually select its master. For these
70 cases, elections can be turned off.
73 Manually selecting a master is an activity that should
74 be performed infrequently, if ever. You turn elections
78 <code class="methodname">DbEnv::rep_set_config()</code>
81 <code class="methodname">DbEnv::repmgr_start()</code>
89 How elections are held depends upon the API that you use to
90 implement replication. For example, if you are using the
91 Replication Manager elections are held transparently without any
92 input from your application's code. In this case,
93 DB will determine which environment is the master and which
96 <div class="sect2" lang="en" xml:lang="en">
97 <div class="titlepage">
100 <h3 class="title"><a id="influencingelections"></a>Influencing Elections</h3>
105 If you want to control the election process, you can declare
106 a specific environment to be the master. Note that for the Replication Manager,
107 it is only possible to do this at application startup.
108 Should the master become unavailable during run-time for any
109 reason, an election is held. The environment that receives
110 the most number of votes, wins the election and becomes the
111 master. A machine receives a vote because it has the most
112 up-to-date log records.
115 Because ties are possible when elections are held,
116 it is possible to influence which environment will win
117 the election. How you do this depends on which API you
118 are using. In particular, if you are writing a custom replication
119 layer, then there are a great many ways to manually influence
123 One such mechanism is priorities. When votes are cast
124 during an election, the winner is determined first by
125 the environment with the most up-to-date log records.
126 But if this is a tie, the the environment's priority is
127 considered. So given two environments with log records
128 that are equally recent, votes are cast for the
129 environment with the higher priority.
132 Therefore, if you have a machine that you prefer to
133 become a master in the event of an election, assign it
134 a high priority. Assuming that the election is held at
135 a time when the preferred machine has up-to-date log
136 records, that machine will win the election.
139 <div class="sect2" lang="en" xml:lang="en">
140 <div class="titlepage">
143 <h3 class="title"><a id="winningelections"></a>Winning Elections</h3>
150 <div class="orderedlist">
154 There cannot currently be a
160 The environment must have the most
161 recent log records. Part of
162 holding the election is
163 determining which environments have
164 the most recent log records.
166 automatically; your code does
167 not need to involve itself in
173 The environment must receive the most
174 number of votes from the
175 replication environments that are
176 participating in the election.
182 If you are using the Replication Manager, then in the event of a
183 tie vote the environment with the highest priority wins
184 the election. If two or more environments receive the same
185 number of votes and have the same priority, then
186 the underlying replication code picks one of the
188 be the winner. Which winner will be picked by the
189 replication code is unpredictable from the
190 perspective of your application code.
193 <div class="sect2" lang="en" xml:lang="en">
194 <div class="titlepage">
197 <h3 class="title"><a id="switchingmasters"></a>Switching Masters</h3>
204 <div class="orderedlist">
208 Start up the environment that you want
209 to be master as normal. At this
210 time it is a replica. Make
211 sure this environment has a higher
212 priority than all the other
218 Allow the new environment to run for a
219 time as a replica. This allows
220 it to obtain the most recent
221 copies of the log files.
226 Shut down the current master.
227 This should force an election.
228 Because the new environment has the
229 highest priority, it will win
230 the election, provided it has
231 had enough time to obtain all
237 Optionally restart the old
238 master environment. Because there is
239 currently a master environment, an
240 election will not be held and
241 the old master will now run as
242 a replica environment.
249 <div class="navfooter">
251 <table width="100%" summary="Navigation footer">
253 <td width="40%" align="left"><a accesskey="p" href="apioverview.html">Prev</a> </td>
254 <td width="20%" align="center">
255 <a accesskey="u" href="introduction.html">Up</a>
257 <td width="40%" align="right"> <a accesskey="n" href="permmessages.html">Next</a></td>
260 <td width="40%" align="left" valign="top">The Replication APIs </td>
261 <td width="20%" align="center">
262 <a accesskey="h" href="index.html">Home</a>
264 <td width="40%" align="right" valign="top"> Permanent Message Handling</td>