mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +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:
@@ -1,28 +1,28 @@
|
||||
/*
|
||||
* #%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.ArrayList;
|
||||
@@ -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;
|
||||
@@ -52,7 +50,7 @@ import org.alfresco.service.cmr.attributes.AttributeService;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.security.AuthorityService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.DateUtil;
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -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,48 +275,28 @@ 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)
|
||||
{
|
||||
// Count users
|
||||
IdsEntity idsParam = new IdsEntity();
|
||||
idsParam.setIdOne(qnameDAO.getOrCreateQName(ContentModel.ASPECT_PERSON_DISABLED).getFirst());
|
||||
idsParam.setIdTwo(qnameDAO.getOrCreateQName(ContentModel.TYPE_PERSON).getFirst());
|
||||
userCount = cannedQueryDAO.executeCountQuery(QUERY_NS, QUERY_SELECT_COUNT_PERSONS_NOT_DISABLED, idsParam);
|
||||
|
||||
// We subtract one to cater for 'guest', which is implicit
|
||||
userCount = userCount > 0L ? userCount - 1L : 0L;
|
||||
Long userCount = 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()),
|
||||
KEY_USAGE_ROOT, KEY_USAGE_CURRENT, KEY_USAGE_LAST_UPDATE_USERS);
|
||||
attributeService.setAttribute(
|
||||
userCount,
|
||||
KEY_USAGE_ROOT, KEY_USAGE_CURRENT, KEY_USAGE_USERS);
|
||||
// Success
|
||||
return true;
|
||||
}
|
||||
catch (LockAcquisitionException e)
|
||||
if (!reset)
|
||||
{
|
||||
logger.debug("Failed to get lock for user counts: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (lockToken != null)
|
||||
{
|
||||
jobLockService.releaseLock(lockToken, LOCK_USAGE_USERS);
|
||||
}
|
||||
// Count users
|
||||
IdsEntity idsParam = new IdsEntity();
|
||||
idsParam.setIdOne(qnameDAO.getOrCreateQName(ContentModel.ASPECT_PERSON_DISABLED).getFirst());
|
||||
idsParam.setIdTwo(qnameDAO.getOrCreateQName(ContentModel.TYPE_PERSON).getFirst());
|
||||
userCount = cannedQueryDAO.executeCountQuery(QUERY_NS, QUERY_SELECT_COUNT_PERSONS_NOT_DISABLED, idsParam);
|
||||
|
||||
// We subtract one to cater for 'guest', which is implicit
|
||||
userCount = userCount > 0L ? userCount - 1L : 0L;
|
||||
|
||||
}
|
||||
attributeService.setAttribute(
|
||||
new Long(System.currentTimeMillis()),
|
||||
KEY_USAGE_ROOT, KEY_USAGE_CURRENT, KEY_USAGE_LAST_UPDATE_USERS);
|
||||
attributeService.setAttribute(
|
||||
userCount,
|
||||
KEY_USAGE_ROOT, KEY_USAGE_CURRENT, KEY_USAGE_USERS);
|
||||
// Success
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -336,52 +304,31 @@ public class RepoUsageComponentImpl implements RepoUsageComponent
|
||||
*/
|
||||
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;
|
||||
Long documentCount = 0L;
|
||||
|
||||
if (!reset)
|
||||
{
|
||||
// Count documents
|
||||
Set<QName> searchTypeQNames = new HashSet<QName>(11);
|
||||
Collection<QName> qnames = dictionaryService.getSubTypes(ContentModel.TYPE_CONTENT, true);
|
||||
searchTypeQNames.addAll(qnames);
|
||||
searchTypeQNames.add(ContentModel.TYPE_CONTENT);
|
||||
qnames = dictionaryService.getSubTypes(ContentModel.TYPE_LINK, true);
|
||||
searchTypeQNames.addAll(qnames);
|
||||
searchTypeQNames.add(ContentModel.TYPE_LINK);
|
||||
Set<Long> searchTypeQNameIds = qnameDAO.convertQNamesToIds(searchTypeQNames, false);
|
||||
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()),
|
||||
KEY_USAGE_ROOT, KEY_USAGE_CURRENT, KEY_USAGE_LAST_UPDATE_DOCUMENTS);
|
||||
attributeService.setAttribute(
|
||||
documentCount,
|
||||
KEY_USAGE_ROOT, KEY_USAGE_CURRENT, KEY_USAGE_DOCUMENTS);
|
||||
// Success
|
||||
return true;
|
||||
}
|
||||
catch (LockAcquisitionException e)
|
||||
if (!reset)
|
||||
{
|
||||
logger.debug("Failed to get lock for document counts: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (lockToken != null)
|
||||
{
|
||||
jobLockService.releaseLock(lockToken, LOCK_USAGE_DOCUMENTS);
|
||||
}
|
||||
// Count documents
|
||||
Set<QName> searchTypeQNames = new HashSet<QName>(11);
|
||||
Collection<QName> qnames = dictionaryService.getSubTypes(ContentModel.TYPE_CONTENT, true);
|
||||
searchTypeQNames.addAll(qnames);
|
||||
searchTypeQNames.add(ContentModel.TYPE_CONTENT);
|
||||
qnames = dictionaryService.getSubTypes(ContentModel.TYPE_LINK, true);
|
||||
searchTypeQNames.addAll(qnames);
|
||||
searchTypeQNames.add(ContentModel.TYPE_LINK);
|
||||
Set<Long> searchTypeQNameIds = qnameDAO.convertQNamesToIds(searchTypeQNames, false);
|
||||
IdsEntity idsParam = new IdsEntity();
|
||||
idsParam.setIds(new ArrayList<Long>(searchTypeQNameIds));
|
||||
documentCount = cannedQueryDAO.executeCountQuery(QUERY_NS, QUERY_SELECT_COUNT_DOCUMENTS, idsParam);
|
||||
}
|
||||
attributeService.setAttribute(
|
||||
new Long(System.currentTimeMillis()),
|
||||
KEY_USAGE_ROOT, KEY_USAGE_CURRENT, KEY_USAGE_LAST_UPDATE_DOCUMENTS);
|
||||
attributeService.setAttribute(
|
||||
documentCount,
|
||||
KEY_USAGE_ROOT, KEY_USAGE_CURRENT, KEY_USAGE_DOCUMENTS);
|
||||
// Success
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user