MNT-24708 - Set messagesCache and loadedBundlesCache as local (#3026)

* In a cluster env these caches were always invalidating the other nodes loaded bundles, forcing them to reload
* Only resourceBundlesNamesCache should be invalidating to be able to force the cache reset if a bundle is added, removed or reloaded dynamically
* On unregister of a resource bundle, the cache wasn't being explicitly updated, so it was not invalidating the cache on the other nodes.
This commit is contained in:
Eva Vasques
2024-11-07 18:03:52 +00:00
committed by GitHub
parent e99905efbd
commit 2904535d40
2 changed files with 68 additions and 59 deletions

View File

@@ -205,12 +205,10 @@ public class MessageServiceImpl implements MessageService
if (! tenantResourceBundleBaseNames.contains(resBundlePath)) if (! tenantResourceBundleBaseNames.contains(resBundlePath))
{ {
tenantResourceBundleBaseNames.add(resBundlePath); tenantResourceBundleBaseNames.add(resBundlePath);
putResourceBundleBaseNames(tenantDomain, tenantResourceBundleBaseNames); reloadResourceBundles(tenantResourceBundleBaseNames);
} }
logger.info("Registered message bundle '" + resBundlePath + "'"); logger.info("Registered message bundle '" + resBundlePath + "'");
clearLoadedResourceBundles(tenantDomain); // force re-load of message cache
} }
finally finally
{ {
@@ -290,7 +288,8 @@ public class MessageServiceImpl implements MessageService
Set<String> resourceBundleBaseNamesForAllLocales; Set<String> resourceBundleBaseNamesForAllLocales;
String tenantDomain = getTenantDomain(); String tenantDomain = getTenantDomain();
LockHelper.tryLock(readLock, tryLockTimeout, "getting loaded resource bundles, messages and base names in 'MessageServiceImpl.unregisterResourceBundle()'"); LockHelper.tryLock(readLock, tryLockTimeout,
"getting loaded resource bundles, messages and base names in 'MessageServiceImpl.unregisterResourceBundle()'");
try try
{ {
// all locales // all locales
@@ -303,7 +302,8 @@ public class MessageServiceImpl implements MessageService
readLock.unlock(); readLock.unlock();
} }
LockHelper.tryLock(writeLock, tryLockTimeout, "removing resource bundle by path in 'MessageServiceImpl.unregisterResourceBundle()'"); LockHelper.tryLock(writeLock, tryLockTimeout,
"removing resource bundle by path in 'MessageServiceImpl.unregisterResourceBundle()'");
try try
{ {
// unload resource bundles for each locale (by tenant, if applicable) // unload resource bundles for each locale (by tenant, if applicable)
@@ -342,7 +342,8 @@ public class MessageServiceImpl implements MessageService
} }
catch (IOException ioe) catch (IOException ioe)
{ {
throw new AlfrescoRuntimeException("Failed to read message resource bundle from repository " + resBundlePath + " : " + ioe); throw new AlfrescoRuntimeException("Failed to read message resource bundle from repository "
+ resBundlePath + " : " + ioe);
} }
} }
else else
@@ -372,10 +373,9 @@ public class MessageServiceImpl implements MessageService
if (resourceBundleBaseNamesForAllLocales != null) if (resourceBundleBaseNamesForAllLocales != null)
{ {
resourceBundleBaseNamesForAllLocales.remove(resBundlePath); resourceBundleBaseNamesForAllLocales.remove(resBundlePath);
reloadResourceBundles(resourceBundleBaseNamesForAllLocales);
logger.info("Unregistered message bundle '" + resBundlePath + "'"); logger.info("Unregistered message bundle '" + resBundlePath + "'");
} }
clearLoadedResourceBundles(tenantDomain); // force re-load of message cache
} }
finally finally
{ {
@@ -383,6 +383,14 @@ public class MessageServiceImpl implements MessageService
} }
} }
private void reloadResourceBundles(Set<String> newResourceBundles)
{
logger.debug("Reloading message bundles ...");
String tenantDomain = getTenantDomain();
putResourceBundleBaseNames(tenantDomain, newResourceBundles);
clearLoadedResourceBundles(tenantDomain); // force re-load of message cache
}
/** /**
* Get the messages for a locale. * Get the messages for a locale.
* <p> * <p>
@@ -491,7 +499,8 @@ public class MessageServiceImpl implements MessageService
} }
catch (IOException ioe) catch (IOException ioe)
{ {
throw new AlfrescoRuntimeException("Failed to read message resource bundle from repository " + resBundlePath + " : " + ioe); throw new AlfrescoRuntimeException(
"Failed to read message resource bundle from repository " + resBundlePath + " : " + ioe);
} }
} }
else else

View File

@@ -394,7 +394,7 @@ cache.loadedResourceBundlesSharedCache.tx.statsEnabled=${caches.tx.statsEnabled}
cache.loadedResourceBundlesSharedCache.maxItems=1000 cache.loadedResourceBundlesSharedCache.maxItems=1000
cache.loadedResourceBundlesSharedCache.timeToLiveSeconds=0 cache.loadedResourceBundlesSharedCache.timeToLiveSeconds=0
cache.loadedResourceBundlesSharedCache.maxIdleSeconds=0 cache.loadedResourceBundlesSharedCache.maxIdleSeconds=0
cache.loadedResourceBundlesSharedCache.cluster.type=invalidating cache.loadedResourceBundlesSharedCache.cluster.type=local
cache.loadedResourceBundlesSharedCache.backup-count=1 cache.loadedResourceBundlesSharedCache.backup-count=1
cache.loadedResourceBundlesSharedCache.eviction-policy=LRU cache.loadedResourceBundlesSharedCache.eviction-policy=LRU
cache.loadedResourceBundlesSharedCache.merge-policy=com.hazelcast.spi.merge.PutIfAbsentMergePolicy cache.loadedResourceBundlesSharedCache.merge-policy=com.hazelcast.spi.merge.PutIfAbsentMergePolicy
@@ -405,7 +405,7 @@ cache.messagesSharedCache.tx.statsEnabled=${caches.tx.statsEnabled}
cache.messagesSharedCache.maxItems=1000 cache.messagesSharedCache.maxItems=1000
cache.messagesSharedCache.timeToLiveSeconds=0 cache.messagesSharedCache.timeToLiveSeconds=0
cache.messagesSharedCache.maxIdleSeconds=0 cache.messagesSharedCache.maxIdleSeconds=0
cache.messagesSharedCache.cluster.type=invalidating cache.messagesSharedCache.cluster.type=local
cache.messagesSharedCache.backup-count=1 cache.messagesSharedCache.backup-count=1
cache.messagesSharedCache.eviction-policy=LRU cache.messagesSharedCache.eviction-policy=LRU
cache.messagesSharedCache.merge-policy=com.hazelcast.spi.merge.PutIfAbsentMergePolicy cache.messagesSharedCache.merge-policy=com.hazelcast.spi.merge.PutIfAbsentMergePolicy