mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (4.3/Cloud)
73355: Merged V4.2-BUG-FIX (4.2.3) to HEAD-BUG-FIX (4.3/Cloud) 73281: Merged V4.1-BUG-FIX (4.1.10) to V4.2-BUG-FIX (4.2.3) 73054 (REDO MERGE): 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 73279: Fix javadoc for JobLockService.releaseLock to include @throws This revision undoes the behaviour change of JobLockService.releaseLock introduced by: 56164: Fixes ALF-19964: Breaking API change in JobLockService.releaseLock The JobLockService now behaves the same on 4.1.x and 4.2.x, while all bug fixes are preserved. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@74773 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -175,22 +175,6 @@ public abstract class AbstractLockDAOImpl implements LockDAO
|
|||||||
return updateLocks(lockQName, lockToken, LOCK_TOKEN_RELEASED, 0L, optimistic);
|
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.
|
* 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
|
* @param optimistic <tt>true</tt> if a mismatch in the number of locked rows should
|
||||||
|
@@ -30,7 +30,7 @@ import org.alfresco.service.namespace.QName;
|
|||||||
public interface LockDAO
|
public interface LockDAO
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Aquire a given exclusive lock, assigning it (and any implicitly shared locks) a
|
* Acquire a given exclusive lock, assigning it (and any implicitly shared locks) a
|
||||||
* timeout. All shared locks are implicitly taken as well.
|
* timeout. All shared locks are implicitly taken as well.
|
||||||
* <p>
|
* <p>
|
||||||
* A lock can be re-taken if it has expired and if the lock token has not changed
|
* A lock can be re-taken if it has expired and if the lock token has not changed
|
||||||
@@ -78,15 +78,4 @@ public interface LockDAO
|
|||||||
* and pessimistic release is requested.
|
* and pessimistic release is requested.
|
||||||
*/
|
*/
|
||||||
boolean releaseLock(QName lockQName, String lockToken, boolean optimistic);
|
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);
|
|
||||||
}
|
}
|
||||||
|
@@ -169,27 +169,23 @@ public interface JobLockService
|
|||||||
void refreshLock(String lockToken, QName lockQName, long timeToLive, JobLockRefreshCallback callback);
|
void refreshLock(String lockToken, QName lockQName, long timeToLive, JobLockRefreshCallback callback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Release the lock using a valid lock token. The lock can have expired or even been taken
|
* Release the lock using a valid lock token.
|
||||||
* by another processes (i.e. the lock token will no longer be valid); none of this will
|
|
||||||
* prevent the method from succeeding. This operation is functionally the same as the newer
|
|
||||||
* {@link #releaseLockVerify(String, QName)} operation, other than it returns void. Retained
|
|
||||||
* for backwards-compatibility.
|
|
||||||
*
|
*
|
||||||
* @param lockToken the lock token returned when the lock was acquired
|
* @param lockToken the lock token returned when the lock was acquired
|
||||||
* @param lockQName the name of the previously-acquired lock
|
* @param lockQName the name of the previously-acquired lock
|
||||||
|
* @throws LockAcquisitionException if the lock has been taken over by another process
|
||||||
*/
|
*/
|
||||||
void releaseLock(String lockToken, QName lockQName);
|
void releaseLock(String lockToken, QName lockQName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Release the lock using a valid lock token. The lock can have expired or even been taken
|
* Release the lock using a valid lock token. The lock can have been taken
|
||||||
* by another processes (i.e. the lock token will no longer be valid); none of this will
|
* by another process (i.e. the lock token will no longer be valid); none of this will
|
||||||
* prevent the method from succeeding. Functionally similar to {@link #releaseLock(String, QName)}, but
|
* prevent the method from succeeding.
|
||||||
* this newer operation indicates whether a lock was actually released by its return value.
|
|
||||||
*
|
*
|
||||||
* @param lockToken the lock token returned when the lock was acquired
|
* @param lockToken the lock token returned when the lock was acquired
|
||||||
* @param lockQName the name of the previously-acquired lock
|
* @param lockQName the name of the previously-acquired lock
|
||||||
* @return <tt>true</tt> if the lock was valid and released otherwise
|
* @return <tt>true</tt> if the lock was valid and released otherwise
|
||||||
* <tt>false</tt> if the lock was no longer valid in any case
|
* <tt>false</tt> if the lock was already held by another token
|
||||||
*/
|
*/
|
||||||
boolean releaseLockVerify(String lockToken, QName lockQName);
|
boolean releaseLockVerify(String lockToken, QName lockQName);
|
||||||
|
|
||||||
|
@@ -354,7 +354,7 @@ public class JobLockServiceImpl implements JobLockService
|
|||||||
// Release the lock in case the initiator did not do it.
|
// Release the lock in case the initiator did not do it.
|
||||||
// We just want to release and don't care if the lock was already released
|
// We just want to release and don't care if the lock was already released
|
||||||
// or taken by another process
|
// or taken by another process
|
||||||
if (releaseLockQuiet(lockToken, lockQName))
|
if (releaseLockVerify(lockToken, lockQName))
|
||||||
{
|
{
|
||||||
// The callback must be informed as we released the lock automatically
|
// The callback must be informed as we released the lock automatically
|
||||||
callLockReleased(callback);
|
callLockReleased(callback);
|
||||||
@@ -424,7 +424,14 @@ public class JobLockServiceImpl implements JobLockService
|
|||||||
@Override
|
@Override
|
||||||
public void releaseLock(final String lockToken, final QName lockQName)
|
public void releaseLock(final String lockToken, final QName lockQName)
|
||||||
{
|
{
|
||||||
releaseLockVerify(lockToken, lockQName);
|
RetryingTransactionCallback<Boolean> releaseCallback = new RetryingTransactionCallback<Boolean>()
|
||||||
|
{
|
||||||
|
public Boolean execute() throws Throwable
|
||||||
|
{
|
||||||
|
return lockDAO.releaseLock(lockQName, lockToken, false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
retryingTransactionHelper.doInTransaction(releaseCallback, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -442,27 +449,6 @@ public class JobLockServiceImpl implements JobLockService
|
|||||||
return retryingTransactionHelper.doInTransaction(releaseCallback, false, true);
|
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
|
* @throws LockAcquisitionException on failure
|
||||||
*/
|
*/
|
||||||
|
@@ -241,9 +241,9 @@ public class LockDAOTest extends TestCase
|
|||||||
|
|
||||||
// Check that the lock cannot be release when not held
|
// Check that the lock cannot be release when not held
|
||||||
release(lockAAA, "Invalid-Token", false);
|
release(lockAAA, "Invalid-Token", false);
|
||||||
assertFalse(lockDAO.releaseLockQuiet(lockAAA, "invalidToken"));
|
assertFalse(lockDAO.releaseLock(lockAAA, "invalidToken", true));
|
||||||
assertTrue(lockDAO.releaseLockQuiet(lockAAA, token));
|
assertTrue(lockDAO.releaseLock(lockAAA, token, true));
|
||||||
assertFalse(lockDAO.releaseLockQuiet(lockAAA, token));
|
assertFalse(lockDAO.releaseLock(lockAAA, token, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testReleaseLockRepeated() throws Exception
|
public void testReleaseLockRepeated() throws Exception
|
||||||
|
@@ -380,7 +380,7 @@ public class JobLockServiceTest extends TestCase
|
|||||||
// The first refresh will occur in 500ms
|
// The first refresh will occur in 500ms
|
||||||
wait(1000L);
|
wait(1000L);
|
||||||
// Should NOT get a callback saying that the lock has been released
|
// Should NOT get a callback saying that the lock has been released
|
||||||
assertTrue("Lock should be optimistically released", released[0] > 0);
|
assertFalse("Lock should be optimistically released", released[0] > 0);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
jobLockService.getLock(lockQName, lockTTL);
|
jobLockService.getLock(lockQName, lockTTL);
|
||||||
|
Reference in New Issue
Block a user