[jboss-user] [JBoss Cache: Core Edition] - Re: tx aware cache config issue

emmartins do-not-reply at jboss.com
Wed Jan 21 08:57:47 EST 2009


  | 
  |          public void begin() throws SystemException {
  | 		
  | 		Transaction tx = getTransaction();
  | 		
  | 		// check there is no transaction
  | 		if (tx != null) {
  | 			throw new SystemException("Transaction already started, cannot nest tx. Ongoing Tx: "+ tx);			
  | 		} 
  | 		
  | 		// begin transaction
  | 		try {
  | 			transactionManager.begin();
  | 		} catch (NotSupportedException e) {				
  | 			throw new SystemException("Failed to begin transaction." + e);
  | 		}
  | 		
  | 		tx = getTransaction();
  | 		
  | 		if (logger.isDebugEnabled()) {
  | 			logger.debug("Transaction started: "+tx);
  | 		}	
  | 
  | 		// register for call-backs
  | 		try {
  | 			tx.registerSynchronization(new SynchronizationHandler(tx));
  | 		} catch (RollbackException e) {
  | 			throw new SystemException("Unable to register listener for created transaction. Error: "+e.getMessage());
  | 		}
  | 	}
  | 
  |         public void commit() throws SystemException {
  | 		
  | 		Transaction tx = getTransaction();
  | 
  | 		if (tx == null) {
  | 			throw new SystemException(
  | 					"Failed to commit transaction since there is no transaction to commit!");
  | 		}
  | 
  | 		if (getRollbackOnly()) {
  | 			if (logger.isDebugEnabled())
  | 				logger
  | 						.debug("Transaction marked for roll back, cannot commit, ending with rollback: "
  | 								+ tx);
  | 			rollback();
  | 		} else if (tx.getStatus() == Status.STATUS_ACTIVE) {
  | 			try {
  | 				transactionManager.commit();
  | 				if (logger.isDebugEnabled())
  | 					logger.debug("Committed tx "+tx);
  | 			} catch (Exception e) {
  | 				throw new SystemException("Failed to commit tx " + tx + ". Error: "
  | 						+ e.getMessage());
  | 			}
  | 		} else {
  | 			throw new SystemException(
  | 					"Failed to commit transaction "+tx+" since state is "
  | 							+ tx.getStatus());
  | 		}
  | 	}
  | 
  | 
  | 	public boolean getRollbackOnly() throws SystemException {
  | 		
  | 		Transaction tx = getTransaction();
  | 		
  | 		if (tx == null) {
  | 			throw new SystemException("no transaction");
  | 		}
  | 		
  | 		return tx.getStatus() == Status.STATUS_MARKED_ROLLBACK;
  | 	}
  | 
  | 	public Transaction getTransaction() {
  | 		
  | 		if (transactionManager != null) {
  | 			try {
  | 				return transactionManager.getTransaction();
  | 			} catch (SystemException e) {
  | 				throw new RuntimeException(
  | 						"Failed to obtain active JTA transaction");
  | 			}
  | 		}
  | 		else {
  | 			throw new RuntimeException("tx manager unavailable");
  | 		}
  | 	}
  | 
  | 
  | 	public void rollback() throws SystemException {
  | 		
  | 		Transaction tx = getTransaction();
  | 		
  | 		if (tx == null) {
  | 			throw new SystemException(
  | 					"Failed to rollback transaction since there is no transaction to rollback!");
  | 		}
  | 
  | 		if (!((tx.getStatus() != Status.STATUS_ACTIVE) || (tx.getStatus() != Status.STATUS_MARKED_ROLLBACK))) {
  | 			throw new SystemException(
  | 					"Failed to rollback transaction since transaction is in state: "
  | 							+ tx.getStatus());
  | 		}
  | 
  | 		transactionManager.rollback();
  | 
  | 		if (logger.isDebugEnabled()) {
  | 			logger.debug("Rollbacked tx "+tx);
  | 		}
  | 	}
  | 
  | 	public void setRollbackOnly() throws SystemException {
  | 		
  | 		if (transactionManager != null) {
  | 			transactionManager.setRollbackOnly();
  | 			if (logger.isDebugEnabled())
  | 				logger.debug("rollbackonly set on tx "
  | 						+ getTransaction());
  | 		}
  | 		else {
  | 			throw new SystemException("tx manager unavailable");
  | 		}			
  | 	}
  | 
  | 

The methods just delegate to JTA Tx Manager, in this case the RealTransactionManager bean from JBossAS 5.

