mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-15 15:02:20 +00:00
Merged 5.1.N (5.1.1) to HEAD (5.2)
122472 dhulley: Increase the TTL for the property value cleaner to 1 hour (ACE-5153) - Simplify the lock code because it's not iterative i.e. just lock and unlock git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@123666 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -23,7 +23,6 @@ import org.alfresco.repo.lock.JobLockService;
|
||||
import org.alfresco.repo.lock.LockAcquisitionException;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -39,18 +38,11 @@ public class PropTablesCleaner
|
||||
private JobLockService jobLockService;
|
||||
|
||||
/* 1 minute */
|
||||
private static final long LOCK_TTL = 60000L;
|
||||
private static final long LOCK_TTL = 360000L;
|
||||
private static final QName LOCK_QNAME = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, PropTablesCleaner.class.getName());
|
||||
private static ThreadLocal<Pair<Long, String>> lockThreadLocal = new ThreadLocal<Pair<Long, String>>();
|
||||
|
||||
private static Log logger = LogFactory.getLog(PropTablesCleaner.class);
|
||||
|
||||
public void checkProperties()
|
||||
{
|
||||
PropertyCheck.mandatory(this, "jobLockService", jobLockService);
|
||||
PropertyCheck.mandatory(this, "propertyValueDAO", propertyValueDAO);
|
||||
}
|
||||
|
||||
public void setPropertyValueDAO(PropertyValueDAO propertyValueDAO)
|
||||
{
|
||||
this.propertyValueDAO = propertyValueDAO;
|
||||
@@ -61,76 +53,47 @@ public class PropTablesCleaner
|
||||
this.jobLockService = jobLockService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazily update the job lock
|
||||
*/
|
||||
private void refreshLock()
|
||||
public void checkProperties()
|
||||
{
|
||||
Pair<Long, String> lockPair = lockThreadLocal.get();
|
||||
if (lockPair == null)
|
||||
{
|
||||
String lockToken = jobLockService.getLock(LOCK_QNAME, LOCK_TTL);
|
||||
Long lastLock = new Long(System.currentTimeMillis());
|
||||
// We have not locked before
|
||||
lockPair = new Pair<Long, String>(lastLock, lockToken);
|
||||
lockThreadLocal.set(lockPair);
|
||||
}
|
||||
else
|
||||
{
|
||||
long now = System.currentTimeMillis();
|
||||
long lastLock = lockPair.getFirst().longValue();
|
||||
String lockToken = lockPair.getSecond();
|
||||
// Only refresh the lock if we are past a threshold
|
||||
if (now - lastLock > (long)(LOCK_TTL/2L))
|
||||
{
|
||||
jobLockService.refreshLock(lockToken, LOCK_QNAME, LOCK_TTL);
|
||||
lastLock = System.currentTimeMillis();
|
||||
lockPair = new Pair<Long, String>(lastLock, lockToken);
|
||||
lockThreadLocal.set(lockPair);
|
||||
}
|
||||
}
|
||||
PropertyCheck.mandatory(this, "jobLockService", jobLockService);
|
||||
PropertyCheck.mandatory(this, "propertyValueDAO", propertyValueDAO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Release the lock after the job completes
|
||||
* Get {@link #LOCK_QNAME a lock} for {@link #LOCK_TTL a long-running job} and {@link PropertyValueDAO#cleanupUnusedValues() call through}
|
||||
* to get the unused data cleaned up.
|
||||
*/
|
||||
private void releaseLock()
|
||||
{
|
||||
Pair<Long, String> lockPair = lockThreadLocal.get();
|
||||
if (lockPair != null)
|
||||
{
|
||||
// We can't release without a token
|
||||
try
|
||||
{
|
||||
jobLockService.releaseLock(lockPair.getSecond(), LOCK_QNAME);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Reset
|
||||
lockThreadLocal.set(null);
|
||||
}
|
||||
}
|
||||
// else: We can't release without a token
|
||||
}
|
||||
|
||||
public void execute()
|
||||
{
|
||||
checkProperties();
|
||||
|
||||
String lockToken = null;
|
||||
try
|
||||
{
|
||||
refreshLock();
|
||||
// Get a lock
|
||||
lockToken = jobLockService.getLock(LOCK_QNAME, LOCK_TTL);
|
||||
propertyValueDAO.cleanupUnusedValues();
|
||||
}
|
||||
catch (LockAcquisitionException e)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Skipping prop tables cleaning. " + e.getMessage());
|
||||
logger.debug("Skipping prop tables cleaning (could not get lock): " + e.getMessage());
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
releaseLock();
|
||||
if (lockToken != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
jobLockService.releaseLock(lockToken, LOCK_QNAME);
|
||||
}
|
||||
catch (LockAcquisitionException e)
|
||||
{
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user