0

We are experimenting with Apache Ignite to use it as a Read and Write through caching layer for Distributed applications. The need is to weave a cache layer for the aggregates we depend on. Indiviual constituent entities that these aggregates comprise of, are managed entities maintained by EntityManager. Two Questions:

  1. Does Apache Ignite participate in Container Managed Transaction out of box ?

  2. In order to understand solution to Q1 , I did a small experiment described below. Any insights on what induces below behaviour ?

Aggregates : Strategy and Strategy Parameter - one to many mapping. Individual Entities : Strategy and StrategyParam (both managed by JPA/Hibernate). CacheStore definition based on entitymanager : eg write method:

  @Override
public void write(Cache.Entry<? extends Long, ? extends StrategyAggregate> entry) throws CacheWriterException {
    em.merge(entry.getValue().getStrategy());
    entry.getValue().getStrategyParamList().forEach(strategyParam -> em.merge(strategyParam));
} 

Now when we init first node with above cache definition, I see the transaction nature working alright i.e. post method completion I see both cache and database updated i.e. I can read the changes from cache.

But as soon as second node joins the cluster, the same api throws up error "no entitymanager available ..." followed by stacktrace having transaction has been rolled back. Though Read from both cache and direct read from entity manager works fine.

Stacktrace

Caused by: javax.cache.integration.CacheWriterException: javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'merge' call ... 79 common frames omitted Caused by: javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'merge' call at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:285) ~[spring-orm-4.3.25.RELEASE.jar:4.3.25.RELEASE] at com.sun.proxy.$Proxy102.merge(Unknown Source) ~[na:na] at StrategyAggregateCacheStore.write(StrategyAggregateCacheStore.java:47) ~[classes/:na] at org.apache.ignite.internal.processors.cache.store.GridCacheStoreManagerAdapter.put(GridCacheStoreManagerAdapter.java:585) ~[ignite-core-2.11.0.jar:2.11.0] ... 78 common frames omitted

  • Ignite supports distributed transactions https://ignite.apache.org/docs/latest/key-value-api/transactions, but I don't think it has out-of-the-box support for something except JTA for https://ignite.apache.org/releases/latest/javadoc/org/apache/ignite/cache/jta/package-summary.html. btw, the mentioned exception seems to be related to the spring configuration. You probably confused some annotations as mentioned here - https://stackoverflow.com/questions/32269192/spring-no-entitymanager-with-actual-transaction-available-for-current-thread – Andrei Aleksandrov Sep 28 '21 at 12:47
  • @AndreiAleksandrov Missed tagging you in the comment above. – user3474840 Oct 04 '21 at 10:04
  • I created a small quickstart project with wildfly to test JTA setup with h2 database jdbc store. The behaviour I see is as below: Ignite tries to send database updates post CMT commit, any ideas what I need to do this to make ignite write through to database inline with the put operation on cache. Repo link : https://github.com/vikramp/ignite-test/tree/master/cmt Cache Initializer : https://github.com/vikramp/ignite-test/blob/master/cmt/src/main/java/org/jboss/as/quickstarts/cmt/cache/CacheInitializer.java – user3474840 Oct 12 '21 at 08:17
  • Ignite Documentation states that this should be inline see excerpt below "Write-through means that the data is automatically persisted when it is updated in the cache. All read-through and write-through operations participate in cache transactions and are committed or rolled back as a whole" – user3474840 Oct 12 '21 at 08:32

0 Answers0