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>Ex_rep: a replication example</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_faq.html" title="Replication FAQ" /> 12 <link rel="next" href="rep_ex_comm.html" title="Ex_rep_base: a TCP/IP based communication infrastructure" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Ex_rep: a replication example</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="rep_faq.html">Prev</a> </td> 22 <th width="60%" align="center">Chapter 12. 23 Berkeley DB Replication 24 </th> 25 <td width="20%" align="right"> <a accesskey="n" href="rep_ex_comm.html">Next</a></td> 26 </tr> 27 </table> 28 <hr /> 29 </div> 30 <div class="sect1" lang="en" xml:lang="en"> 31 <div class="titlepage"> 32 <div> 33 <div> 34 <h2 class="title" style="clear: both"><a id="rep_ex"></a>Ex_rep: a replication example</h2> 35 </div> 36 </div> 37 </div> 38 <p>Ex_rep, found in the <code class="filename">examples_c/ex_rep</code> subdirectory 39of the Berkeley DB distribution, is a simple but complete demonstration of a 40replicated application. The application is a mock stock ticker. The 41master accepts a stock symbol and a numerical value as input, and 42stores this information into a replicated database; either master or 43clients can display the contents of the database, given an empty input 44line.</p> 45 <p>There are two versions of the application: ex_rep_mgr uses Replication 46Manager, while ex_rep_base uses the replication Base API. This is 47intended to demonstrate that, while the basic function of the 48application is the same in either case, the replication support 49infrastructure differs markedly.</p> 50 <p>The communication infrastructure demonstrated with ex_rep_base has the 51same dependencies on system networking and threading support as does 52the Replication Manager (see the <a class="xref" href="rep.html#rep_intro" title="Replication introduction">Replication introduction</a>). The Makefile created by the standard UNIX 53configuration will build the ex_rep examples on most platforms. Enter 54"make ex_rep_mgr" and/or "make ex_rep_base" to build them.</p> 55 <p>The synopsis for both programs is as follows:</p> 56 <code class="literal">ex_rep_xxx <span class="bold"><strong>-h home</strong></span> <span class="bold"><strong>-l host:port</strong></span> [<span class="bold"><strong>-MC</strong></span>] [<span class="bold"><strong>-r host:port</strong></span>] [<span class="bold"><strong>-R host:port</strong></span>] [<span class="bold"><strong>-a all|quorum</strong></span>] [<span class="bold"><strong>-b</strong></span>] [<span class="bold"><strong>-n sites</strong></span>] [<span class="bold"><strong>-p priority</strong></span>] [<span class="bold"><strong>-v</strong></span>]</code> 57 <p> 58 where "ex_rep_xxx" is either "ex_rep_mgr" or "ex_rep_base". The only 59 difference is that specifying <span class="bold"><strong>-M</strong></span> or 60 <span class="bold"><strong>-C</strong></span> is optional for ex_rep_mgr, but 61 one of these options must be specified for ex_rep_base. 62</p> 63 <p>The options apply to either version of the program except where 64noted. They are as follows:</p> 65 <div class="variablelist"> 66 <dl> 67 <dt> 68 <span class="term"> 69 <span class="bold"> 70 <strong>-h</strong> 71 </span> 72 </span> 73 </dt> 74 <dd>Specify a home directory for the database environment.</dd> 75 <dt> 76 <span class="term"> 77 <span class="bold"> 78 <strong>-l</strong> 79 </span> 80 </span> 81 </dt> 82 <dd>Listen on local host "host" at port "port" for incoming connections.</dd> 83 <dt> 84 <span class="term"> 85 <span class="bold"> 86 <strong>-M</strong> 87 </span> 88 </span> 89 </dt> 90 <dd>Configure this process as a master.</dd> 91 <dt> 92 <span class="term"> 93 <span class="bold"> 94 <strong>-C</strong> 95 </span> 96 </span> 97 </dt> 98 <dd>Configure this process as a client.</dd> 99 <dt> 100 <span class="term"> 101 <span class="bold"> 102 <strong>-r</strong> 103 </span> 104 </span> 105 </dt> 106 <dd>Attempt to connect to a remote member of the replication group which is 107listening on host "host" at port "port". Members of a replication group 108should be able to find all other members of a replication group so long 109as they are in contact with at least one other member of the replication 110group. Any number of these may be specified. </dd> 111 <dt> 112 <span class="term"> 113 <span class="bold"> 114 <strong>-R</strong> 115 </span> 116 </span> 117 </dt> 118 <dd>Attempt to connect as a remote peer to a remote member of the replication group which is listening on host "host" at port "port". At most, one of these may be specified. See <a class="xref" href="rep_mastersync.html#rep_c2c_sync" title="Client-to-client synchronization">Client-to-client synchronization</a> for more information (ex_rep_mgr only.)</dd> 119 <dt> 120 <span class="term"> 121 <span class="bold"> 122 <strong>-a</strong> 123 </span> 124 </span> 125 </dt> 126 <dd>Specify repmgr acknowledgement policy of all or quorum. See <a href="../api_reference/C/repmgrset_ack_policy.html" class="olink">DB_ENV->repmgr_set_ack_policy()</a> for more information (ex_rep_mgr only.)</dd> 127 <dt> 128 <span class="term"> 129 <span class="bold"> 130 <strong>-b</strong> 131 </span> 132 </span> 133 </dt> 134 <dd>Indicates that bulk transfer should be used. See <a class="xref" href="rep_bulk.html" title="Bulk transfer">Bulk transfer</a> for more information. 135</dd> 136 <dt> 137 <span class="term"> 138 <span class="bold"> 139 <strong>-n</strong> 140 </span> 141 </span> 142 </dt> 143 <dd>Specify the total number of sites in the replication group.</dd> 144 <dt> 145 <span class="term"> 146 <span class="bold"> 147 <strong>-p</strong> 148 </span> 149 </span> 150 </dt> 151 <dd>Set the election priority. See <a class="xref" href="rep_elect.html" title="Elections">Elections</a> for more 152information.</dd> 153 <dt> 154 <span class="term"> 155 <span class="bold"> 156 <strong>-v</strong> 157 </span> 158 </span> 159 </dt> 160 <dd>Indicates that additional informational and debugging output should be enabled.</dd> 161 </dl> 162 </div> 163 <p>A typical ex_rep session begins with a command such as the 164following, to start a master:</p> 165 <pre class="programlisting">ex_rep_mgr -M -p 100 -n 4 -h DIR1 -l localhost:6000</pre> 166 <p>and several clients:</p> 167 <pre class="programlisting">ex_rep_mgr -C -p 50 -n 4 -h DIR2 -l localhost:6001 -r localhost:6000 168ex_rep_mgr -C -p 10 -n 4 -h DIR3 -l localhost:6002 -r localhost:6000 169ex_rep_mgr -C -p 0 -n 4 -h DIR4 -l localhost:6003 -r localhost:6000</pre> 170 <p>In this example, the client with home directory DIR4 can never become 171a master (its priority is 0). Both of the other clients can become 172masters, but the one with home directory DIR2 is preferred. Priorities 173are assigned by the application and should reflect the desirability of 174having particular clients take over as master in the case that the 175master fails.</p> 176 </div> 177 <div class="navfooter"> 178 <hr /> 179 <table width="100%" summary="Navigation footer"> 180 <tr> 181 <td width="40%" align="left"><a accesskey="p" href="rep_faq.html">Prev</a> </td> 182 <td width="20%" align="center"> 183 <a accesskey="u" href="rep.html">Up</a> 184 </td> 185 <td width="40%" align="right"> <a accesskey="n" href="rep_ex_comm.html">Next</a></td> 186 </tr> 187 <tr> 188 <td width="40%" align="left" valign="top">Replication FAQ </td> 189 <td width="20%" align="center"> 190 <a accesskey="h" href="index.html">Home</a> 191 </td> 192 <td width="40%" align="right" valign="top"> Ex_rep_base: a TCP/IP based communication infrastructure</td> 193 </tr> 194 </table> 195 </div> 196 </body> 197</html> 198