Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/JPA/Basic JPA Development/Caching/Coordination"

(Clustering and Cache Coordination)
Line 42: Line 42:
  
 
Cache coordination is configured using persistence unit properties.  The following cache coordination properties are supported:
 
Cache coordination is configured using persistence unit properties.  The following cache coordination properties are supported:
 +
 +
{{EclipseLink_AttributeTable
 +
|caption=Cache Coordination Persistence Unit Properties
 +
|content=
 +
<tr>
 +
<td><tt>"eclipselink.cache.coordination.protocol"</tt></td>
 +
<td>Enable cache coordination using the communication protocol:
 +
* rmi - Use Java RMI to broadcast changes.
 +
* rmi-iiop - Use Java RMI over CORBA IIOP to broadcast changes.
 +
* jms - Use the Java Messaging Service to broadcast changes.
 +
* jms-publishing - Allows an EJB MessageDrivenBean to be used to broadcast changes.  The MDB must be configured separately.
 +
* <class-name> - The fully qualified class name of a custom implementation of a <code>TransportManager</code>.
 +
 +
</td>
 +
<td><tt>no coordination</tt></td>
 +
<td>Required</td>
 +
</tr>
 +
}}
  
  

Revision as of 14:31, 22 May 2012

EclipseLink JPA

Clustering and Cache Coordination

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.

Application clusters can consist of Java EE servers, web containers, or Java server applications.

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), then each server will maintain its own cache, and each caches data can get out of sync with the other servers and the database.

EclipseLink provides cache coordination in a clustered environment to ensure the servers caches are is sync.

There are also many other solutions to caching in a clustered environment, including:

  • Disable the shared cache (through setting @Cacheable(false), or @Cache(isolation=ISOLATED)).
  • Only cache read-only objects.
  • Set a cache invalidation timeout to reduce stale data.
  • Use refreshing on objects/queries when fresh data is required.
  • Use optimistic locking to ensure write consistency (writes on stale data will fail, and will automatically invalidate the cache).
  • Use a distributed cache (such as Oracle TopLink Grid's integration of EclipseLink with Oracle Coherence).
  • Use database events to invalidate changed data in the cache (such as EclipseLink's support for Oracle DCN/QCN).

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.

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.

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.

Cache coordination is configured using persistence unit properties. The following cache coordination properties are supported:

Cache Coordination Persistence Unit Properties
Attribute Description Default Required?
"eclipselink.cache.coordination.protocol" Enable cache coordination using the communication protocol:
  • rmi - Use Java RMI to broadcast changes.
  • rmi-iiop - Use Java RMI over CORBA IIOP to broadcast changes.
  • jms - Use the Java Messaging Service to broadcast changes.
  • jms-publishing - Allows an EJB MessageDrivenBean to be used to broadcast changes. The MDB must be configured separately.
  • <class-name> - The fully qualified class name of a custom implementation of a TransportManager.
no coordination Required


Eclipselink-logo.gif
Version: 2.4 DRAFT
Other versions...

Back to the top