Debian Codegraph @

docs/programmer_reference/rep_replicate.html

raw symbols SCIP
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">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <title>Running Replication using the db_replicate Utility</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="Berkeley DB Programmer's Reference Guide" />
10 <link rel="up" href="rep.html" title="Chapter 12.  Berkeley DB Replication" />
11 <link rel="prev" href="rep_mgrmulti.html" title="Running Replication Manager in multiple processes" />
12 <link rel="next" href="rep_mgr_ack.html" title="Choosing a Replication Manager Ack Policy" />
13 </head>
14 <body>
15 <div xmlns="" class="navheader">
16 <div class="libver">
17 <p>Library Version 11.2.5.3</p>
18 </div>
19 <table width="100%" summary="Navigation header">
20 <tr>
21 <th colspan="3" align="center">Running Replication using the db_replicate Utility</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="rep_mgrmulti.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 12. 
26 Berkeley DB Replication
27 </th>
28 <td width="20%" align="right"> <a accesskey="n" href="rep_mgr_ack.html">Next</a></td>
29 </tr>
30 </table>
31 <hr />
32 </div>
33 <div class="sect1" lang="en" xml:lang="en">
34 <div class="titlepage">
35 <div>
36 <div>
37 <h2 class="title" style="clear: both"><a id="rep_replicate"></a>Running Replication using the db_replicate Utility</h2>
38 </div>
39 </div>
40 </div>
41 <div class="toc">
42 <dl>
43 <dt>
44 <span class="sect2">
45 <a href="rep_replicate.html#idp52430544">One Replication Process and Multiple Subordinate Processes</a>
46 </span>
47 </dt>
48 <dt>
49 <span class="sect2">
50 <a href="rep_replicate.html#idp52447760">Common Use Case</a>
51 </span>
52 </dt>
53 <dt>
54 <span class="sect2">
55 <a href="rep_replicate.html#idp52457840">Avoiding Rollback</a>
56 </span>
57 </dt>
58 <dt>
59 <span class="sect2">
60 <a href="rep_replicate.html#idp52462952">When to Consider an Integrated HA Application</a>
61 </span>
62 </dt>
63 </dl>
64 </div>
65 <p>Replication Manager supports shared access to a database
66 environment from multiple processes. Berkeley DB provides a
67 replication-aware utility, db_replicate, that enables you to upgrade an existing Transactional Data Store
68 application, as discussed in the <a class="xref" href="transapp.html#transapp_intro" title="Transactional Data Store introduction">Transactional Data Store introduction</a> section,
69 to an HA application with
70 minor modifications. While the <a href="../api_reference/C/db_replicate.html" class="olink">db_replicate</a> utility simplifies the use
71 of replication with a TDS application, you
72 must still understand replication and its impact on the application.
73 </p>
74 <div class="sect2" lang="en" xml:lang="en">
75 <div class="titlepage">
76 <div>
77 <div>
78 <h3 class="title"><a id="idp52430544"></a>One Replication Process and Multiple Subordinate Processes</h3>
79 </div>
80 </div>
81 </div>
82 <p>Based on the terminology introduced in the <a class="xref" href="rep_mgrmulti.html" title="Running Replication Manager in multiple processes">Running Replication Manager in multiple processes</a> section,
83 application processes are "subordinate processes" and the <a href="../api_reference/C/db_replicate.html" class="olink">db_replicate</a> utility
84 is the "primary replication process".</p>
85 <p>
86 You must consider the following items when
87 planning to use the <a href="../api_reference/C/db_replicate.html" class="olink">db_replicate</a> utility in combination with
88 a TDS application.
89 </p>
90 <div class="itemizedlist">
91 <ul type="disc">
92 <li>Memory regions
93 <p>
94 The <a href="../api_reference/C/db_replicate.html" class="olink">db_replicate</a> utility requires shared memory access among
95 separate processes, and therefore cannot be used with <a href="../api_reference/C/envopen.html#envopen_DB_PRIVATE" class="olink">DB_PRIVATE</a>.
96 </p></li>
97 <li>Multi-process implications
98 <p>
99 You must understand and accept all of the TDS implications
100 of multi-process use as specified in <a class="xref" href="transapp_app.html" title="Architecting Transactional Data Store applications">Architecting Transactional Data Store applications</a>. Special attention should be
101 paid to the coordination needed for unrelated processes to
102 start up correctly.
103 </p></li>
104 <li>Replication configuration
105 <p>
106 Several configuration settings are required for replication.
107 You must set the <a href="../api_reference/C/envopen.html#envopen_DB_INIT_REP" class="olink">DB_INIT_REP</a>
108 and <a href="../api_reference/C/dbopen.html#open_DB_THREAD" class="olink">DB_THREAD</a> flags for the <a href="../api_reference/C/envopen.html" class="olink">DB_ENV-&gt;open()</a> method.
109 Another required configuration item is the local address. You identify
110 this by creating a <a href="../api_reference/C/db_site.html" class="olink">DB_SITE</a> handle and then setting the
111 <code class="literal">DB_LOCAL_SITE</code> parameter using the
112 <a href="../api_reference/C/dbsite_set_config.html" class="olink">DB_SITE-&gt;set_config()</a> method. You also tell sites how to contact other
113 sites by creating <a href="../api_reference/C/db_site.html" class="olink">DB_SITE</a> handles for those sites.
114 Most replication configuration options start with reasonable
115 defaults, but applications have to customize
116 at least some of them. You can set all replication related configuration options
117 either programmatically or in the <a href="../api_reference/C/configuration_reference.html" class="olink">DB_CONFIG</a> file.
118 </p></li>
119 <li> Starting the application and replication
120 <p>
121 The <a href="../api_reference/C/db_replicate.html" class="olink">db_replicate</a> utility assumes that an
122 environment exists and that the application has run recovery,
123 if necessary, and created and configured the environment.
124 The startup flow of a typical TDS application may not be the
125 best flow for a replication application and you
126 must understand the issues involved.
127 For instance, if an application starts, runs recovery,
128 and performs update operations before starting the <a href="../api_reference/C/db_replicate.html" class="olink">db_replicate</a> utility,
129 then if that site becomes a client when replication starts,
130 those update operations will be rolled back.
131 </p></li>
132 <li> Handling events
133 <p>
134 Almost all of the replication-specific events are handled
135 by the <a href="../api_reference/C/db_replicate.html" class="olink">db_replicate</a> utility process, and therefore the application
136 process does not see them. If the application needs to know
137 the information from those replication-specific events, such as
138 role changes, the application must call the <a href="../api_reference/C/repstat.html" class="olink">rep_stat()</a> method method.
139 The one replication-specific event the application can now
140 receive is the <a href="../api_reference/C/envevent_notify.html#event_notify_DB_EVENT_REP_PERM_FAILED" class="olink">DB_EVENT_REP_PERM_FAILED</a> event.
141 See <a class="xref" href="rep_mgr_ack.html" title="Choosing a Replication Manager Ack Policy">Choosing a Replication Manager Ack Policy</a>
142 for additional information about this event.
143 </p></li>
144 <li> Handling errors
145 <p>
146 There are some error return values that relate only to replication.
147 Specifically, the <code class="literal">DB_REP_HANDLE_DEAD</code> error should now be handled
148 by the application. Also, if master leases are in use, then the
149 application also needs to consider the <code class="literal">DB_REP_LEASE_EXPIRED</code> error.
150 </p></li>
151 <li> Flexibility tradeoff
152 <p>
153 You are giving up flexibility
154 for the ease of use of the utility.
155 Application complexity or requirements may eventually
156 dictate integrating HA calls into the application
157 over using the <a href="../api_reference/C/db_replicate.html" class="olink">db_replicate</a> utility. </p></li>
158 <li> Read-only client application
159 <p>
160 The application requires additional changes to manage
161 the read-only status when the application takes on the role of
162 a client.
163 </p></li>
164 </ul>
165 </div>
166 </div>
167 <div class="sect2" lang="en" xml:lang="en">
168 <div class="titlepage">
169 <div>
170 <div>
171 <h3 class="title"><a id="idp52447760"></a>Common Use Case</h3>
172 </div>
173 </div>
174 </div>
175 <p>
176 This section lists the steps needed to get replication running for
177 a common use case of the <a href="../api_reference/C/db_replicate.html" class="olink">db_replicate</a> utility.
178 The use case presented is an existing TDS application that
179 already has its environment and databases created and is up and running.
180 At some point, HA is considered because failover protection
181 or balancing the read load may now be desired.
182 </p>
183 <div class="orderedlist">
184 <ol type="1">
185 <li>
186 <p>
187 To understand the issues involved in a replication/HA application, see
188 the <a href="../api_reference/C/db_replicate.html" class="olink">db_replicate</a> utility section in the <span class="emphasis"><em>API Reference Guide</em></span>, the <a href="../api_reference/C/rep.html" class="olink">Replication Chapter</a> in the <span class="emphasis"><em>
189 Programmer's Reference Guide</em></span>, and the source code of the ex_rep_mgr
190 example program.
191 </p>
192 </li>
193 <li>
194 <p>
195 Make a local hot backup of the current
196 application environment to a new location to use as a testing area.
197 </p>
198 </li>
199 <li>
200 <p>
201 Add the <a href="../api_reference/C/envopen.html#envopen_DB_INIT_REP" class="olink">DB_INIT_REP</a> and <a href="../api_reference/C/dbopen.html#open_DB_THREAD" class="olink">DB_THREAD</a> flags (if not already
202 being used) to the application or the <a href="../api_reference/C/configuration_reference.html" class="olink">DB_CONFIG</a> file.
203 </p>
204 </li>
205 <li>
206 <p>
207 Modify the <a href="../api_reference/C/configuration_reference.html" class="olink">DB_CONFIG</a> file to add the necessary replication
208 configuration values. At a minimum, the local
209 host and port information must be added using
210 the <a href="../api_reference/C/repmgr_site_parameter.html" class="olink">repmgr_site</a> method parameter.
211 As more sites are added to the group, remote host and port
212 information can optionally also be added by adding
213 more <a href="../api_reference/C/repmgr_site_parameter.html" class="olink">repmgr_site</a> method parameters to the <a href="../api_reference/C/configuration_reference.html" class="olink">DB_CONFIG</a> file file.
214 </p>
215 </li>
216 <li>
217 <p>
218 Rebuild the application and restart
219 it in the current testing directory.
220 </p>
221 </li>
222 <li>
223 <p>
224 Start the <a href="../api_reference/C/db_replicate.html" class="olink">db_replicate</a> utility on the master site with the -M option and
225 any other options needed such as -h for the home directory.
226 At this point you have a lone master site running in an
227 environment with no other replicated sites in the group.
228 </p>
229 </li>
230 <li>
231 <p>
232 Optionally, prepare to start a client site by performing a
233 manual hot backup of the running master environment to
234 initialize a client target directory. While replication
235 can make its own copy, the hot backup will expedite the
236 synchronization process. Also, if the application assumes
237 the existence of a database and the client site is started
238 without data, the application may have errors or incorrectly
239 attempt to create the database.
240 </p>
241 </li>
242 <li>
243 <p>
244 Copy the application to the client target.
245 </p>
246 </li>
247 <li>
248 <p>
249 Modify the client environment's <a href="../api_reference/C/configuration_reference.html" class="olink">DB_CONFIG</a> file to set the client's local host and port values and to add
250 remote site information for the master site and any
251 other replication configuration choices necessary.
252 </p>
253 </li>
254 <li>
255 <p>
256 Start the application on the client. The client application
257 should not update data at this point, as explained previously.
258 </p>
259 </li>
260 <li>
261 <p>
262 Start the <a href="../api_reference/C/db_replicate.html" class="olink">db_replicate</a> utility specifying the
263 client environment's home directory using the -h option. Omit the -M
264 option in this case, because the utility defaults to
265 starting in the client role.
266 </p>
267 </li>
268 </ol>
269 </div>
270 <p>
271 Once the initial replication group is established, do not use the -M option with
272 the <a href="../api_reference/C/db_replicate.html" class="olink">db_replicate</a> utility.
273 After the initial start, <a href="../api_reference/C/db_replicate.html" class="olink">db_replicate</a> utility assumes the use of
274 elections. If a site crashes, it should rejoin the group as
275 a client so that it can synchronize with the rest of the group.
276 </p>
277 </div>
278 <div class="sect2" lang="en" xml:lang="en">
279 <div class="titlepage">
280 <div>
281 <div>
282 <h3 class="title"><a id="idp52457840"></a>Avoiding Rollback</h3>
283 </div>
284 </div>
285 </div>
286 <p>
287 Depending on how an application is structured, transactional rollback
288 can occur. If this is possible, then you must make application
289 changes or be prepared for successful transactions to disappear.
290 Consider a common program flow where the application first creates
291 and opens the environment with recovery. Then, immediately after
292 that, the application opens up the databases it expects to use.
293 Often an application will use the <a href="../api_reference/C/dbopen.html#open_DB_CREATE" class="olink">DB_CREATE</a> flag so that if the
294 database does not exist it is created, otherwise the existing one is
295 used automatically. Then the application begins servicing transactions
296 to write and read data.
297 </p>
298 <p>
299 When replication is introduced, particularly via the <a href="../api_reference/C/db_replicate.html" class="olink">db_replicate</a> utility, the
300 possibility of rollback exists unless the application takes steps
301 to prevent it. In the situation described above, if all of the
302 above steps occur before the <a href="../api_reference/C/db_replicate.html" class="olink">db_replicate</a> utility process starts, and
303 the site is started as a client, then all the operations will be
304 rolled back when the site finds the master. The client site will
305 synchronize with the log and operations on the master site, so
306 any operations that occurred in the client application before it
307 knew it was a client will be discarded.
308 </p>
309 <p>
310 One way to reduce the possibility of rollback is to modify the
311 application so that it only performs update operations (including
312 creation of a database) if it is the master site. If the application
313 refrains from updating until it is the master, then it will not perform
314 operations when it is in the undefined state before replication
315 has been started.
316 The event indicating a site is master will be delivered to the
317 <a href="../api_reference/C/db_replicate.html" class="olink">db_replicate</a> utility process, so the application process must look
318 for that information via the <a href="../api_reference/C/repstat.html" class="olink">rep_stat()</a> method.
319 A site that is expecting to perform updates may need to poll
320 via the <a href="../api_reference/C/repstat.html" class="olink">rep_stat()</a> method to see the state change from an undefined
321 role to either the master or client role. Similarly, since a
322 client site cannot create a database, it may need to poll for
323 the database's existence while the client synchronizes with the master
324 until the database is created at the client site.
325 </p>
326 </div>
327 <div class="sect2" lang="en" xml:lang="en">
328 <div class="titlepage">
329 <div>
330 <div>
331 <h3 class="title"><a id="idp52462952"></a>When to Consider an Integrated HA Application</h3>
332 </div>
333 </div>
334 </div>
335 <p>
336 The <a href="../api_reference/C/db_replicate.html" class="olink">db_replicate</a> utility provides the means to achieve
337 a replicated application quickly. However,
338 the trade-off for this rapid implementation is that the full
339 flexibility of replication is not available. Some applications
340 may eventually need to consider integrating directly with
341 replication rather than using the <a href="../api_reference/C/db_replicate.html" class="olink">db_replicate</a> utility if greater flexibility is desired.
342 </p>
343 <p>
344 One likely reason for considering integration would be the
345 convenience of receiving all replication-related events in
346 the application process and gaining direct knowledge of such
347 things as role changes.
348 Using the event callback is cleaner and easier than
349 polling for state changes via the <a href="../api_reference/C/repstat.html" class="olink">rep_stat()</a> method.
350 </p>
351 <p>
352 A second likely reason for integrating replication directly
353 into the application is the multi-process aspect of the
354 utility program. The developer may find it easier to insert
355 the start of replication directly into the code once the
356 environment is created, recovered, or opened, and avoid
357 the scenario where the application is running in the
358 undefined state. Also it may simply be easier to start
359 the application once than to coordinate different processes
360 and their startup order in the system.
361 </p>
362 </div>
363 </div>
364 <div class="navfooter">
365 <hr />
366 <table width="100%" summary="Navigation footer">
367 <tr>
368 <td width="40%" align="left"><a accesskey="p" href="rep_mgrmulti.html">Prev</a> </td>
369 <td width="20%" align="center">
370 <a accesskey="u" href="rep.html">Up</a>
371 </td>
372 <td width="40%" align="right"> <a accesskey="n" href="rep_mgr_ack.html">Next</a></td>
373 </tr>
374 <tr>
375 <td width="40%" align="left" valign="top">Running Replication Manager in multiple processes </td>
376 <td width="20%" align="center">
377 <a accesskey="h" href="index.html">Home</a>
378 </td>
379 <td width="40%" align="right" valign="top"> Choosing a Replication Manager Ack Policy</td>
380 </tr>
381 </table>
382 </div>
383 </body>
384 </html>