| 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>Building the communications infrastructure</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_base_meth.html" title="Base API Methods" /> |
| 12 | <link rel="next" href="rep_newsite.html" title="Connecting to a new site" /> |
| 13 | </head> |
| 14 | <body> |
| 15 | <div xmlns="" class="navheader"> |
| 16 | <div class="libver"> |
| 17 | <p>Library Version 11.2.5.3</p> |
| 18 | </div> |
| 19 | <table width="100%" summary="Navigation header"> |
| 20 | <tr> |
| 21 | <th colspan="3" align="center">Building the communications infrastructure</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="rep_base_meth.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 12. |
| 26 | Berkeley DB Replication |
| 27 | </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="rep_newsite.html">Next</a></td> |
| 29 | </tr> |
| 30 | </table> |
| 31 | <hr /> |
| 32 | </div> |
| 33 | <div class="sect1" lang="en" xml:lang="en"> |
| 34 | <div class="titlepage"> |
| 35 | <div> |
| 36 | <div> |
| 37 | <h2 class="title" style="clear: both"><a id="rep_comm"></a>Building the communications infrastructure</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <p>Replication Manager provides a built-in communications |
| 42 | infrastructure.</p> |
| 43 | <p>Base API applications must provide |
| 44 | their own communications infrastructure, which is typically written with one |
| 45 | or more threads of control looping on one or more communication |
| 46 | channels, receiving and sending messages. These threads accept messages |
| 47 | from remote environments for the local database environment, and accept |
| 48 | messages from the local environment for remote environments. Messages |
| 49 | from remote environments are passed to the local database environment |
| 50 | using the <a href="../api_reference/C/repmessage.html" class="olink">DB_ENV->rep_process_message()</a> method. Messages from the local environment are |
| 51 | passed to the application for transmission using the callback function |
| 52 | specified to the <a href="../api_reference/C/reptransport.html" class="olink">DB_ENV->rep_set_transport()</a> method.</p> |
| 53 | <p>Processes establish communication channels by calling the |
| 54 | <a href="../api_reference/C/reptransport.html" class="olink">DB_ENV->rep_set_transport()</a> method, regardless of whether they are running in |
| 55 | client or server environments. This method specifies the <span class="bold"><strong>send</strong></span> |
| 56 | function, a callback function used by Berkeley DB for sending messages to |
| 57 | other database environments in the replication group. The <span class="bold"><strong>send</strong></span> |
| 58 | function takes an environment ID and two opaque data objects. It is the |
| 59 | responsibility of the <span class="bold"><strong>send</strong></span> function to transmit the information |
| 60 | in the two data objects to the database environment corresponding to the |
| 61 | ID, with the receiving application then calling the <a href="../api_reference/C/repmessage.html" class="olink">DB_ENV->rep_process_message()</a> method |
| 62 | to process the message.</p> |
| 63 | <p>The details of the transport mechanism are left entirely to the |
| 64 | application; the only requirement is that the data buffer and size of |
| 65 | each of the control and rec <a href="../api_reference/C/dbt.html" class="olink">DBT</a>s passed to the <span class="bold"><strong>send</strong></span> |
| 66 | function on the sending site be faithfully copied and delivered to the |
| 67 | receiving site by means of a call to <a href="../api_reference/C/repmessage.html" class="olink">DB_ENV->rep_process_message()</a> with |
| 68 | corresponding arguments. Messages that are broadcast (whether by |
| 69 | broadcast media or when directed by setting the |
| 70 | <a href="../api_reference/C/reptransport.html" class="olink">DB_ENV->rep_set_transport()</a> method's envid parameter DB_EID_BROADCAST), should |
| 71 | not be processed by the message sender. In all cases, the application's |
| 72 | transport media or software must ensure that <a href="../api_reference/C/repmessage.html" class="olink">DB_ENV->rep_process_message()</a> is |
| 73 | never called with a message intended for a different database |
| 74 | environment or a broadcast message sent from the same environment on |
| 75 | which <a href="../api_reference/C/repmessage.html" class="olink">DB_ENV->rep_process_message()</a> will be called. |
| 76 | The <a href="../api_reference/C/repmessage.html" class="olink">DB_ENV->rep_process_message()</a> method is |
| 77 | free-threaded; it is safe to deliver any number of messages |
| 78 | simultaneously, and from any arbitrary thread or process in the Berkeley DB |
| 79 | environment.</p> |
| 80 | <p>There are a number of informational returns from the |
| 81 | <a href="../api_reference/C/repmessage.html" class="olink">DB_ENV->rep_process_message()</a> method:</p> |
| 82 | <div class="variablelist"> |
| 83 | <dl> |
| 84 | <dt> |
| 85 | <span class="term"> |
| 86 | <a href="../api_reference/C/repmessage.html#repmsg_DB_REP_DUPMASTER" class="olink">DB_REP_DUPMASTER</a> |
| 87 | </span> |
| 88 | </dt> |
| 89 | <dd> |
| 90 | <p> |
| 91 | When <a href="../api_reference/C/repmessage.html" class="olink">DB_ENV->rep_process_message()</a> returns <a href="../api_reference/C/repmessage.html#repmsg_DB_REP_DUPMASTER" class="olink">DB_REP_DUPMASTER</a>, it means that |
| 92 | another database environment in the replication group also |
| 93 | believes itself to be the master. The application should |
| 94 | complete all active transactions, close all open database |
| 95 | handles, reconfigure itself as a client using the |
| 96 | <a href="../api_reference/C/repstart.html" class="olink">DB_ENV->rep_start()</a> method, and then call for an election by calling |
| 97 | the <a href="../api_reference/C/repelect.html" class="olink">DB_ENV->rep_elect()</a> method. |
| 98 | </p> |
| 99 | </dd> |
| 100 | <dt> |
| 101 | <span class="term"> |
| 102 | <a href="../api_reference/C/repmessage.html#repmsg_DB_REP_HOLDELECTION" class="olink">DB_REP_HOLDELECTION</a> |
| 103 | </span> |
| 104 | </dt> |
| 105 | <dd> |
| 106 | <p> |
| 107 | When <a href="../api_reference/C/repmessage.html" class="olink">DB_ENV->rep_process_message()</a> returns <a href="../api_reference/C/repmessage.html#repmsg_DB_REP_HOLDELECTION" class="olink">DB_REP_HOLDELECTION</a>, it means that |
| 108 | another database environment in the replication group has |
| 109 | called for an election. The application should call the |
| 110 | <a href="../api_reference/C/repelect.html" class="olink">DB_ENV->rep_elect()</a> method. |
| 111 | </p> |
| 112 | </dd> |
| 113 | <dt> |
| 114 | <span class="term"> |
| 115 | <a href="../api_reference/C/repmessage.html#repmsg_DB_REP_IGNORE" class="olink">DB_REP_IGNORE</a> |
| 116 | </span> |
| 117 | </dt> |
| 118 | <dd> |
| 119 | <p> |
| 120 | When <a href="../api_reference/C/repmessage.html" class="olink">DB_ENV->rep_process_message()</a> returns <a href="../api_reference/C/repmessage.html#repmsg_DB_REP_IGNORE" class="olink">DB_REP_IGNORE</a>, it means that this |
| 121 | message cannot be processed. This is normally an indication |
| 122 | that this message is irrelevant to the current replication |
| 123 | state, such as a message from an old generation that arrived |
| 124 | late. |
| 125 | </p> |
| 126 | </dd> |
| 127 | <dt> |
| 128 | <span class="term"> |
| 129 | <a href="../api_reference/C/repmessage.html#repmsg_DB_REP_ISPERM" class="olink">DB_REP_ISPERM</a> |
| 130 | </span> |
| 131 | </dt> |
| 132 | <dd> |
| 133 | <p> |
| 134 | When <a href="../api_reference/C/repmessage.html" class="olink">DB_ENV->rep_process_message()</a> returns <a href="../api_reference/C/repmessage.html#repmsg_DB_REP_ISPERM" class="olink">DB_REP_ISPERM</a>, it means a permanent |
| 135 | record, perhaps a message previously returned as |
| 136 | <a href="../api_reference/C/repmessage.html#repmsg_DB_REP_NOTPERM" class="olink">DB_REP_NOTPERM</a>, was successfully written to disk. This |
| 137 | record may have filled a gap in the log record that allowed |
| 138 | additional records to be written. The <span class="bold"><strong>ret_lsnp</strong></span> contains the maximum LSN of |
| 139 | the permanent records written. |
| 140 | </p> |
| 141 | </dd> |
| 142 | <dt> |
| 143 | <span class="term"> |
| 144 | <a href="../api_reference/C/repmessage.html#repmsg_DB_REP_NEWSITE" class="olink">DB_REP_NEWSITE</a> |
| 145 | </span> |
| 146 | </dt> |
| 147 | <dd> |
| 148 | <p> |
| 149 | When <a href="../api_reference/C/repmessage.html" class="olink">DB_ENV->rep_process_message()</a> returns <a href="../api_reference/C/repmessage.html#repmsg_DB_REP_NEWSITE" class="olink">DB_REP_NEWSITE</a>, it means that a |
| 150 | message from a previously unknown member of the replication |
| 151 | group has been received. The application should reconfigure |
| 152 | itself as necessary so it is able to send messages to this |
| 153 | site. |
| 154 | </p> |
| 155 | </dd> |
| 156 | <dt> |
| 157 | <span class="term"> |
| 158 | <a href="../api_reference/C/repmessage.html#repmsg_DB_REP_NOTPERM" class="olink">DB_REP_NOTPERM</a> |
| 159 | </span> |
| 160 | </dt> |
| 161 | <dd> |
| 162 | <p> |
| 163 | When <a href="../api_reference/C/repmessage.html" class="olink">DB_ENV->rep_process_message()</a> returns <a href="../api_reference/C/repmessage.html#repmsg_DB_REP_NOTPERM" class="olink">DB_REP_NOTPERM</a>, it means a message |
| 164 | marked as <a href="../api_reference/C/reptransport.html#transport_DB_REP_PERMANENT" class="olink">DB_REP_PERMANENT</a> was processed successfully but was not |
| 165 | written to disk. This is normally an indication that one or |
| 166 | more messages, which should have arrived before this message, |
| 167 | have not yet arrived. This operation will be written to disk |
| 168 | when the missing messages arrive. The <span class="bold"><strong>ret_lsnp</strong></span> argument will contain the |
| 169 | LSN of this record. The application should take whatever |
| 170 | action is deemed necessary to retain its recoverability |
| 171 | characteristics. |
| 172 | </p> |
| 173 | </dd> |
| 174 | </dl> |
| 175 | </div> |
| 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_base_meth.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_newsite.html">Next</a></td> |
| 186 | </tr> |
| 187 | <tr> |
| 188 | <td width="40%" align="left" valign="top">Base API Methods </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"> Connecting to a new site</td> |
| 193 | </tr> |
| 194 | </table> |
| 195 | </div> |
| 196 | </body> |
| 197 | </html> |