Question

I am trying to do some bench-marking of Distributed transaction memory using Terracotta Ehcache (Open Source). I am having some problem understanding its working with JTA. In code I have found that cache interested in a Distributed Transaction enlist itself as a resource with JTA on which JTA later executes the two phase commit.

My question is if only one cache is enlisted as a resource, how JTA will be able to update all other caches atomically in distributed settings? We are not passing other caches reference to JTA, so atomically update will not be done on them. I feel, I am missing some string here, can anyone explain how it works? I am new to J2EE too, am I missing some J2EE concept which allow automatic reference passing of other caches to JTA?

Was it helpful?

Solution

Ehcache, if configured that way (transactionalMode="xa" or transactionalMode="xa_strict"), can work as a full XAResource to participate in JTA transactions (global transactions), which is controlled by a Transaction Manager (from your application server or some standalone product). Ehcache itself takes care of registering at the Transaction Manager in this case. Also, as a full XAResource, multiple caches can be registered and can be part of a transaction.

Strong, cluster-wide consistency is quite expensive (there is no free lunch). It boils down using locks and synchronous (network) operations involving waits, acknowledging etc.

For a more detailed read, I'd suggest you to consult Ehcache docs: Transactions in Ehcache

OTHER TIPS

Each cache configured with transactionalMode="xa_strict" and updated within a JTA transaction will register itself as an XAResource to the transaction manager. This is all automated and transparent to the end user, you don't have anything special at all to do for this mechanism to kick in, you just have to use your cache inside a JTA beg

If you also happen to access other, non-transactional caches in the JTA transaction context, those won't be part of the transaction and will simply be updated as soon as you modify them.

Tried xa_strict but there seems to be no automatic enlistment of the XAResource? Switching to plain xa works though...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top