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.2) to 5.2.N (5.2.1)
126675 rneamtu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2) 126654 amukha: MNT-16272: User usages prevent some CMIS sessions from starting under load - Removed JobLock from RepoUsageComponent. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@127010 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -52,7 +52,6 @@
|
||||
<property name="authorityService" ref="authorityService"/>
|
||||
<property name="attributeService" ref="attributeService"/>
|
||||
<property name="dictionaryService" ref="dictionaryService"/>
|
||||
<property name="jobLockService" ref="jobLockService"/>
|
||||
<property name="cannedQueryDAO" ref="cannedQueryDAO"/>
|
||||
<property name="qnameDAO" ref="qnameDAO"/>
|
||||
</bean>
|
||||
@@ -61,6 +60,7 @@
|
||||
<property name="scheduler" ref="schedulerFactory" />
|
||||
<property name="transactionService" ref="transactionService"/>
|
||||
<property name="repoUsageComponent" ref="repoUsageComponent"/>
|
||||
<property name="jobLockService" ref="jobLockService"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
@@ -39,11 +39,6 @@ import org.alfresco.service.namespace.QName;
|
||||
*/
|
||||
public interface RepoUsageComponent
|
||||
{
|
||||
public static final Long LOCK_TTL = 60000L;
|
||||
public static final QName LOCK_USAGE = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "RepoUsageComponent");
|
||||
public static final QName LOCK_USAGE_USERS = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "RepoUsageComponent.Users");
|
||||
public static final QName LOCK_USAGE_DOCUMENTS = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "RepoUsageComponent.Documents");
|
||||
|
||||
public static final String KEY_USAGE_ROOT = ".repoUsages";
|
||||
public static final String KEY_USAGE_CURRENT = "current";
|
||||
public static final String KEY_USAGE_LAST_UPDATE_USERS = "lastUpdateUsers";
|
||||
|
@@ -39,8 +39,6 @@ import org.alfresco.ibatis.IdsEntity;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.domain.qname.QNameDAO;
|
||||
import org.alfresco.repo.domain.query.CannedQueryDAO;
|
||||
import org.alfresco.repo.lock.JobLockService;
|
||||
import org.alfresco.repo.lock.LockAcquisitionException;
|
||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport.TxnReadState;
|
||||
import org.alfresco.service.cmr.admin.RepoUsage;
|
||||
@@ -77,7 +75,6 @@ public class RepoUsageComponentImpl implements RepoUsageComponent
|
||||
private AuthorityService authorityService;
|
||||
private AttributeService attributeService;
|
||||
private DictionaryService dictionaryService;
|
||||
private JobLockService jobLockService;
|
||||
private CannedQueryDAO cannedQueryDAO;
|
||||
private QNameDAO qnameDAO;
|
||||
|
||||
@@ -130,14 +127,6 @@ public class RepoUsageComponentImpl implements RepoUsageComponent
|
||||
this.dictionaryService = dictionaryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param jobLockService service to prevent duplicate work when updating usages
|
||||
*/
|
||||
public void setJobLockService(JobLockService jobLockService)
|
||||
{
|
||||
this.jobLockService = jobLockService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cannedQueryDAO DAO for executing queries
|
||||
*/
|
||||
@@ -169,7 +158,6 @@ public class RepoUsageComponentImpl implements RepoUsageComponent
|
||||
PropertyCheck.mandatory(this, "authorityService", authorityService);
|
||||
PropertyCheck.mandatory(this, "attributeService", attributeService);
|
||||
PropertyCheck.mandatory(this, "dictionaryService", dictionaryService);
|
||||
PropertyCheck.mandatory(this, "jobLockService", jobLockService);
|
||||
PropertyCheck.mandatory(this, "cannedQueryDAO", cannedQueryDAO);
|
||||
PropertyCheck.mandatory(this, "qnameDAO", qnameDAO);
|
||||
}
|
||||
@@ -287,11 +275,6 @@ public class RepoUsageComponentImpl implements RepoUsageComponent
|
||||
*/
|
||||
private boolean updateUsers(boolean reset)
|
||||
{
|
||||
String lockToken = null;
|
||||
try
|
||||
{
|
||||
// Lock to prevent concurrent queries
|
||||
lockToken = jobLockService.getLock(LOCK_USAGE_USERS, LOCK_TTL);
|
||||
Long userCount = 0L;
|
||||
|
||||
if (!reset)
|
||||
@@ -305,8 +288,6 @@ public class RepoUsageComponentImpl implements RepoUsageComponent
|
||||
// We subtract one to cater for 'guest', which is implicit
|
||||
userCount = userCount > 0L ? userCount - 1L : 0L;
|
||||
|
||||
// Lock again to be sure we still have the right to update
|
||||
jobLockService.refreshLock(lockToken, LOCK_USAGE_USERS, LOCK_TTL);
|
||||
}
|
||||
attributeService.setAttribute(
|
||||
new Long(System.currentTimeMillis()),
|
||||
@@ -317,30 +298,12 @@ public class RepoUsageComponentImpl implements RepoUsageComponent
|
||||
// Success
|
||||
return true;
|
||||
}
|
||||
catch (LockAcquisitionException e)
|
||||
{
|
||||
logger.debug("Failed to get lock for user counts: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (lockToken != null)
|
||||
{
|
||||
jobLockService.releaseLock(lockToken, LOCK_USAGE_USERS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update number of documents with appropriate locking
|
||||
*/
|
||||
private boolean updateDocuments(boolean reset)
|
||||
{
|
||||
String lockToken = null;
|
||||
try
|
||||
{
|
||||
// Lock to prevent concurrent queries
|
||||
lockToken = jobLockService.getLock(LOCK_USAGE_DOCUMENTS, LOCK_TTL);
|
||||
Long documentCount = 0L;
|
||||
|
||||
if (!reset)
|
||||
@@ -357,9 +320,6 @@ public class RepoUsageComponentImpl implements RepoUsageComponent
|
||||
IdsEntity idsParam = new IdsEntity();
|
||||
idsParam.setIds(new ArrayList<Long>(searchTypeQNameIds));
|
||||
documentCount = cannedQueryDAO.executeCountQuery(QUERY_NS, QUERY_SELECT_COUNT_DOCUMENTS, idsParam);
|
||||
|
||||
// Lock again to be sure we still have the right to update
|
||||
jobLockService.refreshLock(lockToken, LOCK_USAGE_DOCUMENTS, LOCK_TTL);
|
||||
}
|
||||
attributeService.setAttribute(
|
||||
new Long(System.currentTimeMillis()),
|
||||
@@ -370,19 +330,6 @@ public class RepoUsageComponentImpl implements RepoUsageComponent
|
||||
// Success
|
||||
return true;
|
||||
}
|
||||
catch (LockAcquisitionException e)
|
||||
{
|
||||
logger.debug("Failed to get lock for document counts: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (lockToken != null)
|
||||
{
|
||||
jobLockService.releaseLock(lockToken, LOCK_USAGE_DOCUMENTS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the usage component. Protect with a read lock, transaction check and authentication check.
|
||||
|
@@ -28,6 +28,8 @@ package org.alfresco.repo.usage;
|
||||
import java.util.Date;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.lock.JobLockService;
|
||||
import org.alfresco.repo.lock.LockAcquisitionException;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
@@ -63,9 +65,13 @@ public class RepoUsageMonitor implements RepoUsageComponent.RestrictionObserver
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(RepoUsageMonitor.class);
|
||||
|
||||
public static final Long LOCK_TTL = 60000L;
|
||||
public static final QName LOCK_USAGE = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "RepoUsageMonitor");
|
||||
|
||||
private Scheduler scheduler;
|
||||
private TransactionServiceImpl transactionService;
|
||||
private RepoUsageComponent repoUsageComponent;
|
||||
private JobLockService jobLockService;
|
||||
private final QName vetoName = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "RepoUsageMonitor");
|
||||
|
||||
/**
|
||||
@@ -99,6 +105,14 @@ public class RepoUsageMonitor implements RepoUsageComponent.RestrictionObserver
|
||||
this.repoUsageComponent = repoUsageComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param jobLockService service to prevent duplicate work when updating usages
|
||||
*/
|
||||
public void setJobLockService(JobLockService jobLockService)
|
||||
{
|
||||
this.jobLockService = jobLockService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that all properties are properly set
|
||||
*/
|
||||
@@ -107,6 +121,7 @@ public class RepoUsageMonitor implements RepoUsageComponent.RestrictionObserver
|
||||
PropertyCheck.mandatory(this, "scheduler", scheduler);
|
||||
PropertyCheck.mandatory(this, "transactionService", transactionService);
|
||||
PropertyCheck.mandatory(this, "repoUsageComponent", repoUsageComponent);
|
||||
PropertyCheck.mandatory(this, "jobLockService", jobLockService);
|
||||
|
||||
// Trigger the scheduled updates
|
||||
final JobDetail jobDetail = new JobDetail("rmj", Scheduler.DEFAULT_GROUP, RepoUsageMonitorJob.class);
|
||||
@@ -167,8 +182,35 @@ public class RepoUsageMonitor implements RepoUsageComponent.RestrictionObserver
|
||||
return null;
|
||||
}
|
||||
};
|
||||
String lockToken = null;
|
||||
TrackerJobLockRefreshCallback callback = new TrackerJobLockRefreshCallback();
|
||||
try
|
||||
{
|
||||
// Lock to prevent concurrent queries
|
||||
lockToken = jobLockService.getLock(LOCK_USAGE, LOCK_TTL);
|
||||
jobLockService.refreshLock(lockToken, LOCK_USAGE, LOCK_TTL / 2, callback);
|
||||
AuthenticationUtil.runAs(runAs, AuthenticationUtil.getSystemUserName());
|
||||
}
|
||||
catch (LockAcquisitionException e)
|
||||
{
|
||||
logger.debug("Failed to get lock for usage monitor: " + e.getMessage());
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (lockToken != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
callback.isActive = false;
|
||||
jobLockService.releaseLock(lockToken, LOCK_USAGE);
|
||||
}
|
||||
catch (LockAcquisitionException e)
|
||||
{
|
||||
logger.debug("Failed to release lock for usage monitor: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the current status, logs messages and sets a read-write veto, if necessary
|
||||
@@ -209,4 +251,24 @@ public class RepoUsageMonitor implements RepoUsageComponent.RestrictionObserver
|
||||
repoUsageMonitor.checkUsages();
|
||||
}
|
||||
}
|
||||
|
||||
private class TrackerJobLockRefreshCallback implements JobLockService.JobLockRefreshCallback
|
||||
{
|
||||
public boolean isActive = true;
|
||||
|
||||
@Override
|
||||
public boolean isActive()
|
||||
{
|
||||
return isActive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lockReleased()
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("lock released");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -236,7 +236,10 @@ public class RepoUsageComponentTest extends TestCase
|
||||
|
||||
/**
|
||||
* Check that concurrent updates are prevented
|
||||
*
|
||||
* The test is disabled as the Component is not using JobLocks any more
|
||||
*/
|
||||
/*
|
||||
public void test6ConcurrentUpdates() throws Exception
|
||||
{
|
||||
// Firstly check that we can get an update
|
||||
@@ -286,4 +289,5 @@ public class RepoUsageComponentTest extends TestCase
|
||||
jobLockService.releaseLock(lockToken, RepoUsageComponent.LOCK_USAGE_USERS);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
Reference in New Issue
Block a user