Commit 0006eeb5 authored by Tom Evans's avatar Tom Evans Committed by tevans

OF-588: Add synchronization for cache swap during cluster startup/shutdown

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13382 b35dd754-fafc-0310-a699-88a17e54d16e
parent 70fe97f4
...@@ -381,7 +381,7 @@ public class CacheFactory { ...@@ -381,7 +381,7 @@ public class CacheFactory {
* *
* @param name the name of the cache to destroy. * @param name the name of the cache to destroy.
*/ */
public static void destroyCache(String name) { public static synchronized void destroyCache(String name) {
Cache cache = caches.remove(name); Cache cache = caches.remove(name);
if (cache != null) { if (cache != null) {
if (localOnly.contains(name)) { if (localOnly.contains(name)) {
...@@ -411,7 +411,11 @@ public class CacheFactory { ...@@ -411,7 +411,11 @@ public class CacheFactory {
if (localOnly.contains(cache.getName())) { if (localOnly.contains(cache.getName())) {
return localCacheFactoryStrategy.getLock(key, cache); return localCacheFactoryStrategy.getLock(key, cache);
} else { } else {
return cacheFactoryStrategy.getLock(key, cache); // synchronized here because the backing cache
// will be swapped cluster startup/shutdown (OF-588)
synchronized(cache) {
return cacheFactoryStrategy.getLock(key, cache);
}
} }
} }
...@@ -686,10 +690,12 @@ public class CacheFactory { ...@@ -686,10 +690,12 @@ public class CacheFactory {
for (Cache cache : getAllCaches()) { for (Cache cache : getAllCaches()) {
// skip local-only caches // skip local-only caches
if (localOnly.contains(cache.getName())) continue; if (localOnly.contains(cache.getName())) continue;
cache.clear(); synchronized (cache) {
CacheWrapper cacheWrapper = ((CacheWrapper) cache); cache.clear();
Cache clusteredCache = cacheFactoryStrategy.createCache(cacheWrapper.getName()); CacheWrapper cacheWrapper = ((CacheWrapper) cache);
cacheWrapper.setWrappedCache(clusteredCache); Cache clusteredCache = cacheFactoryStrategy.createCache(cacheWrapper.getName());
cacheWrapper.setWrappedCache(clusteredCache);
}
} }
clusteringStarting = false; clusteringStarting = false;
clusteringStarted = true; clusteringStarted = true;
...@@ -708,10 +714,12 @@ public class CacheFactory { ...@@ -708,10 +714,12 @@ public class CacheFactory {
for (Cache cache : getAllCaches()) { for (Cache cache : getAllCaches()) {
// skip local-only caches // skip local-only caches
if (localOnly.contains(cache.getName())) continue; if (localOnly.contains(cache.getName())) continue;
cache.clear(); synchronized (cache) {
CacheWrapper cacheWrapper = ((CacheWrapper) cache); cache.clear();
Cache standaloneCache = cacheFactoryStrategy.createCache(cacheWrapper.getName()); CacheWrapper cacheWrapper = ((CacheWrapper) cache);
cacheWrapper.setWrappedCache(standaloneCache); Cache standaloneCache = cacheFactoryStrategy.createCache(cacheWrapper.getName());
cacheWrapper.setWrappedCache(standaloneCache);
}
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Error reverting caches to local caches", e); log.error("Error reverting caches to local caches", e);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment