Debian Codegraph @

docs/programmer_reference/rep_ex_rq.html

raw symbols SCIP
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>Ex_rep_base: putting it all together</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_ex_comm.html" title="Ex_rep_base: a TCP/IP based communication infrastructure" />
12 <link rel="next" href="rep_ex_chan.html" title="Ex_rep_chan: a Replication Manager channel example" />
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">Ex_rep_base: putting it all together</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="rep_ex_comm.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_ex_chan.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_ex_rq"></a>Ex_rep_base: putting it all together</h2>
38 </div>
39 </div>
40 </div>
41 <p>Beyond simply initializing a replicated environment, a Base API application
42 must set up its communication
43 infrastructure, and then make sure that incoming messages are received
44 and processed.</p>
45 <p>To initialize replication, ex_rep_base creates a Berkeley DB environment and
46 calls <a href="../api_reference/C/reptransport.html" class="olink">DB_ENV-&gt;rep_set_transport()</a> to establish a send function. (See
47 the main function in <code class="filename">ex_rep/base/rep_base.c</code>, including its
48 calls to the create_env and env_init functions in
49 <code class="filename">ex_rep/common/rep_common.c</code>.)</p>
50 <p>ex_rep_base opens a listening socket for incoming connections and opens
51 an outgoing connection to every machine that it knows about (that is,
52 all the sites listed in the <span class="bold"><strong>-r</strong></span> and
53 <span class="bold"><strong>-R</strong></span> command line arguments).
54 Applications can structure the details of this in different ways, but
55 ex_rep_base creates a user-level thread to listen on its socket, plus
56 a thread to loop and handle messages on each socket, in addition to the
57 threads needed to manage the user interface, update the database on the
58 master, and read from the database on the client (in other words, in
59 addition to the normal functionality of any database application).</p>
60 <p>Once the initial threads have all been started and the communications
61 infrastructure is initialized, the application signals that it is ready
62 for replication and joins a replication group by calling
63 <a href="../api_reference/C/repstart.html" class="olink">DB_ENV-&gt;rep_start()</a>. (Again, see the main function in
64 <code class="filename">ex_rep/base/rep_base.c</code>.)</p>
65 <p>Note the use of the optional second argument to <a href="../api_reference/C/repstart.html" class="olink">DB_ENV-&gt;rep_start()</a> in
66 the client initialization code. The argument "local" is a piece of
67 data, opaque to Berkeley DB, that will be broadcast to each member of a
68 replication group; it allows new clients to join a replication group,
69 without knowing the location of all its members; the new client will
70 be contacted by the members it does not know about, who will receive
71 the new client's contact information that was specified in "myaddr."
72 See <a class="xref" href="rep_newsite.html" title="Connecting to a new site">Connecting to a new site</a> for more
73 information.</p>
74 <p>The final piece of a replicated application is the code that loops,
75 receives, and processes messages from a given remote environment.
76 ex_rep_base runs one of these loops in a parallel thread for each
77 socket connection (see the hm_loop function in
78 <code class="filename">ex_rep/base/rep_msg.c</code>). Other applications may want to queue
79 messages somehow and process them asynchronously, or select() on a
80 number of sockets and either look up the correct environment ID for each
81 or encapsulate the ID in the communications protocol.</p>
82 </div>
83 <div class="navfooter">
84 <hr />
85 <table width="100%" summary="Navigation footer">
86 <tr>
87 <td width="40%" align="left"><a accesskey="p" href="rep_ex_comm.html">Prev</a> </td>
88 <td width="20%" align="center">
89 <a accesskey="u" href="rep.html">Up</a>
90 </td>
91 <td width="40%" align="right"> <a accesskey="n" href="rep_ex_chan.html">Next</a></td>
92 </tr>
93 <tr>
94 <td width="40%" align="left" valign="top">Ex_rep_base: a TCP/IP based communication infrastructure </td>
95 <td width="20%" align="center">
96 <a accesskey="h" href="index.html">Home</a>
97 </td>
98 <td width="40%" align="right" valign="top"> Ex_rep_chan: a Replication Manager
99 channel example</td>
100 </tr>
101 </table>
102 </div>
103 </body>
104 </html>