Debug logs with 3.0.2.GA:


  | 13:39:46,655 DEBUG [InterceptorChain] Interceptor chain is: InterceptorChain{
  | 	>> org.jboss.cache.interceptors.CallInterceptor
  | 	>> org.jboss.cache.interceptors.MVCCLockingInterceptor
  | 	>> org.jboss.cache.interceptors.NotificationInterceptor
  | 	>> org.jboss.cache.interceptors.TxInterceptor
  | 	>> org.jboss.cache.interceptors.CacheMgmtInterceptor
  | 	>> org.jboss.cache.interceptors.InvocationContextInterceptor
  | }
  | 13:39:46,655 DEBUG [RegionManagerImpl] Not using an EvictionPolicy
  | 13:39:46,679 DEBUG [VersionAwareMarshaller] Started with version 3.0.2 and versionInt 30
  | 13:39:46,679 DEBUG [VersionAwareMarshaller] Using default marshaller class class org.jboss.cache.marshall.CacheMarshaller300
  | 13:39:46,679 DEBUG [DataContainerImpl] Setting rootInternal to UnversionedNode[ /]
  | 13:39:46,707 DEBUG [JmxRegistrationManager] Base name is: jboss.cache:service=JBossCache,uniqueId=69b249
  | 13:39:46,735 INFO  [PlatformMBeanServerRegistration] JBossCache MBeans were successfully registered to the platform mbean server.
  | 13:39:46,737 DEBUG [RPCManagerImpl] cache mode is local, will not create the channel
  | 13:39:46,737 INFO  [ComponentRegistry] JBoss Cache version: JBossCache 'Naga' 3.0.2.GA
  | 13:39:46,761 DEBUG [SleeTransactionManagerImpl] Transaction started: TransactionImple < ac, BasicAction: -53e0fec0:d852:4977259f:9 status: ActionStatus.RUNNING >
  | 13:39:46,764 DEBUG [SleeTransactionManagerImpl] rollbackonly set on tx TransactionImple < ac, BasicAction: -53e0fec0:d852:4977259f:9 status: ActionStatus.ABORT_ONLY >
  | 13:39:46,772 DEBUG [SleeTransactionManagerImpl] Transaction marked for roll back, cannot commit, ending with rollback: TransactionImple < ac, BasicAction: -53e0fec0:d852:4977259f:9 status: ActionStatus.ABORT_ONLY >
  | 13:39:46,773 DEBUG [SleeTransactionManagerImpl] Rollbacked tx TransactionImple < ac, BasicAction: -53e0fec0:d852:4977259f:9 status: ActionStatus.ABORTED >
  | 13:39:46,773 DEBUG [SleeTransactionManagerImpl] Transaction started: TransactionImple < ac, BasicAction: -53e0fec0:d852:4977259f:b status: ActionStatus.RUNNING >
  | 13:39:46,786 INFO  [SleeTransactionManagerImpl] BIGGGGGGGGGGGGGGG ISSSSSSSSSSSSSSSSSSSSUEEEEEEEEEE
  | 13:39:46,787 DEBUG [SleeTransactionManagerImpl] beforeCompletion for tx TransactionImple < ac, BasicAction: -53e0fec0:d852:4977259f:b status: ActionStatus.RUNNING >
  | 13:39:46,787 DEBUG [SleeTransactionManagerImpl] Committed tx TransactionImple < ac, BasicAction: -53e0fec0:d852:4977259f:b status: ActionStatus.COMMITTED >
  | 

Another failing similar scenario:


  | Fqn fqn = Fqn.fromElements("short test");
  | 			Object key = new Object();
  | 			Object value = new Object();			
  | 			try {
  | 				begin();
  | 				cache.getRoot().addChild(fqn);
  | 				commit();
  | 				begin();
  | 				setRollbackOnly();	
  | 				cache.getRoot().getChild(fqn).put(key, value);							
  | 				rollback();
  | 				begin();
  | 				if (cache.getRoot().getChild(fqn).get(key) != null) {
  | 					logger.info("BIGGGGGGGGGGGGGGG ISSSSSSSSSSSSSSSSSSSSUEEEEEEEEEE");
  | 				}
  | 				commit();
  | 			}
  | 			catch (Exception e) {
  | 				logger.error(e.getMessage(),e);
  | 			}
  | 

