Berkeley DB Reference Guide:
Berkeley DB Replication

PrevRefNext

Ex_rep: a replication example

Ex_rep, found in the examples_c/ex_rep subdirectory of the Berkeley DB distribution, is a simple but complete demonstration of a replicated application. The application is a mock stock ticker. The master accepts a stock symbol and an numerical value as input, and stores this information into a replicated database; either master or clients can display the contents of the database, given an empty input line.

There are two versions of the application: ex_rep_mgr uses Replication Manager, while ex_rep_base uses the Base replication API. This is intended to demonstrate that, while the basic function of the application is the same in either case, the replication support infrastructure differs markedly.

The communication infrastructure demonstrated with ex_rep_base has the same dependencies on system networking and threading support as does the Replication Manager (see the Introduction). The Makefile created by the standard UNIX configuration will build the ex_rep examples on most platforms. Enter "make ex_rep_mgr" and/or "make ex_rep_base" to attempt to build them.

The synopsis for both programs is as follows:

ex_rep_xxx [-MC] [-h home] [-m host:port] [-o host:port] [-n sites] [-p priority]

where "ex_rep_xxx" is either "ex_rep_mgr" or "ex_rep_base".

The options, to either version of the program, are as follows:

-M
Configure this process as a master.
-C
Configure this process as a client.
-h
Specify a home directory for the database environment; by default, the current working directory is used.
-m
Listen on port "port" of host "host" for incoming connections.
-o
Attempt to connect to another member of the replication group which is listening on host "host" at port "port". Members of a replication group should be able to find all other members of a replication group so long as they are in contact with at least one other member of the replication group.
-n
Specify the total number of sites in the replication group.
-p
Set the election priority. See DB_ENV->rep_elect for more information.

A typical ex_rep session begins with a command such as the following, to start a master:

ex_rep_mgr -M -p 100 -n 4 -h DIR1 -m localhost:6000

and several clients:

ex_rep_mgr -C -p 50 -n 4 -h DIR2 -m localhost:6001 -o localhost:6000
ex_rep_mgr -C -p 10 -n 4 -h DIR3 -m localhost:6002 -o localhost:6000
ex_rep_mgr -C -p  0 -n 4 -h DIR4 -m localhost:6003 -o localhost:6000

In this example, the client with home directory DIR4 can never become a master (its priority is 0). Both of the other clients can become masters, but the one with home directory DIR2 is preferred. Priorities are assigned by the application and should reflect the desirability of having particular clients take over as master in the case that the master fails.


PrevRefNext

Copyright (c) 1996-2006 Oracle Corporation - All rights reserved.