<ahref="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>
<divclass="sect2"lang="en"xml:lang="en">
<divclass="titlepage">
<div>
<div>
<h3class="title"><aid="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 <ahref="../api_reference/C/txnset_commit_token.html"class="olink">DB_TXN->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 <aclass="ulink"href="../java/com/sleepycat/db/Transaction.html#getCommitToken()"target="_top">Transaction.getCommitToken()</a> method,