Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud)

69946: Merged V4.2-BUG-FIX (4.2.3) to HEAD-BUG-FIX (4.3/Cloud)
      69860: MNT-11371: Alfresco unable to bootstrap due to LockTryExceptions following an upgrade from 3.4.8 -> 3.4.13 -> 4.0.2 to either 4.1.8 or 4.2.1
      Merged 4.1.N to V4.2.N (4.2.3)
         69848: MNT-11371: Alfresco unable to bootstrap due to LockTryExceptions following an upgrade from 3.4.8 -> 3.4.13 -> 4.0.2 to either 4.1.8 or 4.2.1
           Ability to configure try lock timeout for several different contexts has been implemented. New configuration for every context has been added:
           - system.lockTryTimeout=100
           - system.lockTryTimeout.DictionaryDAOImpl=2000
           - system.lockTryTimeout.MessageServiceImpl=${system.lockTryTimeout}
            - system.lockTryTimeout.PolicyComponentImpl=${system.lockTryTimeout}
           'LockHelper.tryLock()' has been modified to accept additional string 'useCase' parameter. Parameter is used for throwing exceptions with contextual messages when lock is not acquired
         69858: MNT-11371: Alfresco unable to bootstrap due to LockTryExceptions following an upgrade from 3.4.8 -> 3.4.13 -> 4.0.2 to either 4.1.8 or 4.2.1
           Additional boolean parameter 'haveWriteLock' has been added to 'MessageServiceImpl.getResourceBundleBaseNames()' method. It serves to avoid unlocking external write locks. The method still assumes that read lock is acquired if 'haveWriteLock=false'. Read lock will be upgraded to write lock only if 'haveWriteLock' parameter is equal to false


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@70462 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2014-05-16 20:06:48 +00:00
parent dab8858288
commit c505322c35
10 changed files with 104 additions and 45 deletions

View File

@@ -502,6 +502,9 @@
<property name="messagesCache">
<ref bean="messagesCache"/>
</property>
<property name="tryLockTimeout">
<value>${system.lockTryTimeout.MessageServiceImpl}</value>
</property>
</bean>
<!-- -->
@@ -732,6 +735,9 @@
<property name="defaultAnalyserResourceBundleName">
<value>${lucene.defaultAnalyserResourceBundleName}</value>
</property>
<property name="tryLockTimeout">
<value>${system.lockTryTimeout.DictionaryDAOImpl}</value>
</property>
</bean>
<bean id="dictionaryService" class="org.alfresco.repo.dictionary.DictionaryComponent" depends-on="dictionaryBootstrap">

View File

@@ -44,6 +44,9 @@
<property name="transactionInvocationHandlerFactory">
<ref bean="policyTransactionHandlerFactory"/>
</property>
<property name="tryLockTimeout">
<value>${system.lockTryTimeout.PolicyComponentImpl}</value>
</property>
</bean>
<bean id="policyRegistration" abstract="true" init-method="register">

View File

