<h2class="title"style="clear: both"><aid="rep_comm"></a>Building the communications infrastructure</h2>
</div>
</div>
</div>
<p>Replication Manager provides a built-in communications
infrastructure.</p>
<p>Base API applications must provide
their own communications infrastructure, which 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 <ahref="../api_reference/C/repmessage.html"class="olink">DB_ENV->rep_process_message()</a> method. Messages from the local environment are
passed to the application for transmission using the callback function
specified to the <ahref="../api_reference/C/reptransport.html"class="olink">DB_ENV->rep_set_transport()</a> method.</p>
<p>Processes establish communication channels by calling the
<ahref="../api_reference/C/reptransport.html"class="olink">DB_ENV->rep_set_transport()</a> method, regardless of whether they are running in
client or server environments. This method specifies the <spanclass="bold"><strong>send</strong></span>
function, a callback function used by Berkeley DB for sending messages to
other database environments in the replication group. The <spanclass="bold"><strong>send</strong></span>
function takes an environment ID and two opaque data objects. It is the
responsibility of the <spanclass="bold"><strong>send</strong></span> function to transmit the information
in the two data objects to the database environment corresponding to the
ID, with the receiving application then calling the <ahref="../api_reference/C/repmessage.html"class="olink">DB_ENV->rep_process_message()</a> method
to process the message.</p>
<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 <ahref="../api_reference/C/dbt.html"class="olink">DBT</a>s passed to the <spanclass="bold"><strong>send</strong></span>
function on the sending site be faithfully copied and delivered to the
receiving site by means of a call to <ahref="../api_reference/C/repmessage.html"class="olink">DB_ENV->rep_process_message()</a> with
corresponding arguments. Messages that are broadcast (whether by
broadcast media or when directed by setting the
<ahref="../api_reference/C/reptransport.html"class="olink">DB_ENV->rep_set_transport()</a> method's envid parameter DB_EID_BROADCAST), should
not be processed by the message sender. In all cases, the application's
transport media or software must ensure that <ahref="../api_reference/C/repmessage.html"class="olink">DB_ENV->rep_process_message()</a> is
never called with a message intended for a different database
environment or a broadcast message sent from the same environment on
which <ahref="../api_reference/C/repmessage.html"class="olink">DB_ENV->rep_process_message()</a> will be called.
The <ahref="../api_reference/C/repmessage.html"class="olink">DB_ENV->rep_process_message()</a> method 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>
<p>There are a number of informational returns from the
When <ahref="../api_reference/C/repmessage.html"class="olink">DB_ENV->rep_process_message()</a> returns <ahref="../api_reference/C/repmessage.html#repmsg_DB_REP_DUPMASTER"class="olink">DB_REP_DUPMASTER</a>, it means that
another database environment in the replication group also
believes itself to be the master. The application should
complete all active transactions, close all open database
handles, reconfigure itself as a client using the
<ahref="../api_reference/C/repstart.html"class="olink">DB_ENV->rep_start()</a> method, and then call for an election by calling
the <ahref="../api_reference/C/repelect.html"class="olink">DB_ENV->rep_elect()</a> method.
When <ahref="../api_reference/C/repmessage.html"class="olink">DB_ENV->rep_process_message()</a> returns <ahref="../api_reference/C/repmessage.html#repmsg_DB_REP_HOLDELECTION"class="olink">DB_REP_HOLDELECTION</a>, it means that
another database environment in the replication group has
called for an election. The application should call the
When <ahref="../api_reference/C/repmessage.html"class="olink">DB_ENV->rep_process_message()</a> returns <ahref="../api_reference/C/repmessage.html#repmsg_DB_REP_IGNORE"class="olink">DB_REP_IGNORE</a>, it means that this
message cannot be processed. This is normally an indication
that this message is irrelevant to the current replication
state, such as a message from an old generation that arrived
When <ahref="../api_reference/C/repmessage.html"class="olink">DB_ENV->rep_process_message()</a> returns <ahref="../api_reference/C/repmessage.html#repmsg_DB_REP_ISPERM"class="olink">DB_REP_ISPERM</a>, it means a permanent
record, perhaps a message previously returned as
<ahref="../api_reference/C/repmessage.html#repmsg_DB_REP_NOTPERM"class="olink">DB_REP_NOTPERM</a>, was successfully written to disk. This
record may have filled a gap in the log record that allowed
additional records to be written. The <spanclass="bold"><strong>ret_lsnp</strong></span> contains the maximum LSN of
When <ahref="../api_reference/C/repmessage.html"class="olink">DB_ENV->rep_process_message()</a> returns <ahref="../api_reference/C/repmessage.html#repmsg_DB_REP_NEWSITE"class="olink">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
When <ahref="../api_reference/C/repmessage.html"class="olink">DB_ENV->rep_process_message()</a> returns <ahref="../api_reference/C/repmessage.html#repmsg_DB_REP_NOTPERM"class="olink">DB_REP_NOTPERM</a>, it means a message
marked as <ahref="../api_reference/C/reptransport.html#transport_DB_REP_PERMANENT"class="olink">DB_REP_PERMANENT</a> was processed successfully but was not
written to disk. This is normally an indication that one or
more messages, which should have arrived before this message,
have not yet arrived. This operation will be written to disk
when the missing messages arrive. The <spanclass="bold"><strong>ret_lsnp</strong></span> argument will contain the
LSN of this record. The application should take whatever
action is deemed necessary to retain its recoverability