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

@@ -175,6 +175,22 @@ public abstract class AbstractLockDAOImpl implements LockDAO
return updateLocks(lockQName, lockToken, LOCK_TOKEN_RELEASED, 0L, optimistic);
}
@Override
public boolean releaseLockQuiet(QName lockQName, String lockToken)
{
try
{
updateLocks(lockQName, lockToken, LOCK_TOKEN_RELEASED, 0L, false);
// It worked
return true;
}
catch (LockAcquisitionException e)
{
// We absorb this
return false;
}
}
/**
* Put new values against the given exclusive lock. This works against the related locks as well.
* @param optimistic <tt>true</tt> if a mismatch in the number of locked rows should

View File

@@ -71,11 +71,22 @@ public interface LockDAO
* @param lockToken the current lock token
* @param optimistic <tt>true</tt> if the release attempt is enough even
* if the number of released locks was incorrect.
* @return <tt>true</tt> if the lock was successfully (and completely)
* released or <tt>false</tt> if the lock was no longer valid
* <b>and the method was being called optimistically.</b>
* @return Returns <tt>true</tt> if all the required locks were
* (still) held under the lock token and were
* valid at the time of release, otherwise <tt>false</tt>
* @throws LockAcquisitionException if the number of locks released was incorrect
* and pessimistic release is requested.
*/
boolean releaseLock(QName lockQName, String lockToken, boolean optimistic);
/**
* Release a lock without throwing any exceptions if the lock was not updated.
*
* @param lockQName the unique name of the lock to release
* @param lockToken the current lock token
* @return Returns <tt>true</tt> if all the required locks were
* (still) held under the lock token and were
* valid at the time of release, otherwise <tt>false</tt>
*/
boolean releaseLockQuiet(QName lockQName, String lockToken);
}

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
*/