1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
<!--Id: comm.so,v 1.3 2001/10/25 20:05:34 bostic Exp -->
<!--Copyright 1997-2001 by Sleepycat Software, Inc.-->
<!--All rights reserved.-->
<html>
<head>
<title>Berkeley DB Reference Guide: Building the communications infrastructure</title>
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++">
</head>
<body bgcolor=white>
<table width="100%"><tr valign=top>
<td><h3><dl><dt>Berkeley DB Reference Guide:<dd>Berkeley DB Replication</dl></h3></td>
<td align=right><a href="../../ref/rep/app.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/rep/newsite.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p>
<h1 align=center>Building the communications infrastructure</h1>
<p>The replication portion of an application is typically written with one
or more threads of control looping on one or more communication
channels, receiving and sending messages. These threads accept messages
from remote environments for the local database environment, and accept
messages from the local environment for remote environments. Messages
from remote environments are passed to the local database environment
using the <a href="../../api_c/rep_message.html">DB_ENV->rep_process_message</a> function. Messages from the local environment
are passed to the application for transmission using the callback
interface specified to the <a href="../../api_c/rep_transport.html">DB_ENV->set_rep_transport</a> function.
<p>Both clients and servers establish communication channels by calling
the <a href="../../api_c/rep_transport.html">DB_ENV->set_rep_transport</a> function. This method specifies the <b>send</b>
interface, a callback interface used by Berkeley DB for sending messages to
other database environments in the replication group. The <b>send</b>
interface takes an environment ID and two opaque data objects. It is
the responsibility of the <b>send</b> interface to transmit the
information in the two data objects to the database environment
corresponding to the ID, with the receiving application then calling
the <a href="../../api_c/rep_message.html">DB_ENV->rep_process_message</a> function to process the message.
<p>The details of the transport mechanism are left entirely to the
application; the only requirement is that the data buffer and size of
each of the control and rec <a href="../../api_c/dbt.html">DBT</a>s passed to the <b>send</b>
function on the sending site be faithfully copied and delivered to the
receiving site by means of a call to <a href="../../api_c/rep_message.html">DB_ENV->rep_process_message</a> with
corresponding arguments. The <a href="../../api_c/rep_message.html">DB_ENV->rep_process_message</a> function is free-threaded; it
is safe to deliver any number of messages simultaneously, and from any
arbitrary thread or process in the Berkeley DB environment.
<p>There are a number of informational returns from the
<a href="../../api_c/rep_message.html">DB_ENV->rep_process_message</a> function:
<p><dl compact>
<p><dt><a href="../../api_c/rep_message.html#DB_REP_DUPMASTER">DB_REP_DUPMASTER</a><dd>When <a href="../../api_c/rep_message.html">DB_ENV->rep_process_message</a> returns <a href="../../api_c/rep_message.html#DB_REP_DUPMASTER">DB_REP_DUPMASTER</a>, it means that
another database environment in the replication group also believes
itself to be the master. The application should reconfigure itself as
a client using the <a href="../../api_c/rep_start.html">DB_ENV->rep_start</a> function, and then call for an election by
calling the <a href="../../api_c/rep_elect.html">DB_ENV->rep_elect</a> function.
<p><dt><a href="../../api_c/rep_message.html#DB_REP_HOLDELECTION">DB_REP_HOLDELECTION</a><dd>When <a href="../../api_c/rep_message.html">DB_ENV->rep_process_message</a> returns <a href="../../api_c/rep_message.html#DB_REP_HOLDELECTION">DB_REP_HOLDELECTION</a>, it means
that another database environment in the replication group has called
for an election. The application should call the <a href="../../api_c/rep_elect.html">DB_ENV->rep_elect</a> function.
<p><dt><a href="../../api_c/rep_message.html#DB_REP_NEWMASTER">DB_REP_NEWMASTER</a><dd>When <a href="../../api_c/rep_message.html">DB_ENV->rep_process_message</a> returns <a href="../../api_c/rep_message.html#DB_REP_NEWMASTER">DB_REP_NEWMASTER</a>, it means that
a new master has been elected. The call will also return the local
environment's ID for that master. If the ID of the master has changed,
the application may need to reconfigure itself (for example, to redirect
update queries to the new master rather then the old one). If the new
master is the local environment, then the application must call the
<a href="../../api_c/rep_start.html">DB_ENV->rep_start</a> function, and reconfigure the supporting Berkeley DB library as a
replication master.
<p><dt><a href="../../api_c/rep_message.html#DB_REP_NEWSITE">DB_REP_NEWSITE</a><dd>When <a href="../../api_c/rep_message.html">DB_ENV->rep_process_message</a> returns <a href="../../api_c/rep_message.html#DB_REP_NEWSITE">DB_REP_NEWSITE</a>, it means that
a message from a previously unknown member of the replication group has
been received. The application should reconfigure itself as necessary
so it is able to send messages to this site.
<p><dt><a href="../../api_c/rep_message.html#DB_REP_OUTDATED">DB_REP_OUTDATED</a><dd>When <a href="../../api_c/rep_message.html">DB_ENV->rep_process_message</a> returns <a href="../../api_c/rep_message.html#DB_REP_OUTDATED">DB_REP_OUTDATED</a>, it means that
the environment has been partitioned from the master for too long a
time, and the master no longer has the necessary log files to update
the local client. The application should shut down, and the client
should be reinitialized (see <a href="../../ref/rep/init.html">Initializing a new site</a> for more information).
</dl>
<table width="100%"><tr><td><br></td><td align=right><a href="../../ref/rep/app.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/rep/newsite.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>
</body>
</html>
|