Commit 18af4f0b authored by Tom Evans's avatar Tom Evans

OF-974: Migrate cache content

When switch to/from clustered deployment, ensure that critical cached
items such as components and remote servers are not inadvertently
dropped from the cache.
parent 5df5dab9
...@@ -732,12 +732,13 @@ public class CacheFactory { ...@@ -732,12 +732,13 @@ public class CacheFactory {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static synchronized void joinedCluster() { public static synchronized void joinedCluster() {
cacheFactoryStrategy = clusteredCacheFactoryStrategy; cacheFactoryStrategy = clusteredCacheFactoryStrategy;
// Loop through local caches and switch them to clustered cache (purge content) // Loop through local caches and switch them to clustered cache (copy content)
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;
CacheWrapper cacheWrapper = ((CacheWrapper) cache); CacheWrapper cacheWrapper = ((CacheWrapper) cache);
Cache clusteredCache = cacheFactoryStrategy.createCache(cacheWrapper.getName()); Cache clusteredCache = cacheFactoryStrategy.createCache(cacheWrapper.getName());
clusteredCache.putAll(cache);
cacheWrapper.setWrappedCache(clusteredCache); cacheWrapper.setWrappedCache(clusteredCache);
} }
clusteringStarting = false; clusteringStarting = false;
...@@ -753,12 +754,13 @@ public class CacheFactory { ...@@ -753,12 +754,13 @@ public class CacheFactory {
clusteringStarted = false; clusteringStarted = false;
cacheFactoryStrategy = localCacheFactoryStrategy; cacheFactoryStrategy = localCacheFactoryStrategy;
// Loop through clustered caches and change them to local caches (purge content) // Loop through clustered caches and change them to local caches (copy content)
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;
CacheWrapper cacheWrapper = ((CacheWrapper) cache); CacheWrapper cacheWrapper = ((CacheWrapper) cache);
Cache standaloneCache = cacheFactoryStrategy.createCache(cacheWrapper.getName()); Cache standaloneCache = cacheFactoryStrategy.createCache(cacheWrapper.getName());
standaloneCache.putAll(cache);
cacheWrapper.setWrappedCache(standaloneCache); cacheWrapper.setWrappedCache(standaloneCache);
} }
log.info("Clustering stopped; cache migration complete"); log.info("Clustering stopped; cache migration complete");
......
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