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:
Ancuta Morarasu
2016-05-12 08:41:13 +00:00
parent b406f49bda
commit 0ba905fa78
5 changed files with 212 additions and 204 deletions

View File

@@ -1,33 +1,35 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
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;
@@ -62,10 +64,14 @@ import org.quartz.TriggerUtils;
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,7 +121,8 @@ 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);
jobDetail.getJobDataMap().put("RepoUsageMonitor", this);
@@ -167,7 +182,34 @@ public class RepoUsageMonitor implements RepoUsageComponent.RestrictionObserver
return null;
}
};
AuthenticationUtil.runAs(runAs, AuthenticationUtil.getSystemUserName());
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());
}
}
}
}
/**
@@ -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");
}
}
}
}