Merged PATCHES/V4.1.3 to HEAD

45612: Fix for ALF-17456 	 BM-0013: SOAK01_04: 150K+ calls to AuthorityDaoImpl.isAuthorityContained in on login
    45648: Final part for     ALF-17456 BM-0013: SOAK01_04: 150K+ calls to AuthorityDaoImpl.isAuthorityContained in on login 
    46033: Build fixes


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@47861 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Andrew Hind
2013-03-11 12:36:32 +00:00
parent c1d11e0f3a
commit 01b6ae39b1
19 changed files with 1517 additions and 55 deletions

View File

@@ -144,7 +144,7 @@ public abstract class AbstractAuthorityBridgeDAO implements AuthorityBridgeDAO
storeId = nodeDAO.getStore(tenantSpecificStoreRef).getFirst();
}
Pair<Long, NodeRef> pair = (authRef == null) ? null : nodeDAO.getNodePair(authRef);
Pair<Long, NodeRef> pair = (authRef == null) ? null : nodeDAO.getNodePair(tenantService.getName(authRef));
return selectDirectAuthoritiesForUser(authorityContainerTypeQNameId, memberAssocQNameId, authorityNameQNameId, storeId, (pair == null) ? -1L : pair.getFirst());
}

View File

@@ -0,0 +1,101 @@
/*
* Copyright (C) 2005-2013 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* 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/>.
*/
package org.alfresco.repo.security.authority;
import java.util.List;
import org.alfresco.repo.cache.AbstractAsynchronouslyRefreshedCache;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.util.BridgeTable;
import org.alfresco.util.PropertyCheck;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
/**
* @author Andy
*/
public class AuthorityBridgeTableAsynchronouslyRefreshedCache extends AbstractAsynchronouslyRefreshedCache<BridgeTable<String>> implements InitializingBean
{
private static Log logger = LogFactory.getLog(AuthorityBridgeTableAsynchronouslyRefreshedCache.class);
private AuthorityBridgeDAO authorityBridgeDAO;
private RetryingTransactionHelper retryingTransactionHelper;
/**
* @param authorityBridgeDAO
* the authorityBridgeDAO to set
*/
public void setAuthorityBridgeDAO(AuthorityBridgeDAO authorityBridgeDAO)
{
this.authorityBridgeDAO = authorityBridgeDAO;
}
/**
* @param retryingTransactionHelper
* the retryingTransactionHelper to set
*/
public void setRetryingTransactionHelper(RetryingTransactionHelper retryingTransactionHelper)
{
this.retryingTransactionHelper = retryingTransactionHelper;
}
/*
* (non-Javadoc)
* @see org.alfresco.repo.cache.AbstractAsynchronouslyRefreshedCache#buildCache()
*/
@Override
protected BridgeTable<String> buildCache(final String tenantId)
{
return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<BridgeTable<String>>()
{
@Override
public BridgeTable<String> execute() throws Throwable
{
return doBuildCache(tenantId);
}
}, true, false);
}
private BridgeTable<String> doBuildCache(String tenantId)
{
List<AuthorityBridgeLink> links = authorityBridgeDAO.getAuthorityBridgeLinks();
BridgeTable<String> bridgeTable = new BridgeTable<String>();
for (AuthorityBridgeLink link : links)
{
bridgeTable.addLink(link.getParentName(), link.getChildName());
}
return bridgeTable;
}
/*
* (non-Javadoc)
* @see org.alfresco.repo.cache.AbstractAsynchronouslyRefreshedCache#afterPropertiesSet()
*/
@Override
public void afterPropertiesSet() throws Exception
{
PropertyCheck.mandatory(this, "authorityBridgeDAO", authorityBridgeDAO);
PropertyCheck.mandatory(this, "retryingTransactionHelper", retryingTransactionHelper);
super.afterPropertiesSet();
}
}

View File

