File: repmgr_channels.html

package info (click to toggle)
db5.3 5.3.28%2Bdfsg1-0.5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 158,360 kB
  • sloc: ansic: 448,411; java: 111,824; tcl: 80,544; sh: 44,326; cs: 33,697; cpp: 21,604; perl: 14,557; xml: 10,799; makefile: 4,077; yacc: 1,003; awk: 965; sql: 801; erlang: 342; python: 216; php: 24; asm: 14
file content (288 lines) | stat: -rw-r--r-- 13,658 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Using Replication Manager message channels</title>
    <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
    <link rel="start" href="index.html" title="Berkeley DB Programmer's Reference Guide" />
    <link rel="up" href="rep.html" title="Chapter 12.  Berkeley DB Replication" />
    <link rel="prev" href="rep_clock_skew.html" title="Clock Skew" />
    <link rel="next" href="rep_twosite.html" title="Special considerations for two-site replication groups" />
  </head>
  <body>
    <div xmlns="" class="navheader">
      <div class="libver">
        <p>Library Version 11.2.5.3</p>
      </div>
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">Using Replication Manager message channels</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="rep_clock_skew.html">Prev</a> </td>
          <th width="60%" align="center">Chapter 12. 
		Berkeley DB Replication
        </th>
          <td width="20%" align="right"> <a accesskey="n" href="rep_twosite.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="sect1" lang="en" xml:lang="en">
      <div class="titlepage">
        <div>
          <div>
            <h2 class="title" style="clear: both"><a id="repmgr_channels"></a>Using Replication Manager message channels</h2>
          </div>
        </div>
      </div>
      <div class="toc">
        <dl>
          <dt>
            <span class="sect2">
              <a href="repmgr_channels.html#dbchannel_class">DB_CHANNEL</a>
            </span>
          </dt>
          <dt>
            <span class="sect2">
              <a href="repmgr_channels.html#dbchannel_send">Sending messages over a message channel</a>
            </span>
          </dt>
          <dt>
            <span class="sect2">
              <a href="repmgr_channels.html#dbchannel_receive">Receiving messages</a>
            </span>
          </dt>
        </dl>
      </div>
      <p>
        The various sites comprising a replication group frequently need to
        communicate with one another. Mostly, these messages are handled
        for you internally by the Replication Manager. However, your
        application may have a requirement to pass messages beyond what the
        Replication Manager requires in order to satisfy its own internal
        workings.
    </p>
      <p>
        For this reason, you can access and use the Replication Manager's
        internal message channels. You do this by using the
        <code class="literal">DB_CHANNEL</code> class, and by implementing a message
        handling function on each of your sites.
    </p>
      <p>
        Note that an example of using Replication Manager message channels
        is available in the distribution. See
        <a class="xref" href="rep_ex_chan.html" title="Ex_rep_chan: a Replication Manager channel example">Ex_rep_chan: a Replication Manager
