| 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>Network partitions</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_twosite.html" title="Special considerations for two-site replication groups" /> |
| 12 | <link rel="next" href="rep_faq.html" title="Replication FAQ" /> |
| 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">Network partitions</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="rep_twosite.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_faq.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_partition"></a>Network partitions</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <p>The Berkeley DB replication implementation can be affected by network |
| 42 | partitioning problems.</p> |
| 43 | <p>For example, consider a replication group with N members. The network |
| 44 | partitions with the master on one side and more than N/2 of the sites |
| 45 | on the other side. The sites on the side with the master will continue |
| 46 | forward, and the master will continue to accept write queries for the |
| 47 | databases. Unfortunately, the sites on the other side of the partition, |
| 48 | realizing they no longer have a master, will hold an election. The |
| 49 | election will succeed as there are more than N/2 of the total sites |
| 50 | participating, and there will then be two masters for the replication |
| 51 | group. Since both masters are potentially accepting write queries, the |
| 52 | databases could diverge in incompatible ways.</p> |
| 53 | <p>If multiple masters are ever found to exist in a replication group, a |
| 54 | master detecting the problem will return <a href="../api_reference/C/repmessage.html#repmsg_DB_REP_DUPMASTER" class="olink">DB_REP_DUPMASTER</a>. If |
| 55 | the application sees this return, it should reconfigure itself as a |
| 56 | client (by calling <a href="../api_reference/C/repstart.html" class="olink">DB_ENV->rep_start()</a>), and then call for an election |
| 57 | (by calling <a href="../api_reference/C/repelect.html" class="olink">DB_ENV->rep_elect()</a>). The site that wins the election may be |
| 58 | one of the two previous masters, or it may be another site entirely. |
| 59 | Regardless, the winning system will bring all of the other systems into |
| 60 | conformance.</p> |
| 61 | <p>As another example, consider a replication group with a master |
| 62 | environment and two clients A and B, where client A may upgrade to |
| 63 | master status and client B cannot. Then, assume client A is partitioned |
| 64 | from the other two database environments, and it becomes out-of-date |
| 65 | with respect to the master. Then, assume the master crashes and does |
| 66 | not come back on-line. Subsequently, the network partition is restored, |
| 67 | and clients A and B hold an election. As client B cannot win the |
| 68 | election, client A will win by default, and in order to get back into |
| 69 | sync with client B, possibly committed transactions on client B will be |
| 70 | unrolled until the two sites can once again move forward together.</p> |
| 71 | <p>In both of these examples, there is a phase where a newly elected master |
| 72 | brings the members of a replication group into conformance with itself |
| 73 | so that it can start sending new information to them. This can result |
| 74 | in the loss of information as previously committed transactions are |
| 75 | unrolled.</p> |
| 76 | <p>In architectures where network partitions are an issue, applications |
| 77 | may want to implement a heart-beat protocol to minimize the consequences |
| 78 | of a bad network partition. As long as a master is able to contact at |
| 79 | least half of the sites in the replication group, it is impossible for |
| 80 | there to be two masters. If the master can no longer contact a |
| 81 | sufficient number of systems, it should reconfigure itself as a client, |
| 82 | and hold an election. Replication Manager does not currently |
| 83 | implement such a feature, so this technique is only available to Base API |
| 84 | applications.</p> |
| 85 | <p>There is another tool applications can use to minimize the damage in |
| 86 | the case of a network partition. By specifying an <span class="bold"><strong>nsites</strong></span> |
| 87 | argument to <a href="../api_reference/C/repelect.html" class="olink">DB_ENV->rep_elect()</a> that is larger than the actual number of |
| 88 | database environments in the replication group, Base API applications can keep |
| 89 | systems from declaring themselves the master unless they can talk to |
| 90 | a large percentage of the sites in the system. For example, if there |
| 91 | are 20 database environments in the replication group, and an argument |
| 92 | of 30 is specified to the <a href="../api_reference/C/repelect.html" class="olink">DB_ENV->rep_elect()</a> method, then a system will have |
| 93 | to be able to talk to at least 16 of the sites to declare itself the |
| 94 | master.</p> |
| 95 | <p>Replication Manager uses the value of <span class="bold"><strong>nsites</strong></span> (configured by |
| 96 | the <a href="../api_reference/C/repnsites.html" class="olink">DB_ENV->rep_set_nsites()</a> method) for elections as well as in calculating how |
| 97 | many acknowledgements to wait for when sending a |
| 98 | <a href="../api_reference/C/reptransport.html#transport_DB_REP_PERMANENT" class="olink">DB_REP_PERMANENT</a> message. So this technique may be useful here |
| 99 | as well, unless the application uses the <a href="../api_reference/C/repmgrset_ack_policy.html#ackspolicy_DB_REPMGR_ACKS_ALL" class="olink">DB_REPMGR_ACKS_ALL</a> or |
| 100 | <a href="../api_reference/C/repmgrset_ack_policy.html#ackspolicy_DB_REPMGR_ACKS_ALL_PEERS" class="olink">DB_REPMGR_ACKS_ALL_PEERS</a> acknowledgement policies.</p> |
| 101 | <p>Specifying a <span class="bold"><strong>nsites</strong></span> argument to <a href="../api_reference/C/repelect.html" class="olink">DB_ENV->rep_elect()</a> that is |
| 102 | smaller than the actual number of database environments in the |
| 103 | replication group has its uses as well. For example, consider a |
| 104 | replication group with 2 environments. If they are partitioned from |
| 105 | each other, neither of the sites could ever get enough votes to become |
| 106 | the master. A reasonable alternative would be to specify a |
| 107 | <span class="bold"><strong>nsites</strong></span> argument of 2 to one of the systems |
| 108 | and a <span class="bold"><strong>nsites</strong></span> |
| 109 | argument of 1 to the other. That way, one of the systems could win |
| 110 | elections even when partitioned, while the other one could not. This |
| 111 | would allow one of the systems to continue accepting write |
| 112 | queries after the partition.</p> |
| 113 | <p>In a 2-site group, Replication Manager by default reacts to the loss of |
| 114 | communication with the master by observing a strict majority rule that |
| 115 | prevents the survivor from taking over. Thus it avoids multiple masters and |
| 116 | the need to unroll some transactions if both sites are running but cannot |
| 117 | communicate. But it does leave the group in a read-only state until both |
| 118 | sites are available. If application availability while one site is down is a |
| 119 | priority and it is acceptable to risk unrolling some transactions, there |
| 120 | is a configuration option to turn off the strict majority rule and allow |
| 121 | the surviving client to declare itself to be master. See the <a href="../api_reference/C/repconfig.html" class="olink">DB_ENV->rep_set_config()</a> |
| 122 | method <a href="../api_reference/C/repconfig.html#config_DB_REPMGR_CONF_2SITE_STRICT" class="olink">DB_REPMGR_CONF_2SITE_STRICT</a> flag for more information.</p> |
| 123 | <p>These scenarios stress the importance of good network infrastructure in |
| 124 | Berkeley DB replicated environments. When replicating database environments |
| 125 | over sufficiently lossy networking, the best solution may well be to |
| 126 | pick a single master, and only hold elections when human intervention |
| 127 | has determined the selected master is unable to recover at all.</p> |
| 128 | </div> |
| 129 | <div class="navfooter"> |
| 130 | <hr /> |
| 131 | <table width="100%" summary="Navigation footer"> |
| 132 | <tr> |
| 133 | <td width="40%" align="left"><a accesskey="p" href="rep_twosite.html">Prev</a> </td> |
| 134 | <td width="20%" align="center"> |
| 135 | <a accesskey="u" href="rep.html">Up</a> |
| 136 | </td> |
| 137 | <td width="40%" align="right"> <a accesskey="n" href="rep_faq.html">Next</a></td> |
| 138 | </tr> |
| 139 | <tr> |
| 140 | <td width="40%" align="left" valign="top">Special considerations for two-site replication groups </td> |
| 141 | <td width="20%" align="center"> |
| 142 | <a accesskey="h" href="index.html">Home</a> |
| 143 | </td> |
| 144 | <td width="40%" align="right" valign="top"> Replication FAQ</td> |
| 145 | </tr> |
| 146 | </table> |
| 147 | </div> |
| 148 | </body> |
| 149 | </html> |