@@ -40,6 +40,8 @@ import org.alfresco.query.CannedQueryFactory;
import org.alfresco.query.CannedQueryResults;
import org.alfresco.query.PagingRequest;
import org.alfresco.query.PagingResults;
import org.alfresco.repo.cache.RefreshableCacheEvent;
import org.alfresco.repo.cache.RefreshableCacheListener;
import org.alfresco.repo.cache.SimpleCache;
import org.alfresco.repo.domain.permissions.AclDAO;
import org.alfresco.repo.node.NodeServicePolicies;
@@ -76,12 +78,14 @@ import org.alfresco.util.EqualsHelper;
import org.alfresco.util.ISO9075;
import org.alfresco.util.Pair;
import org.alfresco.util.ParameterCheck;
import org.alfresco.util.PropertyCheck;
import org.alfresco.util.SearchLanguageConversion;
import org.alfresco.util.registry.NamedObjectRegistry;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.BeforeDeleteNodePolicy, NodeServicePolicies.OnUpdatePropertiesPolicy
public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.BeforeDeleteNodePolicy, NodeServicePolicies.OnUpdatePropertiesPolicy, RefreshableCacheListener, InitializingBean
{
private static Log logger = LogFactory.getLog(AuthorityDAOImpl.class);
@@ -113,7 +117,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
private SimpleCache<String, Set<String>> userAuthorityCache;
private SimpleCache<Pair<String, String>, List<ChildAssociationRef>> zoneAuthorityCache;
private SimpleCache<NodeRef, Pair<Map<NodeRef,String>, List<NodeRef>>> childAuthorityCache;
private SimpleCache<String, BridgeTable<String>> authorityBridgeTableByTenantCache;
private AuthorityBridgeTableAsynchronouslyRefreshedCache authorityBridgeTableCache;
/** System Container ref cache (Tennant aware) */
private Map<String, NodeRef> systemContainerRefs = new ConcurrentHashMap<String, NodeRef>(4);
@@ -126,11 +130,14 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
private boolean useBridgeTable = true;
private boolean useGetContainingAuthoritiesForIsAuthorityContained = true;
private AclDAO aclDao;
private PolicyComponent policyComponent;
private NamedObjectRegistry<CannedQueryFactory> cannedQueryRegistry;
private NamedObjectRegistry<CannedQueryFactory<?>> cannedQueryRegistry;
private AuthorityBridgeDAO authorityBridgeDAO;
public AuthorityDAOImpl()
{
super();
@@ -197,9 +204,9 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
this.childAuthorityCache = childAuthorityCache;
}
public void setAuthorityBridgeTableByTenantCache(SimpleCache<String, BridgeTable<String>> authorityBridgeTableByTenantCache)
public void setAuthorityBridgeTableCache(AuthorityBridgeTableAsynchronouslyRefreshedCache authorityBridgeTableCache)
{
this.authorityBridgeTableByTenantCache = authorityBridgeTableByTenantCache;
this.authorityBridgeTableCache = authorityBridgeTableCache;
}
/**
@@ -231,11 +238,19 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
this.policyComponent = policyComponent;
}
public void setCannedQueryRegistry(NamedObjectRegistry<CannedQueryFactory> cannedQueryRegistry)
public void setCannedQueryRegistry(NamedObjectRegistry<CannedQueryFactory<?>> cannedQueryRegistry)
{
this.cannedQueryRegistry = cannedQueryRegistry;
}
/**
* @param useGetContainingAuthoritiesForHasAuthority the useGetContainingAuthoritiesForHasAuthority to set
*/
public void setUseGetContainingAuthoritiesForIsAuthorityContained(boolean useGetContainingAuthoritiesForIsAuthorityContained)
{
this.useGetContainingAuthoritiesForIsAuthorityContained = useGetContainingAuthoritiesForIsAuthorityContained;
}
/**
* @param authorityBridgeDAO the authorityBridgeDAO to set
*/
@@ -296,7 +311,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
else
{
userAuthorityCache.clear();
authorityBridgeTableByTenantCache.clear();
authorityBridgeTableCache.refresh();
}
}
@@ -352,7 +367,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
removeParentsFromChildAuthorityCache(nodeRef);
authorityLookupCache.remove(cacheKey(name));
userAuthorityCache.clear();
authorityBridgeTableByTenantCache.clear();
authorityBridgeTableCache.refresh();
nodeService.deleteNode(nodeRef);
}
@@ -724,30 +739,14 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
else
{
userAuthorityCache.clear();
authorityBridgeTableByTenantCache.clear();
authorityBridgeTableCache.refresh();
}
}
private BridgeTable<String> getBridgeTable()
{
String tenant = tenantService.getCurrentUserDomain();
BridgeTable<String> bridgeTable = authorityBridgeTableByTenantCache.get(tenant);
if(bridgeTable == null)
{
List<AuthorityBridgeLink> links = authorityBridgeDAO.getAuthorityBridgeLinks();
bridgeTable = new BridgeTable<String>();
for(AuthorityBridgeLink link : links)
{
bridgeTable.addLink(link.getParentName(), link.getChildName());
}
authorityBridgeTableByTenantCache.put(tenant, bridgeTable);
}
return bridgeTable;
}
private void listAuthoritiesByBridgeTable(Set<String> authorities, String name)
{
BridgeTable<String> bridgeTable = getBridgeTable();
BridgeTable<String> bridgeTable = authorityBridgeTableCache.get();
AuthorityType type = AuthorityType.getAuthorityType(name);
switch(type)
@@ -1095,8 +1094,21 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
negativeHits.add(getPooledName(authority));
return false;
}
return isAuthorityContained(authorityNodeRef, getPooledName(authority), authorityToFind, positiveHits, negativeHits);
if(useGetContainingAuthoritiesForIsAuthorityContained)
{
if(authorityBridgeTableCache.isUpToDate())
{
return getContainingAuthorities(null, authorityToFind, false).contains(authority);
}
else
{
return isAuthorityContained(authorityNodeRef, getPooledName(authority), authorityToFind, positiveHits, negativeHits);
}
}
else
{
return isAuthorityContained(authorityNodeRef, getPooledName(authority), authorityToFind, positiveHits, negativeHits);
}
}
private boolean isAuthorityContained(NodeRef authorityNodeRef, String authority, String authorityToFind, Set<String> positiveHits, Set<String> negativeHits)
@@ -1492,7 +1504,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
}
}
authorityLookupCache.clear();
authorityBridgeTableByTenantCache.clear();
authorityBridgeTableCache.refresh();
// Cache is out of date
userAuthorityCache.clear();
@@ -1621,5 +1633,57 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
}
return auths;
}
}
/* (non-Javadoc)
* @see org.alfresco.repo.cache.RefreshableCacheListener#onRefreshableCacheEvent(org.alfresco.repo.cache.RefreshableCacheEvent)
*/
@Override
public void onRefreshableCacheEvent(RefreshableCacheEvent refreshableCacheEvent)
{
if(logger.isDebugEnabled())
{
logger.debug("Bridge Table cache triggering userAuthorityCache.clear()");
}
userAuthorityCache.clear();
}
/* (non-Javadoc)
* @see org.alfresco.repo.cache.RefreshableCacheListener#getCacheId()
*/
@Override
public String getCacheId()
{
return AuthorityDAOImpl.class.getName();
}
/* (non-Javadoc)
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
@Override
public void afterPropertiesSet() throws Exception
{
PropertyCheck.mandatory(this, "aclDao", aclDao);
PropertyCheck.mandatory(this, "authorityBridgeDAO", authorityBridgeDAO);
PropertyCheck.mandatory(this, "authorityBridgeTableCache", authorityBridgeTableCache);
PropertyCheck.mandatory(this, "authorityLookupCache", authorityLookupCache);
PropertyCheck.mandatory(this, "cannedQueryRegistry", cannedQueryRegistry);
PropertyCheck.mandatory(this, "childAuthorityCache", childAuthorityCache);
PropertyCheck.mandatory(this, "dictionaryService", dictionaryService);
PropertyCheck.mandatory(this, "namespacePrefixResolver", namespacePrefixResolver);
PropertyCheck.mandatory(this, "nodeService", nodeService);
PropertyCheck.mandatory(this, "personService", personService);
PropertyCheck.mandatory(this, "policyComponent", policyComponent);
PropertyCheck.mandatory(this, "searchService", searchService);
PropertyCheck.mandatory(this, "storeRef", storeRef);
PropertyCheck.mandatory(this, "tenantService", tenantService);
PropertyCheck.mandatory(this, "userAuthorityCache", userAuthorityCache);
PropertyCheck.mandatory(this, "zoneAuthorityCache", zoneAuthorityCache);
PropertyCheck.mandatory(this, "storeRef", storeRef);
PropertyCheck.mandatory(this, "storeRef", storeRef);
authorityBridgeTableCache.register(this);
};
}

View File

@@ -74,6 +74,7 @@ public class AuthorityServiceTest extends TestCase
private UserTransaction tx;
private AclDAO aclDaoComponent;
private NodeService nodeService;
private AuthorityBridgeTableAsynchronouslyRefreshedCache authorityBridgeTableCache;
public AuthorityServiceTest()
{
@@ -105,6 +106,7 @@ public class AuthorityServiceTest extends TestCase
authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao");
aclDaoComponent = (AclDAO) ctx.getBean("aclDAO");
nodeService = (NodeService) ctx.getBean("nodeService");
authorityBridgeTableCache = (AuthorityBridgeTableAsynchronouslyRefreshedCache) ctx.getBean("authorityBridgeTableCache");
String defaultAdminUser = AuthenticationUtil.getAdminUserName();
AuthenticationUtil.setFullyAuthenticatedUser(defaultAdminUser);
@@ -623,16 +625,19 @@ public class AuthorityServiceTest extends TestCase
assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth3 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "three");
pubAuthorityService.addAuthority(auth1, auth3);
authorityBridgeTableCache.forceInChangesForThisUncommittedTransaction();
assertEquals("GROUP_three", auth3);
assertEquals(GRP_CNT+3, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth4 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "four");
pubAuthorityService.addAuthority(auth1, auth4);
authorityBridgeTableCache.forceInChangesForThisUncommittedTransaction();
assertEquals("GROUP_four", auth4);
assertEquals(GRP_CNT+4, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth5 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "five");
pubAuthorityService.addAuthority(auth2, auth5);
authorityBridgeTableCache.forceInChangesForThisUncommittedTransaction();
assertEquals("GROUP_five", auth5);
assertEquals(GRP_CNT+5, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
@@ -640,6 +645,7 @@ public class AuthorityServiceTest extends TestCase
//System.out.println("Users: "+ getAllAuthorities(AuthorityType.USER));
checkAuthorityCollectionSize(3, getAllAuthorities(AuthorityType.USER), AuthorityType.USER);
pubAuthorityService.addAuthority(auth5, "andy");
authorityBridgeTableCache.forceInChangesForThisUncommittedTransaction();
assertEquals(GRP_CNT+5, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
// The next call looks for people not users :-)
@@ -658,6 +664,7 @@ public class AuthorityServiceTest extends TestCase
assertTrue(pubAuthorityService.getContainedAuthorities(null, auth5, false).contains("andy"));
pubAuthorityService.removeAuthority(auth5, "andy");
authorityBridgeTableCache.forceInChangesForThisUncommittedTransaction();
assertEquals(GRP_CNT+5, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
// The next call looks for people not users :-)
@@ -700,12 +707,14 @@ public class AuthorityServiceTest extends TestCase
assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth5 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "five");
pubAuthorityService.addAuthority(auth2, auth5);
authorityBridgeTableCache.forceInChangesForThisUncommittedTransaction();
assertEquals(GRP_CNT+5, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
assertEquals(3, getAllAuthorities(AuthorityType.USER).size());
pubAuthorityService.addAuthority(auth5, "andy");
pubAuthorityService.addAuthority(auth1, "andy");
authorityBridgeTableCache.forceInChangesForThisUncommittedTransaction();
assertEquals(GRP_CNT+5, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
@@ -725,6 +734,7 @@ public class AuthorityServiceTest extends TestCase
assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, false).contains("andy"));
pubAuthorityService.removeAuthority(auth1, "andy");
authorityBridgeTableCache.forceInChangesForThisUncommittedTransaction();
assertEquals(GRP_CNT+5, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
@@ -776,6 +786,7 @@ public class AuthorityServiceTest extends TestCase
checkAuthorityCollectionSize(3, getAllAuthorities(AuthorityType.USER), AuthorityType.USER);
pubAuthorityService.addAuthority(auth5, "andy");
pubAuthorityService.addAuthority(auth1, "andy");
authorityBridgeTableCache.forceInChangesForThisUncommittedTransaction();
assertEquals(GRP_CNT+5, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
@@ -795,6 +806,7 @@ public class AuthorityServiceTest extends TestCase
assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, false).contains("andy"));
pubAuthorityService.addAuthority(auth3, auth2);
authorityBridgeTableCache.forceInChangesForThisUncommittedTransaction();
assertEquals(GRP_CNT+5, getAllAuthorities(AuthorityType.GROUP).size());
@@ -910,6 +922,7 @@ public class AuthorityServiceTest extends TestCase
pubAuthorityService.addAuthority(auth6, "andy1");
pubAuthorityService.addAuthority(auth6, "andy5");
pubAuthorityService.addAuthority(auth6, "andy6");
authorityBridgeTableCache.forceInChangesForThisUncommittedTransaction();
assertEquals(2, pubAuthorityService.getContainedAuthorities(null, auth1, true).size());
assertEquals(11, pubAuthorityService.getContainedAuthorities(null, auth1, false).size());
@@ -1079,6 +1092,8 @@ public class AuthorityServiceTest extends TestCase
String auth6 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "six");
pubAuthorityService.addAuthority(auth6, "an3dy");
authorityBridgeTableCache.forceInChangesForThisUncommittedTransaction();
assertEquals(1, pubAuthorityService.getContainedAuthorities(null, auth1, true).size());
assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, true).contains("1234"));
assertEquals(1, pubAuthorityService.getContainedAuthorities(null, auth2, true).size());