channel example</a>
        for more information.
    </p>
      <div class="sect2" lang="en" xml:lang="en">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title"><a id="dbchannel_class"></a>DB_CHANNEL</h3>
            </div>
          </div>
        </div>
        <p>
            The <code class="literal">DB_CHANNEL</code> class provides a series of
            methods which allow you to send messages to the other sites in
            your replication group. You create a <code class="literal">DB_CHANNEL</code>
            handle using the <a href="../api_reference/C/repmgr_channel.html" class="olink">DB_ENV-&gt;repmgr_channel()</a> method. When you are
            done with the handle, close it using the <a href="../api_reference/C/dbchannel_close.html" class="olink">DB_CHANNEL-&gt;close()</a>
            method. A closed handle must never be accessed again. Note that
            all channel handles should be closed before the associated
            environment handle is closed. Also, allow all message
            operations to complete on the channel before closing the
            handle.
        </p>
        <p>
            When you create a <code class="literal">DB_CHANNEL</code> handle, you
            indicate what channel you want to use. Possibilities are:
        </p>
        <div class="itemizedlist">
          <ul type="disc">
            <li>
              <p>
                     The numerical env ID of a remote site in the
                     replication group.
                 </p>
            </li>
            <li>
              <p>
                     <code class="literal">DB_EID_MASTER</code>
                 </p>
              <p>
                     Messages sent on this channel are sent only to the
                     master site. Note that messages are always sent to
                     the current master, even if the master has changed
                     since the channel was opened.
                 </p>
              <p>
                     If the local site is the master, then sending messages
                     on this channel will result in the local site
                     receiving those messages echoed back to itself.
                 </p>
            </li>
          </ul>
        </div>
      </div>
      <div class="sect2" lang="en" xml:lang="en">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title"><a id="dbchannel_send"></a>Sending messages over a message channel</h3>
            </div>
          </div>
        </div>
        <p>
            You can send any message you want over a message channel. The
            message can be as simple as a character string and as complex
            as a large data structure. However, before you can send the
            message, you must encapsulate it within one or more <a href="../api_reference/C/dbt.html" class="olink">DBT</a>s.
            This means <a class="link" href="am_misc_struct.html" title="Storing C/C++ structures/objects">marshaling the message</a>
            if it is contained within a complex data structure.
        </p>
        <p>
           The methods that you use to send messages all accept an array of
           <a href="../api_reference/C/dbt.html" class="olink">DBT</a>s. This means that in most circumstances it is perfectly
           acceptable to send multi-part messages.
        </p>
        <p>
            Messages may be sent either asynchronously or synchronously.
            To send a message asynchronously, use the <a href="../api_reference/C/dbchannel_send_msg.html" class="olink">DB_CHANNEL-&gt;send_msg()</a>
            method. This method sends its message and then immediately
            returns without waiting for any sort of a response. 
            
            
        </p>
        <p>
            To send a message synchronously, use the
            <a href="../api_reference/C/dbchannel_send_request.html" class="olink">DB_CHANNEL-&gt;send_request()</a> method. This method blocks until it
            receives a response from the site to which it sent the message
            (or until a timeout threshold is reached).  
            
            
        </p>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="dbchannel_respond"></a>Message Responses</h4>
              </div>
            </div>
          </div>
          <p>
                Message responses are required if a message is sent on a
                channel using the <a href="../api_reference/C/dbchannel_send_request.html" class="olink">DB_CHANNEL-&gt;send_request()</a> method. That
                method accepts the address of a single <a href="../api_reference/C/dbt.html" class="olink">DBT</a> which is used
                to receive the response from the remote site.
            </p>
          <p>
                Message responses are encapsulated in a single <a href="../api_reference/C/dbt.html" class="olink">DBT</a>. The
                response can be anything from a complex data structure, to
                a string, to a simple type, to no information at all. In
                the latter case, receipt of the <a href="../api_reference/C/dbt.html" class="olink">DBT</a> is sufficient to
                indicate that the request was received at the remote site.
            </p>
          <p>
                Responses are sent back from the remote system using its
                message handling function. Usually that function calls
                <a href="../api_reference/C/dbchannel_send_msg.html" class="olink">DB_CHANNEL-&gt;send_msg()</a> to send a single response. 
            </p>
          <p>
                The response must be contained in a single <a href="../api_reference/C/dbt.html" class="olink">DBT</a>. If a
                multi-part response is required by the application, you can
                configure the response <a href="../api_reference/C/dbt.html" class="olink">DBT</a> that you provide to
                <a href="../api_reference/C/dbchannel_send_request.html" class="olink">DB_CHANNEL-&gt;send_request()</a> for 
                <a class="link" href="am_misc_bulk.html" title="Retrieving and updating records in bulk">bulk operations</a>.
            </p>
        </div>
      </div>
      <div class="sect2" lang="en" xml:lang="en">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title"><a id="dbchannel_receive"></a>Receiving messages</h3>
            </div>
          </div>
        </div>
        <p>
            Messages received at a remote site are handled using a callback
            function. This function is configured for the local environment
            using the <a href="../api_reference/C/repmgr_msg_dispatch.html" class="olink">DB_ENV-&gt;repmgr_msg_dispatch()</a> method. For best results,
            the message dispatch function should be configured for the
            local environment before replication is started. In this way,
            you do not run the risk of missing messages sent after
            replication has started but before the message dispatch
            function is configured for the environment.
        </p>
        <p>
            The callback configured by <a href="../api_reference/C/repmgr_msg_dispatch.html" class="olink">DB_ENV-&gt;repmgr_msg_dispatch()</a> accepts
            four parameters of note:
        </p>
        <div class="itemizedlist">
          <ul type="disc">
            <li>
              <p>
                    A response channel. This is the channel the function
                    will use to response to the message, if a response is
                    required. To respond to the message, the function uses
                    the <a href="../api_reference/C/dbchannel_send_msg.html" class="olink">DB_CHANNEL-&gt;send_msg()</a> method.
                </p>
            </li>
            <li>
              <p>
                    An array of <a href="../api_reference/C/dbt.html" class="olink">DBT</a>s. These hold the message that this
                    function must handle.
                </p>
            </li>
            <li>
              <p>
                    A numerical value that indicates how many elements the
                    previously described array holds.
                </p>
            </li>
            <li>
              <p>
                    A flag that indicates whether the message requires a
                    response. If the flag is set to 
                    <code class="literal">DB_REPMGR_NEED_RESPONSE</code>,
                    then the function should send a single <a href="../api_reference/C/dbt.html" class="olink">DBT</a> in
                    response using the channel provided to this function,
                    and the <a href="../api_reference/C/dbchannel_send_msg.html" class="olink">DB_CHANNEL-&gt;send_msg()</a> method.
                </p>
            </li>
          </ul>
        </div>
        <p>
            For an example of using this callback, see the
            <code class="literal">operation_dispatch()</code> function, which is
            available with the <a class="link" href="rep_ex_chan.html" title="Ex_rep_chan: a Replication Manager channel example">ex_rep_chan example</a>
            in your product distribution.
        </p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="rep_clock_skew.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="rep.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="rep_twosite.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">Clock Skew </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> Special considerations for two-site replication groups</td>
        </tr>
      </table>
    </div>
  </body>
</html>