0 Replies Latest reply on Aug 23, 2013 9:44 AM by Evgeny Nacu

    Transaction isolation seems to not work. pls, help

    Evgeny Nacu Newbie

      Hi everyone!

        We are using Infinispan as 2LC with Hibernate. We have some processes using this configuration (2 tomcats and backend - spring based app)

        Exact versions are: Hibernate - 4.2.2

        Infinispan - 5.3.0

       

      We have such situation:

        Backend process gathers and creates some data. There is long-running read-only transaction and many short transactions (using REQUIRES_NEW)

       

      Some other thread in the same process generates files. And this process sometimes fails with such Exception:

      org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [site.domain.Backlink#833026]

              at org.hibernate.internal.SessionFactoryImpl$1$1.handleEntityNotFound(SessionFactoryImpl.java:244)

              at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:212)

              at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:246)

              at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:150)

              at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1092)

              at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1019)

              at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:672)

              at org.hibernate.type.ManyToOneType.assemble(ManyToOneType.java:280)

              at org.hibernate.type.TypeHelper.assemble(TypeHelper.java:113)

              at org.hibernate.cache.spi.entry.StandardCacheEntryImpl.assemble(StandardCacheEntryImpl.java:138)

              at org.hibernate.cache.spi.entry.StandardCacheEntryImpl.assemble(StandardCacheEntryImpl.java:126)

              at org.hibernate.event.internal.DefaultLoadEventListener.convertCacheEntryToEntity(DefaultLoadEventListener.java:643)

              at org.hibernate.event.internal.DefaultLoadEventListener.loadFromSecondLevelCache(DefaultLoadEventListener.java:571)

              at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:421)

              at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:206)

              at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:246)

              at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:150)

              at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1092)

              at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1019)

              at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:672)

              at org.hibernate.type.ManyToOneType.assemble(ManyToOneType.java:280)

              at org.hibernate.collection.internal.PersistentBag.initializeFromCache(PersistentBag.java:160)

              at org.hibernate.cache.spi.entry.CollectionCacheEntry.assemble(CollectionCacheEntry.java:57)

              at org.hibernate.event.internal.DefaultInitializeCollectionEventListener.initializeCollectionFromCache(DefaultInitializeCollectionEventListener.java:148)

              at org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:69)

              at org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1849)

              at org.hibernate.collection.internal.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:681)

              at org.hibernate.engine.internal.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:1030)

              at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:346)

              at org.hibernate.loader.Loader.doList(Loader.java:2522)

              at org.hibernate.loader.Loader.doList(Loader.java:2508)

              at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2338)

              at org.hibernate.loader.Loader.list(Loader.java:2333)

              at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:124)

              at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1662)

              at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:374)

              at site.db.hibernate.AbstractPropertyDBObjectHibernateDao.exportExcludeRegion(AbstractPropertyDBObjectHibernateDao.java:304)

              at site.db.hibernate.AbstractPropertyDBObjectHibernateDao$$FastClassByCGLIB$$18c96b39.invoke(<generated>)

              at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)

              at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:618)

              at site.db.hibernate.PropertyDBObjectHibernateDao$$EnhancerByCGLIB$$5db047af.exportExcludeRegion(<generated>)

              at site.export.common.ExcludeRegionCommonExportProvider.doExport(ExcludeRegionCommonExportProvider.java:9)

              at site.export.common.CommonExportProvider.export(CommonExportProvider.java:47)

              at site.export.common.CommonExportProvider$$FastClassByCGLIB$$e7dac9a0.invoke(<generated>)

              at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)

       

      Backlink is created inside REQUIRES_NEW transaction.

      We think that transactional cache is not working the way it should be (We think links to new entities, Backlinks, are somehow stored in cache before transaction is commited. So, other transaction can't find these entities in the database)

       

      Here is our configuration.

      Hibernate:

       



      factoryBuilder.setProperty("hibernate.dialect","org.hibernate.dialect.MySQLInnoDBDialect");


      factoryBuilder.setProperty("hibernate.show_sql", showSql);


      factoryBuilder.setProperty("hibernate.cache.region.factory_class", secondLevelCache);


      factoryBuilder.setProperty("hibernate.cache.use_second_level_cache", ""+useSecondLevelCache);


      factoryBuilder.setProperty("hibernate.cache.use_query_cache",""+useQueryCache);


      factoryBuilder.setProperty("hibernate.default_schema", rebaseDBSchema);


      factoryBuilder.setProperty("hibernate.connection.zeroDateTimeBehavior", "convertToNull");


      factoryBuilder.setProperty("hibernate.cache.use_structured_entries", "false");


      factoryBuilder.setProperty("javax.persistence.validation.mode", "none");


      factoryBuilder.setProperty("hibernate.hbm2ddl.auto", "none");


      factoryBuilder.setProperty("hibernate.transaction.factory_class", "org.hibernate.transaction.JTATransactionFactory");


      factoryBuilder.setProperty("hibernate.transaction.jta.platform", "org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform");


      factoryBuilder.setProperty("hibernate.transaction.flush_before_completion", "false");


      factoryBuilder.setProperty("hibernate.transaction.auto_close_session", "false");


      factoryBuilder.setProperty("hibernate.cache.infinispan.cfg", INFINISPAN_XML);


      factoryBuilder.setProperty("hibernate.connection.autocommit", "false");

       

      infinispan.xml:

       

      <?xml version="1.0" encoding="UTF-8"?>

      <infinispan xmlns="urn:infinispan:config:5.2">

                <global>

                          <transport>

                                    <properties>

                                              <property name="configurationFile" value="jgroups.xml" />

                                    </properties>

                          </transport>

                          <asyncListenerExecutor factory="org.infinispan.executors.DefaultExecutorFactory">

                                    <properties>

                                              <property

                                                        name="threadNamePrefix"

                                                        value="AsyncTransportThread" />

                                    </properties>

                          </asyncListenerExecutor>

                          <asyncTransportExecutor factory="org.infinispan.executors.DefaultExecutorFactory">

                                    <properties>

                                              <property

                                                        name="threadNamePrefix"

                                                        value="AsyncListenerThread" />

                                    </properties>

                          </asyncTransportExecutor>

                          <evictionScheduledExecutor factory="org.infinispan.executors.DefaultScheduledExecutorFactory">

                                    <properties>

                                              <property

                                                        name="threadNamePrefix"

                                                        value="EvictionThread" />

                                    </properties>

                          </evictionScheduledExecutor>

                          <replicationQueueScheduledExecutor factory="org.infinispan.executors.DefaultScheduledExecutorFactory">

                                    <properties>

                                              <property

                                                        name="threadNamePrefix"

                                                        value="ReplicationQueueThread" />

                                    </properties>

                          </replicationQueueScheduledExecutor>

                          <shutdown hookBehavior="DEFAULT" />

                </global>

                <default>

                          <clustering mode="invalidation">

                                    <stateTransfer

                           timeout="240000"

                           fetchInMemoryState="false"

                           chunkSize="10000"

                        />

                                    <sync replTimeout="20000"/>

                          </clustering>

                          <locking concurrencyLevel="1000" useLockStriping="false" isolationLevel="REPEATABLE_READ" writeSkewCheck="false"/>

              <transaction

                      transactionManagerLookupClass="org.infinispan.transaction.lookup.JBossStandaloneJTAManagerLookup"

                      transactionMode="TRANSACTIONAL"

                      lockingMode="OPTIMISTIC"/>

          </default>

                <!-- manual caches -->

       

                ...some our caches...

       

       

                <!-- Hibernate caches -->

       

              ...some our caches...

       

       

                <namedCache name="org.hibernate.cache.spi.UpdateTimestampsCache">

                          <eviction maxEntries="1000000"/>

                          <clustering mode="replication">

                                    <stateTransfer

                           timeout="240000"

                           fetchInMemoryState="false"

                           chunkSize="10000"

                        />

                                    <async/>

                          </clustering>

                          <loaders preload="false">

                                    <loader class="org.infinispan.loaders.cluster.ClusterCacheLoader">

                                              <properties>

                                                        <property

                                                                  name="remoteCallTimeout"

                                                                  value="20000" />

                                              </properties>

                                    </loader>

                          </loaders>

                          <transaction transactionMode="NON_TRANSACTIONAL"/>

                </namedCache>

       

       

       

       

                <!-- hibernate defaults -->

                <namedCache name="timestamps">

                          <clustering mode="replication">

                                    <stateTransfer

                           timeout="240000"

                           fetchInMemoryState="false"

                           chunkSize="10000"

                        />

                                    <async/>

                          </clustering>

                          <loaders preload="false">

                                              <loader class="org.infinispan.loaders.cluster.ClusterCacheLoader">

                                                        <properties>

                                                                  <property

                                                                            name="remoteCallTimeout"

                                                                            value="20000" />

                                                        </properties>

                                              </loader>

                                    </loaders>

              <transaction transactionMode="NON_TRANSACTIONAL"/>

                </namedCache>

      </infinispan>

       

      Pls, if you have any suggestions or you need more information, let me know.

      Thanks