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,9 +411,13 @@ public class CacheFactory { ...@@ -411,9 +411,13 @@ 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 {
// synchronized here because the backing cache
// will be swapped cluster startup/shutdown (OF-588)
synchronized(cache) {
return cacheFactoryStrategy.getLock(key, cache); return cacheFactoryStrategy.getLock(key, cache);
} }
} }
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static <T extends Cache> T wrapCache(T cache, String name) { private static <T extends Cache> T wrapCache(T cache, String name) {
...@@ -686,11 +690,13 @@ public class CacheFactory { ...@@ -686,11 +690,13 @@ 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;
synchronized (cache) {
cache.clear(); cache.clear();
CacheWrapper cacheWrapper = ((CacheWrapper) cache); CacheWrapper cacheWrapper = ((CacheWrapper) cache);
Cache clusteredCache = cacheFactoryStrategy.createCache(cacheWrapper.getName()); Cache clusteredCache = cacheFactoryStrategy.createCache(cacheWrapper.getName());
cacheWrapper.setWrappedCache(clusteredCache); cacheWrapper.setWrappedCache(clusteredCache);
} }
}
clusteringStarting = false; clusteringStarting = false;
clusteringStarted = true; clusteringStarted = true;
} }
...@@ -708,11 +714,13 @@ public class CacheFactory { ...@@ -708,11 +714,13 @@ 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;
synchronized (cache) {
cache.clear(); cache.clear();
CacheWrapper cacheWrapper = ((CacheWrapper) cache); CacheWrapper cacheWrapper = ((CacheWrapper) cache);
Cache standaloneCache = cacheFactoryStrategy.createCache(cacheWrapper.getName()); Cache standaloneCache = cacheFactoryStrategy.createCache(cacheWrapper.getName());
cacheWrapper.setWrappedCache(standaloneCache); 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