ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject [14/25] ignite git commit: IGNITE-5843 Persist cache configuration received on node join - Fixes #2347.
Date Wed, 16 Aug 2017 15:41:37 GMT
IGNITE-5843 Persist cache configuration received on node join - Fixes #2347.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/5cb5dcaf
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/5cb5dcaf
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/5cb5dcaf

Branch: refs/heads/ignite-5901
Commit: 5cb5dcaf2b773fb6397881147e9e6a4e0b11f0a8
Parents: 81195db
Author: EdShangGG <eshangareev@gridgain.com>
Authored: Mon Aug 14 16:56:11 2017 +0300
Committer: Alexey Goncharuk <alexey.goncharuk@gmail.com>
Committed: Mon Aug 14 17:01:46 2017 +0300

----------------------------------------------------------------------
 .../cache/CacheAffinitySharedManager.java       | 56 +++++++++++++++-----
 .../GridCacheDatabaseSharedManager.java         | 15 +++---
 .../persistence/file/FilePageStoreManager.java  |  1 -
 .../processors/query/GridQueryProcessor.java    | 15 ------
 .../persistence/IgnitePdsDynamicCacheTest.java  | 43 +++++++++++++++
 5 files changed, 92 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/5cb5dcaf/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
index 5d573b2..d476091 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
@@ -731,13 +731,6 @@ public class CacheAffinitySharedManager<K, V> extends GridCacheSharedManagerAdap
             }
 
             try {
-                // Save configuration before cache started.
-                if (cctx.pageStore() != null && !cctx.kernalContext().clientNode())
{
-                    cctx.pageStore().storeCacheData(
-                        new StoredCacheData(req.startCacheConfiguration())
-                    );
-                }
-
                 if (startCache) {
                     cctx.cache().prepareCacheStart(req.startCacheConfiguration(),
                         cacheDesc,
@@ -2189,7 +2182,7 @@ public class CacheAffinitySharedManager<K, V> extends GridCacheSharedManagerAdap
     /**
      *
      */
-    static class CachesInfo {
+    class CachesInfo {
         /** Registered cache groups (updated from exchange thread). */
         private final ConcurrentHashMap<Integer, CacheGroupDescriptor> registeredGrps
= new ConcurrentHashMap<>();
 
@@ -2202,10 +2195,29 @@ public class CacheAffinitySharedManager<K, V> extends GridCacheSharedManagerAdap
          */
         void init(Map<Integer, CacheGroupDescriptor> grps, Map<String, DynamicCacheDescriptor>
caches) {
             for (CacheGroupDescriptor grpDesc : grps.values())
-                registeredGrps.put(grpDesc.groupId(), grpDesc);
+                registerGroup(grpDesc);
 
             for (DynamicCacheDescriptor cacheDesc : caches.values())
-                registeredCaches.put(cacheDesc.cacheId(), cacheDesc);
+                registerCache(cacheDesc);
+        }
+
+
+        /**
+         * @param desc Description.
+         */
+        private DynamicCacheDescriptor registerCache(DynamicCacheDescriptor desc) {
+            saveCacheConfiguration(desc.cacheConfiguration());
+
+            return registeredCaches.put(desc.cacheId(), desc);
+        }
+
+        /**
+         * @param grpDesc Group description.
+         */
+        private CacheGroupDescriptor registerGroup(CacheGroupDescriptor grpDesc) {
+            saveCacheConfiguration(grpDesc.config());
+
+            return registeredGrps.put(grpDesc.groupId(), grpDesc);
         }
 
         /**
@@ -2235,10 +2247,10 @@ public class CacheAffinitySharedManager<K, V> extends GridCacheSharedManagerAdap
                 CacheGroupDescriptor grpDesc = desc.groupDescriptor();
 
                 if (!registeredGrps.containsKey(grpDesc.groupId()))
-                    registeredGrps.put(grpDesc.groupId(), grpDesc);
+                    registerGroup(grpDesc);
 
                 if (!registeredCaches.containsKey(desc.cacheId()))
-                    registeredCaches.put(desc.cacheId(), desc);
+                    registerCache(desc);
             }
         }
 
@@ -2253,7 +2265,7 @@ public class CacheAffinitySharedManager<K, V> extends GridCacheSharedManagerAdap
             }
 
             for (ExchangeActions.CacheGroupActionData startAction : exchActions.cacheGroupsToStart())
{
-                CacheGroupDescriptor old = registeredGrps.put(startAction.descriptor().groupId(),
startAction.descriptor());
+                CacheGroupDescriptor old = registerGroup(startAction.descriptor());
 
                 assert old == null : old;
             }
@@ -2262,7 +2274,7 @@ public class CacheAffinitySharedManager<K, V> extends GridCacheSharedManagerAdap
                 registeredCaches.remove(req.descriptor().cacheId());
 
             for (ExchangeActions.CacheActionData req : exchActions.cacheStartRequests())
-                registeredCaches.put(req.descriptor().cacheId(), req.descriptor());
+                registerCache(req.descriptor());
         }
 
         /**
@@ -2282,4 +2294,20 @@ public class CacheAffinitySharedManager<K, V> extends GridCacheSharedManagerAdap
             registeredCaches.clear();
         }
     }
+
+    /**
+     * @param cfg cache configuration
+     */
+    private void saveCacheConfiguration(CacheConfiguration<?, ?> cfg) {
+        if (cctx.pageStore() != null && cctx.database().persistenceEnabled() &&
!cctx.kernalContext().clientNode()) {
+            try {
+                cctx.pageStore().storeCacheData(
+                    new StoredCacheData(cfg)
+                );
+            }
+            catch (IgniteCheckedException e) {
+                U.error(log(), "Error while saving cache configuration on disk, cfg = " +
cfg, e);
+            }
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/5cb5dcaf/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java
index eb6cb32..99e05dd 100755
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java
@@ -56,9 +56,6 @@ import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-import javax.management.InstanceNotFoundException;
-import javax.management.JMException;
-import javax.management.MBeanRegistrationException;
 import javax.management.ObjectName;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
@@ -98,6 +95,7 @@ import org.apache.ignite.internal.pagemem.wal.record.delta.PartitionDestroyRecor
 import org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRecord;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.CacheGroupContext;
+import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor;
 import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
@@ -1453,11 +1451,12 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan
         // TODO IGNITE-5075: cache descriptor can be removed.
         GridCacheSharedContext sharedCtx = context();
 
-        String memPlcName = sharedCtx
-            .cache()
-            .cacheGroupDescriptors().get(grpId)
-            .config()
-            .getMemoryPolicyName();
+        CacheGroupDescriptor desc = sharedCtx.cache().cacheGroupDescriptors().get(grpId);
+
+        if (desc == null)
+            throw new IgniteCheckedException("Failed to find cache group descriptor [grpId="
+ grpId + ']');
+
+        String memPlcName = desc.config().getMemoryPolicyName();
 
         return (PageMemoryEx)sharedCtx.database().memoryPolicy(memPlcName).pageMemory();
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/5cb5dcaf/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java
index 0041ea6..13bcd2a 100755
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java
@@ -210,7 +210,6 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter
implemen
     @Override public void storeCacheData(
         StoredCacheData cacheData
     ) throws IgniteCheckedException {
-
         File cacheWorkDir = cacheWorkDirectory(cacheData.config());
         File file;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/5cb5dcaf/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index d44be2c..baafb1e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
@@ -504,21 +504,6 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
                 if (cacheDesc != null && F.eq(cacheDesc.deploymentId(), proposeMsg.deploymentId()))
                     cacheDesc.schemaChangeFinish(msg);
-
-                if (ctx.cache().context().pageStore() != null &&
-                    ctx.cache().context().database().persistenceEnabled()) {
-
-                    StoredCacheData cacheData = new StoredCacheData(cacheDesc.cacheConfiguration());
-
-                    cacheData.queryEntities(cacheDesc.schema().entities());
-
-                    try {
-                        ctx.cache().context().pageStore().storeCacheData(cacheData);
-                    }
-                    catch (IgniteCheckedException e) {
-                        throw new IllegalStateException("Failed to persist cache data: "
+ cacheData.config().getName(), e);
-                    }
-                }
             }
 
             // Propose message will be used from exchange thread to

http://git-wip-us.apache.org/repos/asf/ignite/blob/5cb5dcaf/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsDynamicCacheTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsDynamicCacheTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsDynamicCacheTest.java
index 189b866..5873a35 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsDynamicCacheTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsDynamicCacheTest.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.cache.persistence;
 
 import java.io.Serializable;
 import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.cache.CacheAtomicityMode;
 import org.apache.ignite.cache.CacheMode;
@@ -160,6 +161,48 @@ public class IgnitePdsDynamicCacheTest extends IgniteDbDynamicCacheSelfTest
{
     }
 
     /**
+     * @throws Exception If failed.
+     */
+    public void testDynamicCacheSavingOnNewNode() throws Exception {
+        Ignite ignite = startGrid(0);
+
+        ignite.active(true);
+
+        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
+
+        ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
+        ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
+        ccfg.setRebalanceMode(CacheRebalanceMode.SYNC);
+        ccfg.setAffinity(new RendezvousAffinityFunction(false, 32));
+
+        IgniteCache cache = ignite.getOrCreateCache(ccfg);
+
+        for (int i = 0; i < 160; i++)
+            cache.put(i, i);
+
+        ignite = startGrid(1);
+
+        awaitPartitionMapExchange();
+
+        cache = ignite.cache(DEFAULT_CACHE_NAME);
+
+        for (int i = 0; i < 160; i++)
+            assertEquals(i, cache.get(i));
+
+        stopAllGrids(true);
+
+        startGrid(0);
+        ignite = startGrid(1);
+
+        ignite.active(true);
+
+        cache = ignite.cache(DEFAULT_CACHE_NAME);
+
+        for (int i = 0; i < 160; i++)
+            assertEquals(i, cache.get(i));
+    }
+
+    /**
      * @throws IgniteCheckedException If failed.
      */
     private void deleteWorkFiles() throws IgniteCheckedException {


Mime
View raw message