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>The Replication APIs</title> 7 <link rel="stylesheet" href="gettingStarted.css" type="text/css" /> 8 <meta name="generator" content="DocBook XSL Stylesheets V1.62.4" /> 9 <link rel="home" href="index.html" title="Getting Started with Replicated Berkeley DB Applications" /> 10 <link rel="up" href="introduction.html" title="Chapter��1.��Introduction" /> 11 <link rel="previous" href="repadvantage.html" title="Replication Benefits" /> 12 <link rel="next" href="elections.html" title="Holding Elections" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">The Replication APIs</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="repadvantage.html">Prev</a>��</td> 22 <th width="60%" align="center">Chapter��1.��Introduction</th> 23 <td width="20%" align="right">��<a accesskey="n" href="elections.html">Next</a></td> 24 </tr> 25 </table> 26 <hr /> 27 </div> 28 <div class="sect1" lang="en" xml:lang="en"> 29 <div class="titlepage"> 30 <div> 31 <div> 32 <h2 class="title" style="clear: both"><a id="apioverview"></a>The Replication APIs</h2> 33 </div> 34 </div> 35 <div></div> 36 </div> 37 <p> 38 There are two ways that you can choose to implement 39 replication in your transactional application. The first, 40 and preferred, mechanism is to use the pre-packaged 41 replication framework that comes with the 42 DB distribution. This framework should be sufficient 43 for most customers. 44 </p> 45 <p> 46 If for some reason the Replication Framework 47 does not meet your application's technical requirements, 48 you will have to use the replication APIs available 49 through the Berkeley DB library to write your own custom 50 replication framework. 51 </p> 52 <p> 53 Both of these approaches are described in slightly greater 54 detail in this section. The bulk of the chapters later in 55 this book are dedicated to these two replication 56 implementation mechanisms. 57 </p> 58 <div class="sect2" lang="en" xml:lang="en"> 59 <div class="titlepage"> 60 <div> 61 <div> 62 <h3 class="title"><a id="repframeworkoverview"></a>Replication Framework Overview</h3> 63 </div> 64 </div> 65 <div></div> 66 </div> 67 <p> 68 DB's pre-packaged replication framework exists 69 as a layer on top of the DB library. The replication framework is a 70 multi-threaded implementation that allows you to easily add 71 replication to your existing transactional application. 72 73 <span> 74 You access and manage the replication framework using special 75 methods and classes designated for its use. 76 Mostly these are centered around the 77 <tt class="classname">Environment</tt> 78 and 79 <tt class="classname">EnvironmentConfig</tt> 80 classes. 81 </span> 82 </p> 83 <p> 84 The replication framework: 85 </p> 86 <div class="itemizedlist"> 87 <ul type="disc"> 88 <li> 89 <p> 90 Provides a multi-threaded communications layer 91 using pthreads (on Unix-style systems and 92 similar derivatives such as Mac OS X), or 93 Windows threads on Microsoft Windows systems. 94 </p> 95 </li> 96 <li> 97 <p> 98 Uses TCP/IP sockets. Network traffic is 99 handled via threads that handle inbound and 100 outbound messages. However, each 101 process uses a single socket 102 that is shared using <tt class="function">select()</tt>. 103 </p> 104 <p> 105 Note that for this reason, the replication framework is 106 limited to a maximum of 60 replicas (on 107 Windows) and approximately 1000 replicas (on 108 Unix and related systems), depending on how 109 your system is configured. 110 </p> 111 </li> 112 <li> 113 <p> 114 Requires a single process for the master replica. 115 </p> 116 </li> 117 <li> 118 <p> 119 Requires that only one instance of the 120 environment handle be used. 121 </p> 122 </li> 123 <li> 124 <p> 125 Upon application startup, a master can be 126 selected either manually or via elections. 127 After startup time, however, during the course of 128 normal operations it is possible for the 129 replication group to need to locate a new master (due 130 to network or other hardware related problems, 131 for example) and in this scenario elections are 132 always used to select the new master. 133 </p> 134 </li> 135 </ul> 136 </div> 137 <p> 138 If your application has technical requirements that do 139 not conform to the implementation provided by the 140 replication framework, you must write a custom 141 replication framework using the DB replication APIs 142 directly. See the next section for introductory 143 details. 144 </p> 145 </div> 146 <div class="sect2" lang="en" xml:lang="en"> 147 <div class="titlepage"> 148 <div> 149 <div> 150 <h3 class="title"><a id="repapioverview"></a>Replication API Overview</h3> 151 </div> 152 </div> 153 <div></div> 154 </div> 155 <p> 156 The replication API is a series of Berkeley DB library 157 classes and methods that you can use to build your own 158 replication infrastructure. You should use the 159 replication API only if the replication framework does not meet your 160 application's technical requirements. 161 </p> 162 <p> 163 To make use of the replication API, you must write your 164 own networking code. This frees you from the technical 165 constraints imposed by the replication framework. For example, by 166 writing your own framework, you can: 167 </p> 168 <div class="itemizedlist"> 169 <ul type="disc"> 170 <li> 171 <p> 172 Use a threading package other than 173 pthreads (Unix) or Windows threads 174 (Microsoft Windows). This might be interesting 175 to you if you are using a platform 176 whose preferred threading package 177 is something other than (for 178 example) pthreads, such as is the case for 179 Sun Microsystem's Solaris operating systems. 180 </p> 181 </li> 182 <li> 183 <p> 184 Implement your own sockets. The 185 replication framework uses TCP/IP sockets. While 186 this should be acceptable for the 187 majority of applications, sometimes 188 UDP or even raw sockets might be 189 desired. 190 </p> 191 </li> 192 <li> 193 <p> 194 Write a multi-process master 195 replica. 196 </p> 197 </li> 198 </ul> 199 </div> 200 <p> 201 For information on writing a replicated application 202 using the Berkeley DB replication APIs, see the 203 <i class="citetitle">Berkeley DB Programmer's Reference Guide</i>. 204 </p> 205 </div> 206 </div> 207 <div class="navfooter"> 208 <hr /> 209 <table width="100%" summary="Navigation footer"> 210 <tr> 211 <td width="40%" align="left"><a accesskey="p" href="repadvantage.html">Prev</a>��</td> 212 <td width="20%" align="center"> 213 <a accesskey="u" href="introduction.html">Up</a> 214 </td> 215 <td width="40%" align="right">��<a accesskey="n" href="elections.html">Next</a></td> 216 </tr> 217 <tr> 218 <td width="40%" align="left" valign="top">Replication Benefits��</td> 219 <td width="20%" align="center"> 220 <a accesskey="h" href="index.html">Home</a> 221 </td> 222 <td width="40%" align="right" valign="top">��Holding Elections</td> 223 </tr> 224 </table> 225 </div> 226 </body> 227</html> 228