@@ -1092,3 +1092,11 @@ system.cronJob.startDelayMinutes=1
# Enable transformation retrying if the file has MIME type differ than file extension.
#
content.transformer.retryOn.different.mimetype=true
#
# Lock timeout configuration
#
system.lockTryTimeout=100
system.lockTryTimeout.DictionaryDAOImpl=2000
system.lockTryTimeout.MessageServiceImpl=${system.lockTryTimeout}
system.lockTryTimeout.PolicyComponentImpl=${system.lockTryTimeout}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2013 Alfresco Software Limited.
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -86,6 +86,9 @@ public class MessageServiceImpl implements MessageService
private NamespaceService namespaceService;
private NodeService nodeService;
// Try lock timeout (MNT-11371)
private long tryLockTimeout;
/**
* List of registered bundles
*/
@@ -139,6 +142,11 @@ public class MessageServiceImpl implements MessageService
this.messagesCache = messagesCache;
}
public void setTryLockTimeout(long tryLockTimeout)
{
this.tryLockTimeout = tryLockTimeout;
}
public void setLocale(Locale locale)
{
I18NUtil.setLocale(locale);
@@ -173,7 +181,7 @@ public class MessageServiceImpl implements MessageService
{
String tenantDomain = getTenantDomain();
Set<String> tenantResourceBundleBaseNames = null;
LockHelper.tryLock(readLock, 100);
LockHelper.tryLock(readLock, tryLockTimeout, "getting resource bundle base names in 'MessageServiceImpl.registerResourceBundle()'");
try
{
tenantResourceBundleBaseNames = getResourceBundleBaseNames(tenantDomain);
@@ -183,7 +191,7 @@ public class MessageServiceImpl implements MessageService
readLock.unlock();
}
LockHelper.tryLock(writeLock, 100);
LockHelper.tryLock(writeLock, tryLockTimeout, "adding new resource bundle path and clearing loaded resource bundles in 'MessageServiceImpl.registerResourceBundle()'");
try
{
if (! tenantResourceBundleBaseNames.contains(resBundlePath))
@@ -273,7 +281,7 @@ public class MessageServiceImpl implements MessageService
Set<String> resourceBundleBaseNamesForAllLocales;
String tenantDomain = getTenantDomain();
LockHelper.tryLock(readLock, 100);
LockHelper.tryLock(readLock, tryLockTimeout, "getting loaded resource bundles, messages and base names in 'MessageServiceImpl.unregisterResourceBundle()'");
try
{
// all locales
@@ -286,7 +294,7 @@ public class MessageServiceImpl implements MessageService
readLock.unlock();
}
LockHelper.tryLock(writeLock, 100);
LockHelper.tryLock(writeLock, tryLockTimeout, "removing resource bundle by path in 'MessageServiceImpl.unregisterResourceBundle()'");
try
{
// unload resource bundles for each locale (by tenant, if applicable)
@@ -388,7 +396,7 @@ public class MessageServiceImpl implements MessageService
Map<Locale, Map<String, String>> tenantCachedMessages = null;
Set<String> tenantResourceBundleBaseNames = null;
LockHelper.tryLock(readLock, 100);
LockHelper.tryLock(readLock, tryLockTimeout, "getting loaded resource bundles, messages and base names in 'MessageServiceImpl.getLocaleProperties()'");
try
{
tenantLoadedResourceBundles = getLoadedResourceBundles(tenantDomain);
@@ -407,7 +415,7 @@ public class MessageServiceImpl implements MessageService
if (loadedBundles == null)
{
LockHelper.tryLock(writeLock, 100);
LockHelper.tryLock(writeLock, tryLockTimeout, "adding resource bundle for locale in 'MessageServiceImpl.getLocaleProperties()'");
try
{
loadedBundles = new HashSet<String>();
@@ -422,7 +430,8 @@ public class MessageServiceImpl implements MessageService
if (props == null)
{
LockHelper.tryLock(writeLock, 100);
LockHelper.tryLock(writeLock, tryLockTimeout,
"adding resource bundle properties into the cache (because properties are not cached) in 'MessageServiceImpl.getLocaleProperties()'");
try
{
props = new HashMap<String, String>();
@@ -437,7 +446,8 @@ public class MessageServiceImpl implements MessageService
if ((loadedBundles.size() != loadedBundleCount) || (init == true))
{
LockHelper.tryLock(writeLock, 100);
LockHelper.tryLock(writeLock, tryLockTimeout,
"searching resource bundle and adding new resource bundle for locale if the bundle is not found in 'MessageServiceImpl.getLocaleProperties()'");
try
{
// get registered resource bundles
@@ -582,7 +592,7 @@ public class MessageServiceImpl implements MessageService
public Set<String> getRegisteredBundles()
{
LockHelper.tryLock(readLock, 100);
LockHelper.tryLock(readLock, tryLockTimeout, "getting resource bundle base names in 'MessageServiceImpl.getRegisteredBundles()'");
try
{
return getResourceBundleBaseNames(getTenantDomain());
@@ -604,7 +614,7 @@ public class MessageServiceImpl implements MessageService
// They are not there. Upgrade to the write lock.
readLock.unlock();
LockHelper.tryLock(writeLock, 100);
LockHelper.tryLock(writeLock, tryLockTimeout, "getting cached resource bundle base names by tenant domain in 'MessageServiceImpl.getRegisteredBundles()'");
try
{
resourceBundleBaseNames = resourceBundleBaseNamesCache.get(tenantDomain);
@@ -618,7 +628,7 @@ public class MessageServiceImpl implements MessageService
finally
{
writeLock.unlock();
LockHelper.tryLock(readLock, 100);
LockHelper.tryLock(readLock, tryLockTimeout, "upgrading to read lock in MessageServiceImpl.getResourceBundleBaseNames()");
}
if (resourceBundleBaseNames == null)
@@ -655,7 +665,7 @@ public class MessageServiceImpl implements MessageService
// Not present. Upgrade to write lock.
readLock.unlock();
LockHelper.tryLock(writeLock, 100);
LockHelper.tryLock(writeLock, tryLockTimeout, "getting cached resource bundle by tenant domain in 'MessageServiceImpl.getLoadedResourceBundles()'");
try
{
loadedResourceBundles = loadedResourceBundlesCache.get(tenantDomain);
@@ -669,7 +679,7 @@ public class MessageServiceImpl implements MessageService
finally
{
writeLock.unlock();
LockHelper.tryLock(readLock, 100);
LockHelper.tryLock(readLock, tryLockTimeout, "upgrading to read lock in MessageServiceImpl.getLoadedResourceBundles()");
}
if (loadedResourceBundles == null)
@@ -714,7 +724,7 @@ public class MessageServiceImpl implements MessageService
// Need to create it. Upgrade to write lock.
readLock.unlock();
LockHelper.tryLock(writeLock, 100);
LockHelper.tryLock(writeLock, tryLockTimeout, "getting messages by tenant domain from the cache in 'MessageServiceImpl.getMessages()'");
try
{
messages = messagesCache.get(tenantDomain);
@@ -728,7 +738,7 @@ public class MessageServiceImpl implements MessageService
finally
{
writeLock.unlock();
LockHelper.tryLock(readLock, 100);
LockHelper.tryLock(readLock, tryLockTimeout, "upgrading to read lock in MessageServiceImpl.getMessages()");
}
if (messages == null)

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -52,7 +52,7 @@ public class AssociationPolicyDelegate<P extends AssociationPolicy>
* @param index the behaviour index to query against
*/
@SuppressWarnings("unchecked")
/*package*/ AssociationPolicyDelegate(DictionaryService dictionary, Class<P> policyClass, BehaviourIndex<ClassFeatureBehaviourBinding> index)
/*package*/ AssociationPolicyDelegate(DictionaryService dictionary, Class<P> policyClass, BehaviourIndex<ClassFeatureBehaviourBinding> index, long tryLockTimeout)
{
// Get list of all pre-registered behaviours for the policy and
// ensure they are valid.
@@ -65,6 +65,7 @@ public class AssociationPolicyDelegate<P extends AssociationPolicy>
// Rely on cached implementation of policy factory
// Note: Could also use PolicyFactory (without caching)
this.factory = new CachedPolicyFactory<ClassFeatureBehaviourBinding, P>(policyClass, index);
this.factory.setTryLockTimeout(tryLockTimeout);
this.dictionary = dictionary;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2013 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -59,6 +59,15 @@ import org.apache.commons.logging.LogFactory;
*/
private Map<B, Collection<P>> listCache = new HashMap<B, Collection<P>>();
// Try lock timeout (MNT-11371)
private long tryLockTimeout;
public void setTryLockTimeout(long tryLockTimeout)
{
this.tryLockTimeout = tryLockTimeout;
}
/**
* Construct cached policy factory
@@ -93,7 +102,7 @@ import org.apache.commons.logging.LogFactory;
return super.create(binding);
}
LockHelper.tryLock(lock.readLock(), 100);
LockHelper.tryLock(lock.readLock(), tryLockTimeout, "getting policy from cache in 'CachedPolicyFactory.create()'");
try
{
P policyInterface = singleCache.get(binding);
@@ -108,7 +117,7 @@ import org.apache.commons.logging.LogFactory;
}
// There wasn't one
LockHelper.tryLock(lock.writeLock(), 100);
LockHelper.tryLock(lock.writeLock(), tryLockTimeout, "putting new policy to cache in 'CachedPolicyFactory.create()'");
try
{
P policyInterface = singleCache.get(binding);
@@ -140,7 +149,7 @@ import org.apache.commons.logging.LogFactory;
return super.createList(binding);
}
LockHelper.tryLock(lock.readLock(), 100);
LockHelper.tryLock(lock.readLock(), tryLockTimeout, "getting policy list from cache in 'CachedPolicyFactory.createList()'");
try
{
Collection<P> policyInterfaces = listCache.get(binding);
@@ -155,7 +164,7 @@ import org.apache.commons.logging.LogFactory;
}
// There wasn't one
LockHelper.tryLock(lock.writeLock(), 100);
LockHelper.tryLock(lock.writeLock(), tryLockTimeout, "putting policy list to cache in 'CachedPolicyFactory.createList()'");
try
{
Collection<P> policyInterfaces = listCache.get(binding);
@@ -188,7 +197,7 @@ import org.apache.commons.logging.LogFactory;
{
if (binding == null)
{
LockHelper.tryLock(lock.writeLock(), 100);
LockHelper.tryLock(lock.writeLock(), tryLockTimeout, "clearing policy cache in 'CachedPolicyFactory.clearCache()'");
try
{
// A specific binding has not been provided, so clear all entries
@@ -226,7 +235,7 @@ import org.apache.commons.logging.LogFactory;
// Remove all invalid bindings
if (invalidBindings.size() > 0)
{
LockHelper.tryLock(lock.writeLock(), 100);
LockHelper.tryLock(lock.writeLock(), tryLockTimeout, "removing invalid policy bindings from cache in 'CachedPolicyFactory.clearCache()'");
try
{
for (B invalidBinding : invalidBindings)

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -53,6 +53,14 @@ import org.alfresco.util.LockHelper;
// Behaviour Filter
private BehaviourFilter filter = null;
// Try lock timeout (MNT-11371)
private long tryLockTimeout;
public void setTryLockTimeout(long tryLockTimeout)
{
this.tryLockTimeout = tryLockTimeout;
}
/**
* Construct.
@@ -92,7 +100,7 @@ import org.alfresco.util.LockHelper;
@Override
public Collection<BehaviourDefinition> getAll()
{
LockHelper.tryLock(lock.readLock(), 100);
LockHelper.tryLock(lock.readLock(), tryLockTimeout, "getting all behavior definitions in 'ClassBehaviourIndex.getAll()'");
try
{
@@ -112,7 +120,7 @@ import org.alfresco.util.LockHelper;
@SuppressWarnings("unchecked")
public Collection<BehaviourDefinition> find(B binding)
{
LockHelper.tryLock(lock.readLock(), 100);
LockHelper.tryLock(lock.readLock(), tryLockTimeout, "searching behavior definitions list in 'ClassBehaviourIndex.find()'");
try
{
@@ -175,7 +183,7 @@ import org.alfresco.util.LockHelper;
*/
public void putClassBehaviour(BehaviourDefinition<B> behaviour)
{
LockHelper.tryLock(lock.writeLock(), 100);
LockHelper.tryLock(lock.writeLock(), tryLockTimeout, "putting behavior definition in 'ClassBehaviourIndex.putClassBehavior()'");
try
{
classMap.put(behaviour);
@@ -194,7 +202,7 @@ import org.alfresco.util.LockHelper;
*/
public void putServiceBehaviour(BehaviourDefinition<ServiceBehaviourBinding> behaviour)
{
LockHelper.tryLock(lock.writeLock(), 100);
LockHelper.tryLock(lock.writeLock(), tryLockTimeout, "putting behavior definition in 'ClassBehaviourIndex.putServiceBehavior()'");
try
{
serviceMap.put(behaviour);
@@ -212,7 +220,7 @@ import org.alfresco.util.LockHelper;
*/
public void removeClassBehaviour(BehaviourDefinition<B> behaviour)
{
LockHelper.tryLock(lock.writeLock(), 100);
LockHelper.tryLock(lock.writeLock(), tryLockTimeout, "removing behavior definition in 'ClassBehaviourIndex.removeClassBehavior()'");
try
{
classMap.remove(behaviour);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -51,7 +51,7 @@ public class ClassPolicyDelegate<P extends ClassPolicy>
* @param index the behaviour index to query against
*/
@SuppressWarnings("unchecked")
/*package*/ ClassPolicyDelegate(DictionaryService dictionary, Class<P> policyClass, BehaviourIndex<ClassBehaviourBinding> index)
/*package*/ ClassPolicyDelegate(DictionaryService dictionary, Class<P> policyClass, BehaviourIndex<ClassBehaviourBinding> index, long tryLockTimeout)
{
// Get list of all pre-registered behaviours for the policy and
// ensure they are valid.
@@ -64,6 +64,7 @@ public class ClassPolicyDelegate<P extends ClassPolicy>
// Rely on cached implementation of policy factory
// Note: Could also use PolicyFactory (without caching)
this.factory = new CachedPolicyFactory<ClassBehaviourBinding, P>(policyClass, index);
this.factory.setTryLockTimeout(tryLockTimeout);
this.dictionary = dictionary;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -74,6 +74,14 @@ public class PolicyComponentImpl implements PolicyComponent
// Wild Card Feature
private static final QName FEATURE_WILDCARD = QName.createQName(NamespaceService.DEFAULT_URI, "*");
// Try lock timeout (MNT-11371)
private long tryLockTimeout;
public void setTryLockTimeout(long tryLockTimeout)
{
this.tryLockTimeout = tryLockTimeout;
}
/**
* Construct
@@ -129,7 +137,8 @@ public class PolicyComponentImpl implements PolicyComponent
ParameterCheck.mandatory("Policy interface class", policy);
PolicyDefinition definition = createPolicyDefinition(policy);
registeredPolicies.put(new PolicyKey(definition.getType(), definition.getName()), definition);
ClassPolicyDelegate<P> delegate = new ClassPolicyDelegate<P>(dictionary, policy, getClassBehaviourIndex(definition.getName()));
ClassPolicyDelegate<P> delegate = new ClassPolicyDelegate<P>(dictionary, policy, getClassBehaviourIndex(definition.getName()), tryLockTimeout);
if (logger.isInfoEnabled())
logger.info("Registered class policy " + definition.getName() + " (" + definition.getPolicyInterface() + ")");
@@ -152,7 +161,7 @@ public class PolicyComponentImpl implements PolicyComponent
ParameterCheck.mandatory("Policy interface class", policy);
PolicyDefinition definition = createPolicyDefinition(policy);
registeredPolicies.put(new PolicyKey(definition.getType(), definition.getName()), definition);
PropertyPolicyDelegate<P> delegate = new PropertyPolicyDelegate<P>(dictionary, policy, getPropertyBehaviourIndex(definition.getName()));
PropertyPolicyDelegate<P> delegate = new PropertyPolicyDelegate<P>(dictionary, policy, getPropertyBehaviourIndex(definition.getName()), tryLockTimeout);
if (logger.isInfoEnabled())
logger.info("Registered property policy " + definition.getName() + " (" + definition.getPolicyInterface() + ")");
@@ -170,7 +179,7 @@ public class PolicyComponentImpl implements PolicyComponent
ParameterCheck.mandatory("Policy interface class", policy);
PolicyDefinition definition = createPolicyDefinition(policy);
registeredPolicies.put(new PolicyKey(definition.getType(), definition.getName()), definition);
AssociationPolicyDelegate<P> delegate = new AssociationPolicyDelegate<P>(dictionary, policy, getAssociationBehaviourIndex(definition.getName()));
AssociationPolicyDelegate<P> delegate = new AssociationPolicyDelegate<P>(dictionary, policy, getAssociationBehaviourIndex(definition.getName()), tryLockTimeout);
if (logger.isInfoEnabled())
logger.info("Registered association policy " + definition.getName() + " (" + definition.getPolicyInterface() + ")");
@@ -431,6 +440,7 @@ public class PolicyComponentImpl implements PolicyComponent
if (index == null)
{
index = new ClassBehaviourIndex<ClassBehaviourBinding>(behaviourFilter);
index.setTryLockTimeout(tryLockTimeout);
classBehaviours.put(policy, index);
}
return index;
@@ -449,6 +459,7 @@ public class PolicyComponentImpl implements PolicyComponent
if (index == null)
{
index = new ClassBehaviourIndex<ClassFeatureBehaviourBinding>(behaviourFilter);
index.setTryLockTimeout(tryLockTimeout);
propertyBehaviours.put(policy, index);
}
return index;
@@ -467,6 +478,7 @@ public class PolicyComponentImpl implements PolicyComponent
if (index == null)
{
index = new ClassBehaviourIndex<ClassFeatureBehaviourBinding>(behaviourFilter);
index.setTryLockTimeout(tryLockTimeout);
associationBehaviours.put(policy, index);
}
return index;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -52,7 +52,7 @@ public class PropertyPolicyDelegate<P extends PropertyPolicy>
* @param index the behaviour index to query against
*/
@SuppressWarnings("unchecked")
/*package*/ PropertyPolicyDelegate(DictionaryService dictionary, Class<P> policyClass, BehaviourIndex<ClassFeatureBehaviourBinding> index)
/*package*/ PropertyPolicyDelegate(DictionaryService dictionary, Class<P> policyClass, BehaviourIndex<ClassFeatureBehaviourBinding> index, long tryLockTimeout)
{
// Get list of all pre-registered behaviours for the policy and
// ensure they are valid.
@@ -65,6 +65,7 @@ public class PropertyPolicyDelegate<P extends PropertyPolicy>
// Rely on cached implementation of policy factory
// Note: Could also use PolicyFactory (without caching)
this.factory = new CachedPolicyFactory<ClassFeatureBehaviourBinding, P>(policyClass, index);
this.factory.setTryLockTimeout(tryLockTimeout);
this.dictionary = dictionary;
}