| 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>Synchronizing with a master</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_elect.html" title="Elections" /> |
| 12 | <link rel="next" href="rep_init.html" title="Initializing 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">Synchronizing with a master</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="rep_elect.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_init.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_mastersync"></a>Synchronizing with a master</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <div class="toc"> |
| 42 | <dl> |
| 43 | <dt> |
| 44 | <span class="sect2"> |
| 45 | <a href="rep_mastersync.html#rep_delay_sync">Delaying client synchronization</a> |
| 46 | </span> |
| 47 | </dt> |
| 48 | <dt> |
| 49 | <span class="sect2"> |
| 50 | <a href="rep_mastersync.html#rep_c2c_sync">Client-to-client synchronization</a> |
| 51 | </span> |
| 52 | </dt> |
| 53 | <dt> |
| 54 | <span class="sect2"> |
| 55 | <a href="rep_mastersync.html#idp52488504">Blocked client operations</a> |
| 56 | </span> |
| 57 | </dt> |
| 58 | <dt> |
| 59 | <span class="sect2"> |
| 60 | <a href="rep_mastersync.html#idp52510624">Clients too far out-of-date to synchronize</a> |
| 61 | </span> |
| 62 | </dt> |
| 63 | </dl> |
| 64 | </div> |
| 65 | <p>When a client detects a new replication group master, the client must |
| 66 | synchronize with the new master before the client can process new |
| 67 | database changes. Synchronizing is a heavyweight operation which can |
| 68 | place a burden on both the client and the master. There are several |
| 69 | controls an application can use to reduce the synchronization burden.</p> |
| 70 | <div class="sect2" lang="en" xml:lang="en"> |
| 71 | <div class="titlepage"> |
| 72 | <div> |
| 73 | <div> |
| 74 | <h3 class="title"><a id="rep_delay_sync"></a>Delaying client synchronization</h3> |
| 75 | </div> |
| 76 | </div> |
| 77 | </div> |
| 78 | <p>When a replication group has a new master, either as specified by the |
| 79 | application or as a result of winning an election, all clients in the |
| 80 | replication group must synchronize with the new master. This can |
| 81 | strain the resources of the new master since a large number of clients |
| 82 | may be attempting to communicate with and transfer records from the |
| 83 | master. Client applications wanting to delay client synchronization |
| 84 | should call the <a href="../api_reference/C/repconfig.html" class="olink">DB_ENV->rep_set_config()</a> method with the |
| 85 | <a href="../api_reference/C/repconfig.html#config_DB_REP_CONF_DELAYCLIENT" class="olink">DB_REP_CONF_DELAYCLIENT</a> flag. The application will be |
| 86 | notified of the establishment of the new master as usual, but the |
| 87 | client will not proceed to synchronize with the new master.</p> |
| 88 | <p>Applications learn of a new master via the |
| 89 | <a href="../api_reference/C/envevent_notify.html#event_notify_DB_EVENT_REP_NEWMASTER" class="olink">DB_EVENT_REP_NEWMASTER</a> event.</p> |
| 90 | <p>Client applications choosing to delay synchronization in this manner are |
| 91 | responsible for synchronizing the client environment at some future time |
| 92 | using the <a href="../api_reference/C/repsync.html" class="olink">DB_ENV->rep_sync()</a> method.</p> |
| 93 | </div> |
| 94 | <div class="sect2" lang="en" xml:lang="en"> |
| 95 | <div class="titlepage"> |
| 96 | <div> |
| 97 | <div> |
| 98 | <h3 class="title"><a id="rep_c2c_sync"></a>Client-to-client synchronization</h3> |
| 99 | </div> |
| 100 | </div> |
| 101 | </div> |
| 102 | <p>Instead of synchronizing with the new master, it is sometimes possible |
| 103 | for a client to synchronize with another client. Berkeley DB initiates |
| 104 | synchronization at the client by sending a request message via the |
| 105 | transport call-back function of the communication infrastructure. The |
| 106 | message is destined for the master site, but is also marked with a |
| 107 | <a href="../api_reference/C/reptransport.html#transport_DB_REP_ANYWHERE" class="olink">DB_REP_ANYWHERE</a> flag. The application may choose to send such |
| 108 | a request to another client, or to ignore the flag, sending it to its |
| 109 | indicated destination.</p> |
| 110 | <p>Furthermore, when the other client receives such a request it may be |
| 111 | unable to satisfy it. In this case it will reply to the requesting |
| 112 | client, telling it that it is unable to provide the requested |
| 113 | information. The requesting client will then re-issue the request. |
| 114 | Additionally, if the original request never reaches the other client, |
| 115 | the requesting client will again re-issue the request. In either of |
| 116 | these cases the message will be marked with the <a href="../api_reference/C/reptransport.html#transport_DB_REP_REREQUEST" class="olink">DB_REP_REREQUEST</a> |
| 117 | flag. The application may continue trying to find another client to |
| 118 | service the request, or it may give up and simply send it to the master |
| 119 | (that is, the environment ID explicitly specified to the transport |
| 120 | function).</p> |
| 121 | <p> |
| 122 | Replication Manager allows an application to designate one or more |
| 123 | remote sites (called its "peers") to receive client-to-client requests. |
| 124 | You do this by setting the <code class="literal">DB_REPMGR_PEER</code> parameter |
| 125 | using the <a href="../api_reference/C/dbsite_set_config.html" class="olink">DB_SITE->set_config()</a> method. Replication Manager always tries |
| 126 | to send requests marked with the <a href="../api_reference/C/reptransport.html#transport_DB_REP_ANYWHERE" class="olink">DB_REP_ANYWHERE</a> flag to a peer, if |
| 127 | available. However, it always sends a <a href="../api_reference/C/reptransport.html#transport_DB_REP_REREQUEST" class="olink">DB_REP_REREQUEST</a> to the master |
| 128 | site. |
| 129 | </p> |
| 130 | <p>Base API applications have complete freedom |
| 131 | in choosing where to send these <a href="../api_reference/C/reptransport.html#transport_DB_REP_ANYWHERE" class="olink">DB_REP_ANYWHERE</a> requests, and |
| 132 | in deciding how to handle <a href="../api_reference/C/reptransport.html#transport_DB_REP_REREQUEST" class="olink">DB_REP_REREQUEST</a>.</p> |
| 133 | <p>The delayed synchronization and client-to-client synchronization |
| 134 | features allow applications to do load balancing within replication |
| 135 | groups. For example, consider a replication group with 5 sites, A, B, |
| 136 | C, D and E. Site E just crashed, and site A was elected master. Sites |
| 137 | C and D have been configured for delayed synchronization. When site B |
| 138 | is notified that site A is a new master, it immediately synchronizes. |
| 139 | When B finishes synchronizing with the master, the application calls the |
| 140 | <a href="../api_reference/C/repsync.html" class="olink">DB_ENV->rep_sync()</a> method on sites C and D to cause them to synchronize as well. |
| 141 | Sites C and D (and E, when it has finished rebooting) can send their |
| 142 | requests to site B, and B then bears the brunt of the work and |
| 143 | network traffic for synchronization, making master site A available to |
| 144 | handle the normal application load and any write requests paused by |
| 145 | the election.</p> |
| 146 | </div> |
| 147 | <div class="sect2" lang="en" xml:lang="en"> |
| 148 | <div class="titlepage"> |
| 149 | <div> |
| 150 | <div> |
| 151 | <h3 class="title"><a id="idp52488504"></a>Blocked client operations</h3> |
| 152 | </div> |
| 153 | </div> |
| 154 | </div> |
| 155 | <p>Clients in the process of synchronizing with the master block access to |
| 156 | Berkeley DB operations during some parts of that process. |
| 157 | By default, most Berkeley DB methods will block until |
| 158 | client synchronization is complete, and then the method call proceeds.</p> |
| 159 | <p>Client applications which cannot wait and would prefer an immediate |
| 160 | error return instead of blocking, should call the |
| 161 | <a href="../api_reference/C/repconfig.html" class="olink">DB_ENV->rep_set_config()</a> method with the <a href="../api_reference/C/repconfig.html#config_DB_REP_CONF_NOWAIT" class="olink">DB_REP_CONF_NOWAIT</a> flag. This |
| 162 | configuration causes <a href="../api_reference/C/db.html" class="olink">DB</a> method calls to immediately return a |
| 163 | <a href="../api_reference/C/dbput.html#dbput_DB_REP_LOCKOUT" class="olink">DB_REP_LOCKOUT</a> error instead of blocking, if the client is |
| 164 | currently synchronizing with the master.</p> |
| 165 | </div> |
| 166 | <div class="sect2" lang="en" xml:lang="en"> |
| 167 | <div class="titlepage"> |
| 168 | <div> |
| 169 | <div> |
| 170 | <h3 class="title"><a id="idp52510624"></a>Clients too far out-of-date to synchronize</h3> |
| 171 | </div> |
| 172 | </div> |
| 173 | </div> |
| 174 | <p>Clients attempting to synchronize with the master may discover that |
| 175 | synchronization is not possible because the client no longer has any |
| 176 | overlapping information with the master site. By default, the master and |
| 177 | client automatically detect this state and perform an internal initialization |
| 178 | of the client. Because internal initialization requires transfer of |
| 179 | entire databases to the client, it can take a relatively long period of |
| 180 | time and may require database handles to be reopened in the client |
| 181 | applications.</p> |
| 182 | <p>Client applications which cannot wait or would prefer |
| 183 | to do a hot backup instead of performing internal initialization, should |
| 184 | call the <a href="../api_reference/C/repconfig.html" class="olink">DB_ENV->rep_set_config()</a> method to turn off the <a href="../api_reference/C/repconfig.html#config_DB_REP_CONF_AUTOINIT" class="olink">DB_REP_CONF_AUTOINIT</a> flag. |
| 185 | Turning off this configuration flag causes Berkeley DB to return |
| 186 | <a href="../api_reference/C/repmessage.html#repmsg_DB_REP_JOIN_FAILURE" class="olink">DB_REP_JOIN_FAILURE</a> to the application instead of performing |
| 187 | internal initialization.</p> |
| 188 | </div> |
| 189 | </div> |
| 190 | <div class="navfooter"> |
| 191 | <hr /> |
| 192 | <table width="100%" summary="Navigation footer"> |
| 193 | <tr> |
| 194 | <td width="40%" align="left"><a accesskey="p" href="rep_elect.html">Prev</a> </td> |
| 195 | <td width="20%" align="center"> |
| 196 | <a accesskey="u" href="rep.html">Up</a> |
| 197 | </td> |
| 198 | <td width="40%" align="right"> <a accesskey="n" href="rep_init.html">Next</a></td> |
| 199 | </tr> |
| 200 | <tr> |
| 201 | <td width="40%" align="left" valign="top">Elections </td> |
| 202 | <td width="20%" align="center"> |
| 203 | <a accesskey="h" href="index.html">Home</a> |
| 204 | </td> |
| 205 | <td width="40%" align="right" valign="top"> Initializing a new site</td> |
| 206 | </tr> |
| 207 | </table> |
| 208 | </div> |
| 209 | </body> |
| 210 | </html> |