blob: 8ef1c0a3f91f4b04faa46fb7b105be2a77824756 [file] [log] [blame]
<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>About Cache Coordination | EclipseLink 2.5.x Understanding EclipseLink</title>
<meta name="generator" content="Oracle DARB XHTML Converter (Mode = document) - Version 1.0.11" />
<meta name="date" content="2013-01-29T16:49:7Z" />
<meta name="robots" content="noarchive" />
<meta name="doctitle" content="About Cache Coordination" />
<meta name="relnum" content="Release 2.4" />
<link rel="stylesheet" type="text/css" href="../../dcommon/style.css" media="screen" />
<link rel="copyright" href="../../dcommon/html/cpyr.htm" title="Copyright" type="text/html" />
<link rel="start" href="../../index.htm" title="Home" type="text/html" />
<link rel="contents" href="toc.htm" title="Contents" type="text/html" />
<link rel="prev" href="cache011.htm" title="Previous" type="text/html" />
<link rel="next" href="queries.htm" title="Next" type="text/html" />
<!-- START: Disqus --><script type="text/javascript"> var disqus_developer = 0; </script><!-- END: Disqus --><!-- START: Sharethis --><script type="text/javascript">var switchTo5x=true;</script><script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script><script type="text/javascript" src="http://s.sharethis.com/loader.js"></script> <!-- END: Sharethis --></head>
<body bgcolor="#FFFFFF"><iframe id="docheader" frameborder="0" framemargin="0" scrolling="no" src="../../dcommon/header.html"></iframe><script src="http://www.google.com/jsapi" type="text/javascript"></script><script type="text/javascript"> google.load('search', '1', {language : 'en'}); google.setOnLoadCallback(function() { var customSearchOptions = {}; var googleAnalyticsOptions = {}; googleAnalyticsOptions['queryParameter'] = 'q'; googleAnalyticsOptions['categoryParameter'] = ''; customSearchOptions['googleAnalyticsOptions'] = googleAnalyticsOptions; var customSearchControl = new google.search.CustomSearchControl( '016171230611334810008:mdbgdwjv8zu', customSearchOptions); customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET); var options = new google.search.DrawOptions(); options.setSearchFormRoot('cse-search-form'); customSearchControl.draw('cse', options); }, true);</script><link rel="stylesheet" href="http://www.google.com/cse/style/look/default.css" type="text/css" /><div id="cse" style="width:100%;"></div>
<div class="header"><a id="top" name="top"></a>
<table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td align="left" valign="top"><div class="booktitle">Understanding EclipseLink,
Release 2.5</div></td>
<td valign="bottom" align="right" width="144">
<table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td>&nbsp;</td>
<td align="center" valign="top"><a href="toc.htm"><img src="../../dcommon/images/contents.png" alt="Go To Table Of Contents" border="0" height="16" width="16" /><br />
</td><td>&nbsp;</td><td align="center"><a href="../../" target="_top" class="external text" title="Search" rel="nofollow"><img src="../../dcommon/images/search.png" alt="Search" style="border:0;" /><br /><span class="mini"></span></a></td><td>&nbsp;</td><td align="center"><a href="../eclipselink_otlcg.pdf" title="PDF" target="_blank"><img src="../../dcommon/images/pdf_icon.png" style="padding-right:5px;border:0" alt="PDF"></a></td>
</tr>
</table>
</td>
</tr>
</table>
<hr />
<table class="navigation simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100" align="center">
<tr>
<td align="center"><a href="cache011.htm"><img src="../../dcommon/images/larrow.png" alt="Previous" border="0" height="16" width="16" /></a></td>
<td align="center"><a href="queries.htm"><img src="../../dcommon/images/rarrow.png" alt="Next" border="0" height="16" width="16" /></a></td>
<td>&nbsp;</td>
</tr>
</table>
</div>
<!-- class="header" -->
<div class="ind"><!-- End Header -->
<p align="center"><font color="#FF0000">Beta Draft: 2013-01-29</font></p>
<a id="CDEIBJCE" name="CDEIBJCE"></a><a id="OTLCG94339" name="OTLCG94339"></a>
<div class="sect1"><!-- infolevel="all" infotype="General" -->
<h1 class="sect1"><font face="arial, helvetica, sans-serif" color="#330099">About Cache Coordination</font></h1>
<p>The need to maintain up-to-date data for all applications is a key design challenge for building a distributed application. The difficulty of this increases as the number of servers within an environment increases. EclipseLink provides a distributed cache coordination feature that ensures data in distributed applications remains current.</p>
<p>Cache coordination reduces the number of optimistic lock exceptions encountered in a distributed architecture, and decreases the number of failed or repeated transactions in an application. However, cache coordination in no way eliminates the need for an effective locking policy. To effectively ensure working with up-to-date data, cache coordination must be used with optimistic or pessimistic locking. Oracle recommends that you use cache coordination with an optimistic locking policy.</p>
<p>You can use cache invalidation to improve cache coordination efficiency. For more information, see <a href="cache006.htm#CHEEHFCI">About Cache Expiration and Invalidation</a>.</p>
<p>As <a href="#CDEIJFHB">Figure 9-3</a> shows, cache coordination is a session feature that allows multiple, possibly distributed, instances of a session to broadcast object changes among each other so that each session's cache is either kept up-to-date or notified that the cache must update an object from the data source the next time it is read.</p>
<div align="center">
<div class="inftblnote"><br />
<table class="Note oac_no_warn" summary="" border="1" width="80%" frame="hsides" rules="groups" cellpadding="3" cellspacing="0">
<tbody>
<tr>
<td align="left">
<p class="note"><img src="../../dcommon/images/note_icon.png" width="16" height="16" alt="Note" style="vertical-align:middle;padding-right:5px;" />Note:</p>
<p>You cannot use isolated client sessions with cache coordination. For more information, see <a href="cache009.htm#A7975656">About Isolated Client Sessions.</a></p>
</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblnote" --></div>
<div class="figure"><a id="CDEIJFHB" name="CDEIJFHB"></a><a id="OTLCG94340" name="OTLCG94340"></a>
<p><strong><em><font face="arial, helvetica, sans-serif">Figure 9-3 Coordinated Session Caches</font></em></strong></p>
<img src="img/cachcord.gif" alt="Description of Figure 9-3 follows" title="Description of Figure 9-3 follows" longdesc="img_text/cachcord.htm" /><br />
<a id="sthref69" name="sthref69" href="img_text/cachcord.htm">Description of "Figure 9-3 Coordinated Session Caches"</a><br />
<br /></div>
<!-- class="figure" -->
<p>When sessions are distributed, that is, when an application contains multiple sessions (in the same JVM, in multiple JVMs, possibly on different servers), as long as the servers hosting the sessions are interconnected on the network, sessions can participate in cache coordination. Coordinated cache types that require discovery services also require the servers to support User Datagram Protocol (UDP) communication and multicast configuration. For more information, see <a href="#CDEGAJJB">Coordinated Cache Architecture.</a></p>
<p>This section describes the following:</p>
<ul>
<li>
<p><a href="#CDEDBJCJ">When to Use Cache Coordination</a></p>
</li>
<li>
<p><a href="#CDEGAJJB">Coordinated Cache Architecture</a></p>
</li>
<li>
<p><a href="#CDEECFJH">Coordinated Cache Types</a></p>
</li>
<li>
<p><a href="#CDEECFJG">Custom Coordinated Cache</a></p>
</li>
</ul>
<a id="CDEDBJCJ" name="CDEDBJCJ"></a><a id="OTLCG94341" name="OTLCG94341"></a>
<div class="sect2">
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">When to Use Cache Coordination</font></h2>
<p>Cache coordination can enhance performance and reduce the likelihood of stale data for applications that have the following characteristics:</p>
<ul>
<li>
<p>Changes are all being performed by the same Java application operating with multiple, distributed sessions</p>
</li>
<li>
<p>Primarily read-based</p>
</li>
<li>
<p>Regularly requests and updates the same objects</p>
</li>
</ul>
<p>To maximize performance, avoid cache coordination for applications that do not have these characteristics.</p>
<p>For other options to reduce the likelihood of stale data, see <a href="cache004.htm#CHEEACDJ">About Handling Stale Data.</a></p>
</div>
<!-- class="sect2" -->
<a id="CDEGAJJB" name="CDEGAJJB"></a><a id="OTLCG94342" name="OTLCG94342"></a>
<div class="sect2">
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Coordinated Cache Architecture</font></h2>
<p>EclipseLink provides coordinated cache implementations that perform discovery and message transport services using various technologies including the following:</p>
<ul>
<li>
<p>Java Message Service (JMS)&mdash;See <a href="#CDEJABGH">JMS Coordinated Cache.</a></p>
</li>
<li>
<p>Remote Method Invocation (RMI)&mdash;See <a href="#CDEGHFJA">RMI Coordinated Cache.</a></p>
</li>
</ul>
<p>Regardless of the type of discovery and message transport you choose to use, the following are the principal objects that provide coordinated cache functionality:</p>
<ul>
<li>
<p><a href="#CDEEEHCH">Session</a></p>
</li>
<li>
<p><a href="#CDEEEGGI">Descriptor</a></p>
</li>
<li>
<p><a href="#CDEIFIED">Unit of Work</a></p>
</li>
</ul>
<a id="CDEEEHCH" name="CDEEEHCH"></a><a id="OTLCG94343" name="OTLCG94343"></a>
<div class="sect3">
<h3 class="sect3"><font face="arial, helvetica, sans-serif" color="#330099">Session</font></h3>
<p>When you enable a session for change propagation, the session provides discovery and message transport services using either JMS, RMI, or Oracle Application Server Cluster.</p>
<p>Discovery services ensure that sessions announce themselves to other sessions participating in cache coordination. Discovery services use UDP communication and multicast configuration to monitor sessions as they join and leave the coordinated cache. All coordinated cache types (except JMS) require discovery services.</p>
<p>Message transport services allow the session to broadcast object change notifications to other sessions participating in cache coordination when a unit of work from this session commits a change.</p>
</div>
<!-- class="sect3" -->
<a id="CDEEEGGI" name="CDEEEGGI"></a><a id="OTLCG94344" name="OTLCG94344"></a>
<div class="sect3">
<h3 class="sect3"><font face="arial, helvetica, sans-serif" color="#330099">Descriptor</font></h3>
<p>You can configure how object changes are broadcast on a descriptor-by-descriptor basis. This lets you fine-tune the type of notification to make.</p>
<p>For example, for an object with few attributes, you can configure its descriptor to send object changes. For an object with many attributes, it may be more efficient to configure its descriptor so that the object is flagged as invalid (so that other sessions will know to update the object from the data source the next time it is read).</p>
</div>
<!-- class="sect3" -->
<a id="CDEIFIED" name="CDEIFIED"></a><a id="OTLCG94345" name="OTLCG94345"></a>
<div class="sect3">
<h3 class="sect3"><font face="arial, helvetica, sans-serif" color="#330099">Unit of Work</font></h3>
<p>Only changes committed by a unit of work are subject to propagation when cache coordination is enabled. The unit of work computes the appropriate change set based on the descriptor configuration of affected objects.</p>
</div>
<!-- class="sect3" --></div>
<!-- class="sect2" -->
<a id="CDEECFJH" name="CDEECFJH"></a><a id="OTLCG94346" name="OTLCG94346"></a>
<div class="sect2">
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Coordinated Cache Types</font></h2>
<p>You can configure a coordinated cache to broadcast changes using any of the following communication protocols:</p>
<ul>
<li>
<p><a href="#CDEJABGH">JMS Coordinated Cache</a></p>
</li>
<li>
<p><a href="#CDEGHFJA">RMI Coordinated Cache</a></p>
</li>
</ul>
<a id="CDEJABGH" name="CDEJABGH"></a><a id="OTLCG94347" name="OTLCG94347"></a>
<div class="sect3">
<h3 class="sect3"><font face="arial, helvetica, sans-serif" color="#330099">JMS Coordinated Cache</font></h3>
<p>For a JMS coordinated cache, when a particular session's coordinated cache starts up, it uses its JNDI naming service information to locate and create a connection to the JMS server. The coordinated cache is ready when all participating sessions are connected to the same topic on the same JMS server. At this point, sessions can start sending and receiving object change messages. You can then configure all sessions that are participating in the same coordinated cache with the same JMS and JNDI naming service information.</p>
<p>For more information on configuring JMS, see "Configuring JMS Cache Coordination Using Persistence Properties" in <em>Solutions Guide for EclipseLink</em>. See also your JMS provider's documentation.</p>
</div>
<!-- class="sect3" -->
<a id="CDEGHFJA" name="CDEGHFJA"></a><a id="OTLCG94348" name="OTLCG94348"></a>
<div class="sect3">
<h3 class="sect3"><font face="arial, helvetica, sans-serif" color="#330099">RMI Coordinated Cache</font></h3>
<p>For an RMI coordinated cache, when a particular session's coordinated cache starts up, the session binds its connection in its naming service (either an RMI registry or JNDI), creates an announcement message (that includes its own naming service information), and broadcasts the announcement to its multicast group. When a session that belongs to the same multicast group receives this announcement, it uses the naming service information in the announcement message to establish bidirectional connections with the newly announced session's coordinated cache. The coordinated cache is ready when all participating sessions are interconnected in this way, at which point sessions can start sending and receiving object change messages. You can then configure each session with naming information that identifies the host on which the session is deployed.</p>
<p>For more information, see "Configuring RMI Cache Coordination Using Persistence Properties" in <em>Solutions Guide for EclipseLink</em>.</p>
</div>
<!-- class="sect3" --></div>
<!-- class="sect2" -->
<a id="CDEECFJG" name="CDEECFJG"></a><a id="OTLCG94350" name="OTLCG94350"></a>
<div class="sect2">
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Custom Coordinated Cache</font></h2>
<p>Using the classes in <code>org.eclipse.persistence.sessions.coordination</code> package, you can define your own coordinated cache for custom solutions.</p>
</div>
<!-- class="sect2" -->
<a id="CDEGDGAA" name="CDEGDGAA"></a><a id="OTLCG94351" name="OTLCG94351"></a>
<div class="sect2"><!-- infolevel="all" infotype="General" -->
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Coordinated Cache and Clustering</font></h2>
<p>An application cluster is a set of middle tier server machines or VMs servicing requests for a single application, or set of applications. Multiple servers are used to increase the scalability of the application and/or to provide fault tolerance and high availability. Typically the same application will be deployed to all of the servers in the cluster and application requests will be load balanced across the set of servers. The application cluster will access a single database, or a database cluster. An application cluster may allow new servers to be added to increase scalability, and for servers to be removed such as for updates and servicing.</p>
<p>Application clusters can consist of Java EE servers, Web containers, or Java server applications.</p>
<p>EclipseLink can function in any clustered environment. The main issue in a clustered environment is utilizing a shared persistence unit (L2) cache. If you are using a shared cache (enabled by default in EclipseLink projects), then each server will maintain its own cache, and each caches data can get out of sync with the other servers and the database.</p>
<p>EclipseLink provides cache coordination in a clustered environment to ensure the servers caches are is sync.</p>
<p>There are also many other solutions to caching in a clustered environment, including:</p>
<ul>
<li>
<p>Disable the shared cache (through setting <code>@Cacheable(false)</code>, or <code>@Cache(isolation=ISOLATED</code>)).</p>
</li>
<li>
<p>Only cache read-only objects.</p>
</li>
<li>
<p>Set a cache invalidation timeout to reduce stale data.</p>
</li>
<li>
<p>Use refreshing on objects/queries when fresh data is required.</p>
</li>
<li>
<p>Use optimistic locking to ensure write consistency (writes on stale data will fail, and will automatically invalidate the cache).</p>
</li>
<li>
<p>Use database events to invalidate changed data in the cache (such as EclipseLink's support for Oracle Query Change Notification).</p>
</li>
</ul>
<p>Cache coordination enables a set of persistence units deployed to different servers in the cluster (or on the same server) to synchronize their changes. Cache coordination works by each persistence unit on each server in the cluster being able to broadcast notification of transactional object changes to the other persistence units in the cluster. EclipseLink supports cache coordination over RMI and JMS. The cache coordination framework is also extensible so other options could be developed.</p>
<p>Cache coordination works by broadcasting changes for each transaction to the other servers in the cluster. Each other server will receive the change notification, and either invalidate the changed objects in their cache, or update the cached objects state with the changes. Cache coordination occurs after the database commit, so only committed changes are broadcast.</p>
<p>Cache coordination greatly reduces to chance of an application getting stale data, but does not eliminate the possibility. Optimistic locking should still be used to ensure data integrity. Even in a single server application stale data is still possible within a persistence context unless pessimistic locking is used. Optimistic (or pessimistic) locking is always required to ensure data integrity in any multi-user system.</p>
</div>
<!-- class="sect2" --></div>
<!-- class="sect1" --></div>
<!-- class="ind" -->
<!-- Start Footer -->
<div class="footer">
<hr />
<table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%">
<col width="33%" />
<col width="*" />
<col width="33%" />
<tr>
<td valign="bottom">
<table class="navigation simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100" align="center">
<col width="*" />
<col width="48%" />
<col width="48%" />
<tr>
<td>&nbsp;</td>
<td align="center"><a href="cache011.htm"><img src="../../dcommon/images/larrow.png" alt="Previous" border="0" height="16" width="16" /></a></td>
<td align="center"><a href="queries.htm"><img src="../../dcommon/images/rarrow.png" alt="Next" border="0" height="16" width="16" /></a></td>
</tr>
</table>
</td>
<td align="center" width="34%"><a href="http://www.eclipse.org/eclipselink/" title="EclipseLink home"><img src="../../dcommon/images/ellogo.png" alt="EclipseLink" width="150" border="0" /></a><br />
<font size="-2">Copyright&nbsp;&copy;&nbsp;,&nbsp;Oracle&nbsp;and/or&nbsp;its&nbsp;affiliates.&nbsp;All&nbsp;rights&nbsp;reserved.</font> <a href="../../dcommon/html/cpyr.htm"><br />
<td valign="bottom" align="right">
<table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="225">
<tr>
<td>&nbsp;</td>
<td align="center" valign="top"><a href="toc.htm"><img src="../../dcommon/images/contents.png" alt="Go To Table Of Contents" border="0" height="16" width="16" /><br />
</td><td>&nbsp;</td><td align="center"><a href="../../" target="_top" class="external text" title="Search" rel="nofollow"><img src="../../dcommon/images/search.png" alt="Search" style="border:0;" /><br /><span class="mini"></span></a></td><td>&nbsp;</td><td align="center"><a href="../eclipselink_otlcg.pdf" title="PDF" target="_blank"><img src="../../dcommon/images/pdf_icon.png" style="padding-right:5px;border:0" alt="PDF"></a></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<!-- class="footer" -->
<div id="copyright">Copyright &copy; 2012 by The Eclipse Foundation under the <a href="http://www.eclipse.org/org/documents/epl-v10.php">Eclipse Public License (EPL)</a><br /> <script type="text/javascript">var LastUpdated = document.lastModified;document.writeln ("Updated: " + LastUpdated);</script> </div><!-- START: Analytics --><script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-1608008-2']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script><!-- END: Analytics --><!-- START: Sharethis --><script>var options={ "publisher": "e2fe9e07-fab6-4f84-83ea-0991b429842c", "position": "right", "ad": { "visible": false, "openDelay": 5, "closeDelay": 0}};var st_hover_widget = new sharethis.widgets.hoverbuttons(options);</script><!-- END: Sharethis --></body>
</html>