Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (4.3/Cloud)

73348: Merged V4.2-BUG-FIX (4.2.3) to HEAD-BUG-FIX (4.3/Cloud)
      73162: Merged V4.1-BUG-FIX (4.1.10) to V4.2-BUG-FIX (4.2.3)
         73054: Added LockDAO.releaseLockQuiet and used it for the callback's precautionary lock release
          - Fixes MNT-11507: JobLockService automatic refresh is triggering a retry under normal conditions
          - Prevents a DEBUG message from RetryingTransactionInterceptor when the normal condition is for
            the lock to no longer exist


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@74766 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Will Abson
2014-06-25 15:58:39 +00:00
parent d7695471f8
commit 73d5ddfb3d
4 changed files with 66 additions and 9 deletions

View File

@@ -136,6 +136,7 @@ public class JobLockServiceImpl implements JobLockService
/**
* {@inheritDoc}
*/
@Override
public void getTransactionalLock(QName lockQName, long timeToLive)
{
getTransactionalLock(lockQName, timeToLive, defaultRetryWait, defaultRetryCount);
@@ -144,6 +145,7 @@ public class JobLockServiceImpl implements JobLockService
/**
* {@inheritDoc}
*/
@Override
public void getTransactionalLock(QName lockQName, long timeToLive, long retryWait, int retryCount)
{
// Check that transaction is present
@@ -204,6 +206,7 @@ public class JobLockServiceImpl implements JobLockService
*
* @see #getLock(QName, long, long, int)
*/
@Override
public String getLock(QName lockQName, long timeToLive)
{
return getLock(lockQName, timeToLive, defaultRetryWait, defaultRetryCount);
@@ -212,6 +215,7 @@ public class JobLockServiceImpl implements JobLockService
/**
* {@inheritDoc}
*/
@Override
public String getLock(QName lockQName, long timeToLive, long retryWait, int retryCount)
{
String lockToken = GUID.generate();
@@ -225,6 +229,7 @@ public class JobLockServiceImpl implements JobLockService
*
* @throws LockAcquisitionException on failure
*/
@Override
public void refreshLock(final String lockToken, final QName lockQName, final long timeToLive)
{
RetryingTransactionCallback<Object> refreshLockCallback = new RetryingTransactionCallback<Object>()
@@ -347,16 +352,13 @@ public class JobLockServiceImpl implements JobLockService
}
// The callback is no longer active, so we don't need to refresh.
// Release the lock in case the initiator did not do it.
try
// We just want to release and don't care if the lock was already released
// or taken by another process
if (releaseLockQuiet(lockToken, lockQName))
{
releaseLock(lockToken, lockQName);
// The callback must be informed as we released the lock automatically
callLockReleased(callback);
}
catch (LockAcquisitionException e)
{
// The lock is already gone: job done
}
}
else
{
@@ -419,6 +421,7 @@ public class JobLockServiceImpl implements JobLockService
/**
* {@inheritDoc}
*/
@Override
public void releaseLock(final String lockToken, final QName lockQName)
{
releaseLockVerify(lockToken, lockQName);
@@ -439,6 +442,27 @@ public class JobLockServiceImpl implements JobLockService
return retryingTransactionHelper.doInTransaction(releaseCallback, false, true);
}
/**
* Attempt to release a lock but do not worry about not being able to update the lock.
* If the lock was taken by another process, then it will not matter. Any other database-related
* conditions will still trigger a retry.
*
* @param lockToken the unique lock token to release (expired or not)
* @param lockQName the name of the lock
* @return <tt>true</tt> if the lock was released or <tt>false</tt> if not
*/
private boolean releaseLockQuiet(final String lockToken, final QName lockQName)
{
RetryingTransactionCallback<Boolean> releaseCallback = new RetryingTransactionCallback<Boolean>()
{
public Boolean execute() throws Throwable
{
return lockDAO.releaseLockQuiet(lockQName, lockToken);
}
};
return retryingTransactionHelper.doInTransaction(releaseCallback, false, true);
}
/**
* @throws LockAcquisitionException on failure
*/