1<!--$Id: ex.so,v 1.8 2006/10/05 01:06:08 bostic Exp $--> 2<!--Copyright (c) 1997,2008 Oracle. All rights reserved.--> 3<!--See the file LICENSE for redistribution information.--> 4<html> 5<head> 6<title>Berkeley DB Reference Guide: Ex_rep: a replication example</title> 7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit."> 8<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++"> 9</head> 10<body bgcolor=white> 11<table width="100%"><tr valign=top> 12<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Berkeley DB Replication</dl></b></td> 13<td align=right><a href="../rep/faq.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../rep/ex_comm.html"><img src="../../images/next.gif" alt="Next"></a> 14</td></tr></table> 15<p align=center><b>Ex_rep: a replication example</b></p> 16<p>Ex_rep, found in the <b>examples_c/ex_rep</b> subdirectory 17of the Berkeley DB distribution, is a simple but complete demonstration of a 18replicated application. The application is a mock stock ticker. The 19master accepts a stock symbol and an numerical value as input, and 20stores this information into a replicated database; either master or 21clients can display the contents of the database, given an empty input 22line.</p> 23<p>There are two versions of the application: ex_rep_mgr uses Replication 24Manager, while ex_rep_base uses the Base replication API. This is 25intended to demonstrate that, while the basic function of the 26application is the same in either case, the replication support 27infrastructure differs markedly.</p> 28<p>The communication infrastructure demonstrated with ex_rep_base has the 29same dependencies on system networking and threading support as does 30the Replication Manager (see the <a href="../../ref/rep/intro.html">Introduction</a>). The Makefile created by the standard UNIX 31configuration will build the ex_rep examples on most platforms. Enter 32"make ex_rep_mgr" and/or "make ex_rep_base" to attempt to build 33them.</p> 34<p>The synopsis for both programs is as follows:</p> 35<pre>ex_rep_xxx [<b>-MC</b>] [<b>-h home</b>] [<b>-m host:port</b>] [<b>-o host:port</b>] [<b>-n sites</b>] [<b>-p priority</b>]</pre> 36<p>where "ex_rep_xxx" is either "ex_rep_mgr" or "ex_rep_base".</p> 37<p>The options, to either version of the program, are as follows:</p> 38<br> 39<b>-M</b><ul compact><li>Configure this process as a master.</ul> 40<b>-C</b><ul compact><li>Configure this process as a client.</ul> 41<b>-h</b><ul compact><li>Specify a home directory for the database environment; by 42default, the current working directory is used.</ul> 43<b>-m</b><ul compact><li>Listen on port "port" of host "host" for incoming connections.</ul> 44<b>-o</b><ul compact><li>Attempt to connect to another member of the replication group which is 45listening on host "host" at port "port". Members of a replication group 46should be able to find all other members of a replication group so long 47as they are in contact with at least one other member of the replication 48group.</ul> 49<b>-n</b><ul compact><li>Specify the total number of sites in the replication group.</ul> 50<b>-p</b><ul compact><li>Set the election priority. See <a href="../../api_c/rep_elect.html">DB_ENV->rep_elect</a> for more 51information.</ul> 52<br> 53<p>A typical ex_rep session begins with a command such as the 54following, to start a master:</p> 55<blockquote><pre>ex_rep_mgr -M -p 100 -n 4 -h DIR1 -m localhost:6000</pre></blockquote> 56<p>and several clients:</p> 57<blockquote><pre>ex_rep_mgr -C -p 50 -n 4 -h DIR2 -m localhost:6001 -o localhost:6000 58ex_rep_mgr -C -p 10 -n 4 -h DIR3 -m localhost:6002 -o localhost:6000 59ex_rep_mgr -C -p 0 -n 4 -h DIR4 -m localhost:6003 -o localhost:6000</pre></blockquote> 60<p>In this example, the client with home directory DIR4 can never become 61a master (its priority is 0). Both of the other clients can become 62masters, but the one with home directory DIR2 is preferred. Priorities 63are assigned by the application and should reflect the desirability of 64having particular clients take over as master in the case that the 65master fails.</p> 66<table width="100%"><tr><td><br></td><td align=right><a href="../rep/faq.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../rep/ex_comm.html"><img src="../../images/next.gif" alt="Next"></a> 67</td></tr></table> 68<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 69</body> 70</html> 71