And its debug logs with 3.0.2.GA:


  | 13:54:48,123 DEBUG [DataContainerImpl] Setting rootInternal to NodeReference{delegate=UnversionedNode[ /]}
  | 13:54:48,149 DEBUG [InterceptorChain] Interceptor chain is: InterceptorChain{
  | 	>> org.jboss.cache.interceptors.CallInterceptor
  | 	>> org.jboss.cache.interceptors.MVCCLockingInterceptor
  | 	>> org.jboss.cache.interceptors.NotificationInterceptor
  | 	>> org.jboss.cache.interceptors.TxInterceptor
  | 	>> org.jboss.cache.interceptors.CacheMgmtInterceptor
  | 	>> org.jboss.cache.interceptors.InvocationContextInterceptor
  | }
  | 13:54:48,149 DEBUG [RegionManagerImpl] Not using an EvictionPolicy
  | 13:54:48,171 DEBUG [VersionAwareMarshaller] Started with version 3.0.2 and versionInt 30
  | 13:54:48,171 DEBUG [VersionAwareMarshaller] Using default marshaller class class org.jboss.cache.marshall.CacheMarshaller300
  | 13:54:48,171 DEBUG [DataContainerImpl] Setting rootInternal to UnversionedNode[ /]
  | 13:54:48,197 DEBUG [JmxRegistrationManager] Base name is: jboss.cache:service=JBossCache,uniqueId=8163c
  | 13:54:48,224 INFO  [PlatformMBeanServerRegistration] JBossCache MBeans were successfully registered to the platform mbean server.
  | 13:54:48,225 DEBUG [RPCManagerImpl] cache mode is local, will not create the channel
  | 13:54:48,225 INFO  [ComponentRegistry] JBoss Cache version: JBossCache 'Naga' 3.0.2.GA
  | 13:54:48,240 DEBUG [SleeTransactionManagerImpl] Transaction started: TransactionImple < ac, BasicAction: -53e0fec0:d8d2:49772925:9 status: ActionStatus.RUNNING >
  | 13:54:48,268 DEBUG [SleeTransactionManagerImpl] beforeCompletion for tx TransactionImple < ac, BasicAction: -53e0fec0:d8d2:49772925:9 status: ActionStatus.RUNNING >
  | 13:54:48,269 DEBUG [SleeTransactionManagerImpl] Committed tx TransactionImple < ac, BasicAction: -53e0fec0:d8d2:49772925:9 status: ActionStatus.COMMITTED >
  | 13:54:48,274 DEBUG [SleeTransactionManagerImpl] Transaction started: TransactionImple < ac, BasicAction: -53e0fec0:d8d2:49772925:c status: ActionStatus.RUNNING >
  | 13:54:48,274 DEBUG [SleeTransactionManagerImpl] rollbackonly set on tx TransactionImple < ac, BasicAction: -53e0fec0:d8d2:49772925:c status: ActionStatus.ABORT_ONLY >
  | 13:54:48,274 WARN  [TransactionTable] status is 1 (not ACTIVE or PREPARING); returning null)
  | 13:54:48,275 DEBUG [SleeTransactionManagerImpl] Rollbacked tx TransactionImple < ac, BasicAction: -53e0fec0:d8d2:49772925:c status: ActionStatus.ABORTED >
  | 13:54:48,275 DEBUG [SleeTransactionManagerImpl] Transaction started: TransactionImple < ac, BasicAction: -53e0fec0:d8d2:49772925:e status: ActionStatus.RUNNING >
  | 13:54:48,276 INFO  [SleeTransactionManagerImpl] BIGGGGGGGGGGGGGGG ISSSSSSSSSSSSSSSSSSSSUEEEEEEEEEE
  | 13:54:48,276 DEBUG [SleeTransactionManagerImpl] beforeCompletion for tx TransactionImple < ac, BasicAction: -53e0fec0:d8d2:49772925:e status: ActionStatus.RUNNING >
  | 13:54:48,276 DEBUG [SleeTransactionManagerImpl] Committed tx TransactionImple < ac, BasicAction: -53e0fec0:d8d2:49772925:e status: ActionStatus.COMMITTED >
  | 

Btw, same behavior with 3.0.1.GA

Configuration is pretty much default:


  | <!-- JBOSS CACHE 3 -->
  | 	
  |    <bean name="MobicentsCacheConfig" class="org.jboss.cache.config.Configuration">        
  |       <property name="runtimeConfig">
  |          <bean name="MobicentsCacheRuntimeConfig" class="org.jboss.cache.config.RuntimeConfig">
  |             <property name="transactionManager">
  |                <inject bean="RealTransactionManager"/>
  |             </property>
  |          </bean>
  |       </property>
  |    </bean>
  | 
  |    <!-- Factory to build the Cache. -->
  |    <bean name="MobicentsCacheFactory" class="org.jboss.cache.DefaultCacheFactory">      
  |       <constructor factoryClass="org.jboss.cache.DefaultCacheFactory" factoryMethod="getInstance" />
  |    </bean>  
  | 
  |    <!-- The cache itself -->
  |    <bean name="MobicentsCache" class="org.jboss.cache.Cache">
  |       <constructor factoryMethod="createCache">
  |           <factory bean="MobicentsCacheFactory"/>
  |           <parameter class="org.jboss.cache.config.Configuration"><inject bean="MobicentsCacheConfig"/></parameter>
  |           <parameter class="boolean">false</parameter>
  |       </constructor>
  |    </bean>
  | 

--Eduardo

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4203640#4203640

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4203640



More information about the jboss-user mailing list