Renamed RetryingTransaction to RetryingTransactionHelper, HibernateRetryingTransaction

to HibernateRetryingTransactionHelper.  Changed propagation mode of AVM transactions to
PROPAGATION_REQUIRED and tweaked to not retry in a transaction that wasn't started
locally.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3389 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-07-24 15:26:27 +00:00
parent 7af823d992
commit e5214a5d42
6 changed files with 23 additions and 15 deletions

View File

@@ -211,7 +211,7 @@
<bean id="readTransactionDefinition" <bean id="readTransactionDefinition"
class="org.springframework.transaction.support.DefaultTransactionDefinition"> class="org.springframework.transaction.support.DefaultTransactionDefinition">
<property name="propagationBehaviorName"> <property name="propagationBehaviorName">
<value>PROPAGATION_REQUIRES_NEW</value> <value>PROPAGATION_REQUIRED</value>
</property> </property>
<property name="isolationLevelName"> <property name="isolationLevelName">
<value>ISOLATION_READ_COMMITTED</value> <value>ISOLATION_READ_COMMITTED</value>
@@ -225,7 +225,7 @@
<bean id="writeTransactionDefinition" <bean id="writeTransactionDefinition"
class="org.springframework.transaction.support.DefaultTransactionDefinition"> class="org.springframework.transaction.support.DefaultTransactionDefinition">
<property name="propagationBehaviorName"> <property name="propagationBehaviorName">
<value>PROPAGATION_REQUIRES_NEW</value> <value>PROPAGATION_REQUIRED</value>
</property> </property>
<property name="isolationLevelName"> <property name="isolationLevelName">
<value>ISOLATION_READ_COMMITTED</value> <value>ISOLATION_READ_COMMITTED</value>
@@ -237,7 +237,7 @@
<!-- The Hibernate Transaction wrapper. --> <!-- The Hibernate Transaction wrapper. -->
<bean id="retryingTransaction" <bean id="retryingTransaction"
class="org.alfresco.repo.avm.HibernateRetryingTransaction"> class="org.alfresco.repo.avm.HibernateRetryingTransactionHelper">
<property name="sessionFactory"> <property name="sessionFactory">
<ref bean="sessionFactory"/> <ref bean="sessionFactory"/>
</property> </property>

View File

@@ -44,7 +44,7 @@ class AVMServiceImpl implements AVMService
/** /**
* The RetryingTransaction. * The RetryingTransaction.
*/ */
private RetryingTransaction fTransaction; private RetryingTransactionHelper fTransaction;
/** /**
* The AVMRepository for each service thread. * The AVMRepository for each service thread.
@@ -94,7 +94,7 @@ class AVMServiceImpl implements AVMService
* Set the Retrying Transaction wrapper. * Set the Retrying Transaction wrapper.
* @param txn * @param txn
*/ */
public void setRetryingTransaction(RetryingTransaction txn) public void setRetryingTransaction(RetryingTransactionHelper txn)
{ {
fTransaction = txn; fTransaction = txn;
} }

View File

@@ -26,16 +26,15 @@ import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.orm.hibernate3.HibernateTemplate; import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionException;
import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.TransactionStatus;
/** /**
* Helper for DAOs. * Helper for DAOs.
* @author britt * @author britt
*/ */
class HibernateRetryingTransaction extends HibernateTemplate implements RetryingTransaction class HibernateRetryingTransactionHelper extends HibernateTemplate implements RetryingTransactionHelper
{ {
private static Logger fgLogger = Logger.getLogger(HibernateRetryingTransaction.class); private static Logger fgLogger = Logger.getLogger(HibernateRetryingTransactionHelper.class);
/** /**
* The transaction manager. * The transaction manager.
@@ -61,7 +60,7 @@ class HibernateRetryingTransaction extends HibernateTemplate implements Retrying
* Make one up. * Make one up.
* @param sessionFactory The SessionFactory. * @param sessionFactory The SessionFactory.
*/ */
HibernateRetryingTransaction() HibernateRetryingTransactionHelper()
{ {
fRandom = new Random(); fRandom = new Random();
} }
@@ -77,12 +76,17 @@ class HibernateRetryingTransaction extends HibernateTemplate implements Retrying
while (true) while (true)
{ {
TransactionStatus status = null; TransactionStatus status = null;
boolean newTxn = true;
try try
{ {
status = status =
fTransactionManager.getTransaction(write ? fWriteDefinition : fReadDefinition); fTransactionManager.getTransaction(write ? fWriteDefinition : fReadDefinition);
newTxn = status.isNewTransaction();
execute(new HibernateCallbackWrapper(callback)); execute(new HibernateCallbackWrapper(callback));
if (newTxn)
{
fTransactionManager.commit(status); fTransactionManager.commit(status);
}
return; return;
} }
catch (Throwable t) catch (Throwable t)
@@ -96,6 +100,10 @@ class HibernateRetryingTransaction extends HibernateTemplate implements Retrying
{ {
fTransactionManager.rollback(status); fTransactionManager.rollback(status);
} }
if (!newTxn)
{
throw new AVMException("Unrecoverable error.", t);
}
// If we've lost a race or we've deadlocked, retry. // If we've lost a race or we've deadlocked, retry.
if (t instanceof DeadlockLoserDataAccessException) if (t instanceof DeadlockLoserDataAccessException)
{ {

View File

@@ -36,7 +36,7 @@ class Issuer
/** /**
* The transactional wrapper. * The transactional wrapper.
*/ */
private RetryingTransaction fTransaction; private RetryingTransactionHelper fTransaction;
/** /**
* Default constructor. * Default constructor.
@@ -58,7 +58,7 @@ class Issuer
* Set the transactional wrapper. * Set the transactional wrapper.
* @param retryingTransaction The transactional wrapper. * @param retryingTransaction The transactional wrapper.
*/ */
public void setRetryingTransaction(RetryingTransaction retryingTransaction) public void setRetryingTransaction(RetryingTransactionHelper retryingTransaction)
{ {
fTransaction = retryingTransaction; fTransaction = retryingTransaction;
} }

View File

@@ -33,7 +33,7 @@ class OrphanReaper implements Runnable
/** /**
* The HibernateTxn instance. * The HibernateTxn instance.
*/ */
private RetryingTransaction fTransaction; private RetryingTransactionHelper fTransaction;
/** /**
* Inactive base sleep interval. * Inactive base sleep interval.
@@ -111,7 +111,7 @@ class OrphanReaper implements Runnable
* Set the Hibernate Transaction Wrapper. * Set the Hibernate Transaction Wrapper.
* @param transaction * @param transaction
*/ */
public void setRetryingTransaction(RetryingTransaction transaction) public void setRetryingTransaction(RetryingTransactionHelper transaction)
{ {
fTransaction = transaction; fTransaction = transaction;
} }

View File

@@ -6,7 +6,7 @@ package org.alfresco.repo.avm;
* when a transaction fails for synchronization reasons. * when a transaction fails for synchronization reasons.
* @author britt * @author britt
*/ */
interface RetryingTransaction interface RetryingTransactionHelper
{ {
/** /**
* Perform a set of operations under a single transaction. * Perform a set of operations under a single transaction.