4 Replies Latest reply on Sep 23, 2008 7:40 AM by manik

    addNewSubtree method is not thread safe

    nimrod.gat

      I'm using JBoss cache 2.0.0.GA with multiple threads caching process.
      Sometimes, at the beginning of the process, the unique constraint of the table is violated even though each thread uses a unique id (log attached).

      Ive noticed that the first node added to the tree is the one creating the root node using addNewSubtree method which called from _put method, but the lock acquired in _put is from StripedLock which is FQN based lock what causing two different nodes to create the root node at the same time.

      StripedLock doesn't enough when creating the root node.

      a workaround is to create "dummy" node before multiple thread cache process.


      2008-08-11 02:26:53,698 WARN [com.arjuna.ats.arjuna.logging.arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_2] TwoPhaseCoordinator.beforeCompletion - failed for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple@1befb76d
      java.lang.IllegalStateException: Failed to insert node: ORA-00001: unique constraint (PFIZERMM2_4_HILLEL.JBOSSCACHE_APPLICATION_PK) violated
      
       at org.jboss.cache.loader.AdjListJDBCCacheLoader.insertNode(AdjListJDBCCacheLoader.java:490)
       at org.jboss.cache.loader.JDBCCacheLoader.addNewSubtree(JDBCCacheLoader.java:220)
       at org.jboss.cache.loader.JDBCCacheLoader._put(JDBCCacheLoader.java:188)
       at org.jboss.cache.loader.JDBCCacheLoader.put(JDBCCacheLoader.java:79)
       at org.jboss.cache.loader.AbstractCacheLoader.put(AbstractCacheLoader.java:233)
       at org.jboss.cache.loader.AdjListJDBCCacheLoader.prepare(AdjListJDBCCacheLoader.java:189)
       at org.jboss.cache.interceptors.CacheStoreInterceptor.prepareCacheLoader(CacheStoreInterceptor.java:330)
       at org.jboss.cache.interceptors.CacheStoreInterceptor.invoke(CacheStoreInterceptor.java:144)
       at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:76)
       at org.jboss.cache.interceptors.CacheLoaderInterceptor.invoke(CacheLoaderInterceptor.java:160)
       at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:76)
       at org.jboss.cache.interceptors.UnlockInterceptor.invoke(UnlockInterceptor.java:37)
       at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:76)
       at org.jboss.cache.interceptors.PessimisticLockInterceptor.invoke(PessimisticLockInterceptor.java:203)
       at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:76)
       at org.jboss.cache.interceptors.NotificationInterceptor.invoke(NotificationInterceptor.java:32)
       at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:76)
       at org.jboss.cache.interceptors.TxInterceptor.runPreparePhase(TxInterceptor.java:833)
       at org.jboss.cache.interceptors.TxInterceptor$LocalSynchronizationHandler.beforeCompletion(TxInterceptor.java:1154)
       at org.jboss.cache.interceptors.OrderedSynchronizationHandler.beforeCompletion(OrderedSynchronizationHandler.java:84)
       at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:114)
       at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:247)
       at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:86)
       at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
       at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1389)
       at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
       at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
       at org.jboss.resource.adapter.jms.inflow.JmsServerSession$XATransactionDemarcationStrategy.end(JmsServerSession.java:494)
       at org.jboss.resource.adapter.jms.inflow.JmsServerSession.run(JmsServerSession.java:248)
       at org.jboss.resource.work.WorkWrapper.execute(WorkWrapper.java:204)
       at org.jboss.util.threadpool.BasicTaskWrapper.run(BasicTaskWrapper.java:275)
       at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:756)
       at java.lang.Thread.run(Thread.java:619)
      Caused by: java.sql.SQLException: ORA-00001: unique constraint (PFIZERMM2_4_HILLEL.JBOSSCACHE_APPLICATION_PK) violated
      
       at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
       at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:305)
       at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:272)
       at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:626)
       at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:182)
       at oracle.jdbc.driver.T4CPreparedStatement.execute_for_rows(T4CPreparedStatement.java:630)
       at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1081)
       at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2905)
       at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:2977)
       at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:251)
       at org.jboss.cache.loader.AdjListJDBCCacheLoader.insertNode(AdjListJDBCCacheLoader.java:477)
       ... 32 more