File: rep_ryw.html

package info (click to toggle)
db5.3 5.3.28%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 158,500 kB
  • sloc: ansic: 448,411; java: 111,824; tcl: 80,544; sh: 44,264; cs: 33,697; cpp: 21,604; perl: 14,557; xml: 10,799; makefile: 4,077; javascript: 1,998; yacc: 1,003; awk: 965; sql: 801; erlang: 342; python: 216; php: 24; asm: 14
file content (214 lines) | stat: -rw-r--r-- 10,054 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
<?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>Read your writes consistency</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_lease.html" title="Master Leases" />
    <link rel="next" href="rep_clock_skew.html" title="Clock Skew" />
  </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">Read your writes consistency</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="rep_lease.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_clock_skew.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="rep_ryw"></a>Read your writes consistency</h2>
          </div>
        </div>
      </div>
      <div class="toc">
        <dl>
          <dt>
            <span class="sect2">
              <a href="rep_ryw.html#gettoken">Getting a token</a>
            </span>
          </dt>
          <dt>
            <span class="sect2">
              <a href="rep_ryw.html#tokenhandling">Token handling</a>
            </span>
          </dt>
          <dt>
            <span class="sect2">
              <a href="rep_ryw.html#usingtoken">Using a token to check or wait for a transaction</a>
            </span>
          </dt>
        </dl>
      </div>
      <p>
        Some applications require the ability to read replicated data at a
        client site, and determine whether it is consistent with data that
        has been written previously at the master site.
    </p>
      <p>
        For example, a web application may be backed by multiple database
        environments, linked to form a replication group, in order to share
        the workload.  Web requests that update data must be served by the
        replication master, but any site in the group may serve a read-only
        request.  Consider a work flow of a series of web requests from one
        specific user at a web browser: the first request generates a
        database update, but the second request merely reads data.  If the
        read-only request is served by a replication client database
        environment, it may be important to make sure that the updated data
        has been replicated to the client before performing the read (or to wait
        until it has been replicated) in order to show this user a
        consistent view of the data.
    </p>
      <p>
        Berkeley DB supports this requirement through the use of transaction
        "tokens".  A token is a form of identification for a transaction
        within the scope of the replication group.  The application may
        request a copy of the transaction's token at the master site during
        the execution of the transaction.  Later, the application running
        on a client site can use a copy of the token to determine whether
        the transaction has been applied at that site.
    </p>
      <p>
        It is the application's responsibility to keep track of the token
        during the interim.  In the web example, the token might be sent to
        the browser as a "cookie", or stored on the application server in
        the user's session context.
    </p>
      <p>
        The operations described here are supported both for Replication
        Manager applications and for applications that use the replication
        Base API.
    </p>
      <div class="sect2" lang="en" xml:lang="en">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title"><a id="gettoken"></a>Getting a token</h3>
            </div>
          </div>
        </div>
        <p>
            In order to get a token, the application must supply a small
            memory buffer, using the <a href="../api_reference/C/txnset_commit_token.html" class="olink">DB_TXN-&gt;set_commit_token()</a> method.
        </p>
        <p>
            Note that a token is generated only upon a successful commit
            operation, and therefore the token buffer content is valid
            only after a successful commit.  Also, if a transaction does
            not perform any update operations it does not generate a useful
            token.
        </p>
        <p>
            In the Berkeley DB Java and C# API, getting a token is simpler.
            The application need only invoke the <a class="ulink" href="../java/com/sleepycat/db/Transaction.html#getCommitToken()" target="_top">Transaction.getCommitToken()</a> method,
            after the transaction has committed.
        </p>
      </div>
      <div class="sect2" lang="en" xml:lang="en">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title"><a id="tokenhandling"></a>Token handling</h3>
            </div>
          </div>
        </div>
        <p>
            The application should not try to interpret the content of the
            token buffer, but may store and/or transmit it freely between
            systems.  However, since the buffer contains binary data it
            may be necessary to apply some encoding for transmission (e.g.,
            base 64).
        </p>
        <p>
            The data is resilient to differences in byte order between
            different systems.  It does not expire: it may be retained
            indefinitely for later use, even across Berkeley DB version
            upgrades.
        </p>
      </div>
      <div class="sect2" lang="en" xml:lang="en">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title"><a id="usingtoken"></a>Using a token to check or wait for a transaction</h3>
            </div>
          </div>
        </div>
        <p>
            The <a href="../api_reference/C/envtxn_applied.html" class="olink">DB_ENV-&gt;txn_applied()</a> method takes a copy of a token, and
            determines whether the corresponding transaction is currently
            applied at the local site.  The timeout argument allows the
            application to block for a bounded amount of time for cases
            where the transaction has not yet been applied.
        </p>
        <p>
            Depending on the transaction durability levels implemented or
            configured by the application, it is sometimes possible for a
            transaction to disappear from a replication group if an
            original master site fails and a different site becomes the new
            master without having received the transaction.  When the
            <a href="../api_reference/C/envtxn_applied.html" class="olink">DB_ENV-&gt;txn_applied()</a> method discovers this, it produces the
            <code class="literal">DB_NOTFOUND</code> return code.
        </p>
        <p>
            This means that the results of <a href="../api_reference/C/envtxn_applied.html" class="olink">DB_ENV-&gt;txn_applied()</a> are not guaranteed
            forever.  Even after a successful call to <a href="../api_reference/C/envtxn_applied.html" class="olink">DB_ENV-&gt;txn_applied()</a>, it is
            possible that by the time the application tries to read the
            data, the transaction and its data could have disappeared.
        </p>
        <p>
            To avoid this problem the application should do the read
            operations in the context of a transaction, and hold the
            transaction handle open during the <a href="../api_reference/C/envtxn_applied.html" class="olink">DB_ENV-&gt;txn_applied()</a> call.  The
            <a href="../api_reference/C/envtxn_applied.html" class="olink">DB_ENV-&gt;txn_applied()</a> method itself does not actually execute in the
            context of the transaction; but no rollbacks due to new master
            synchronization ever occur while a transaction is active, even
            a read-only transaction at a client site.
        </p>
        <p>
            Note that the <a href="../api_reference/C/envtxn_applied.html" class="olink">DB_ENV-&gt;txn_applied()</a> method can return
            <code class="literal">DB_LOCK_DEADLOCK</code>.  The application should
            respond to this situation just as it does for any other normal
            operation: abort any existing transaction, and then pause
            briefly before retrying.
        </p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="rep_lease.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_clock_skew.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">Master Leases </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> Clock Skew</td>
        </tr>
      </table>
    </div>
  </body>
</html>