ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject [1/2] ignite git commit: IGNITE-3305 - Fixed SYNC rebalance mode for dynamically started cache.
Date Tue, 14 Jun 2016 20:06:20 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 3c10b691c -> ec005fa0b


IGNITE-3305 - Fixed SYNC rebalance mode for dynamically started cache.


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

Branch: refs/heads/master
Commit: 92acd7404fa0be9d48c80dbdd4f662d7c6a21454
Parents: 8adeef3
Author: Alexey Goncharuk <alexey.goncharuk@gmail.com>
Authored: Mon Jun 13 17:52:39 2016 -0700
Committer: Alexey Goncharuk <alexey.goncharuk@gmail.com>
Committed: Mon Jun 13 17:52:39 2016 -0700

----------------------------------------------------------------------
 .../processors/cache/GridCacheProcessor.java    |  24 ++--
 .../IgniteCacheSyncRebalanceModeSelfTest.java   | 114 +++++++++++++++++++
 .../testsuites/IgniteCacheTestSuite5.java       |   2 +
 3 files changed, 131 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/92acd740/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index 6625093..29a5303 100755
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -727,9 +727,9 @@ public class GridCacheProcessor extends GridProcessorAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
     @Override public void onKernalStart() throws IgniteCheckedException {
-        try {
-            ClusterNode locNode = ctx.discovery().localNode();
+        ClusterNode locNode = ctx.discovery().localNode();
 
+        try {
             if (!ctx.config().isDaemon() && !getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK))
{
                 for (ClusterNode n : ctx.discovery().remoteNodes()) {
                     if (n.attribute(ATTR_CONSISTENCY_CHECK_SKIPPED))
@@ -818,15 +818,21 @@ public class GridCacheProcessor extends GridProcessorAdapter {
             ctx.cacheObjects().onUtilityCacheStarted();
 
         // Wait for caches in SYNC preload mode.
-        for (CacheConfiguration cfg : ctx.config().getCacheConfiguration()) {
-            GridCacheAdapter cache = caches.get(maskNull(cfg.getName()));
+        for (DynamicCacheDescriptor desc : registeredCaches.values()) {
+            CacheConfiguration cfg = desc.cacheConfiguration();
 
-            if (cache != null) {
-                if (cfg.getRebalanceMode() == SYNC) {
-                    CacheMode cacheMode = cfg.getCacheMode();
+            IgnitePredicate filter = cfg.getNodeFilter();
+
+            if (desc.locallyConfigured() || desc.receivedOnDiscovery() && CU.affinityNode(locNode,
filter)) {
+                GridCacheAdapter cache = caches.get(maskNull(cfg.getName()));
 
-                    if (cacheMode == REPLICATED || (cacheMode == PARTITIONED && cfg.getRebalanceDelay()
>= 0))
-                        cache.preloader().syncFuture().get();
+                if (cache != null) {
+                    if (cfg.getRebalanceMode() == SYNC) {
+                        CacheMode cacheMode = cfg.getCacheMode();
+
+                        if (cacheMode == REPLICATED || (cacheMode == PARTITIONED &&
cfg.getRebalanceDelay() >= 0))
+                            cache.preloader().syncFuture().get();
+                    }
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/92acd740/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/IgniteCacheSyncRebalanceModeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/IgniteCacheSyncRebalanceModeSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/IgniteCacheSyncRebalanceModeSelfTest.java
new file mode 100644
index 0000000..9b0637e
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/IgniteCacheSyncRebalanceModeSelfTest.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.distributed.replicated;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CachePeekMode;
+import org.apache.ignite.cache.CacheRebalanceMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ *
+ */
+public class IgniteCacheSyncRebalanceModeSelfTest extends GridCommonAbstractTest {
+    /** Entry count. */
+    public static final int CNT = 100_000;
+    public static final String STATIC_CACHE_NAME = "static";
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        CacheConfiguration ccfg = new CacheConfiguration(STATIC_CACHE_NAME);
+
+        ccfg.setCacheMode(CacheMode.REPLICATED);
+        ccfg.setRebalanceMode(CacheRebalanceMode.SYNC);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception if failed.
+     */
+    public void testStaticCache() throws Exception {
+        IgniteEx ignite = startGrid(0);
+
+        IgniteCache<Object, Object> cache = ignite.cache(STATIC_CACHE_NAME);
+
+        try (IgniteDataStreamer<Object, Object> streamer = ignite.dataStreamer(STATIC_CACHE_NAME))
{
+            streamer.allowOverwrite(true);
+
+            for (int i = 0; i < 100_000; i++)
+                streamer.addData(i, i);
+        }
+
+        assertEquals(CNT, cache.localSize());
+
+        Ignite ignite2 = startGrid(1);
+
+        assertEquals(CNT, ignite2.cache(STATIC_CACHE_NAME).localSize(CachePeekMode.PRIMARY,
CachePeekMode.BACKUP));
+
+        for (int i = 0; i < CNT; i++)
+            assertEquals(i, ignite2.cache(STATIC_CACHE_NAME).localPeek(i));
+    }
+
+    /**
+     * @throws Exception if failed.
+     */
+    public void testDynamicCache() throws Exception {
+        IgniteEx ignite = startGrid(0);
+
+        String cacheName = "dynamic";
+
+        CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(cacheName);
+
+        ccfg.setCacheMode(CacheMode.REPLICATED);
+        ccfg.setRebalanceMode(CacheRebalanceMode.SYNC);
+
+        IgniteCache<Object, Object> cache = ignite.createCache(ccfg);
+
+        try (IgniteDataStreamer<Object, Object> streamer = ignite.dataStreamer(cacheName))
{
+            streamer.allowOverwrite(true);
+
+            for (int i = 0; i < 100_000; i++)
+                streamer.addData(i, i);
+        }
+
+        assertEquals(CNT, cache.localSize());
+
+        Ignite ignite2 = startGrid(1);
+
+        assertEquals(CNT, ignite2.cache(cacheName).localSize(CachePeekMode.PRIMARY, CachePeekMode.BACKUP));
+
+        for (int i = 0; i < CNT; i++)
+            assertEquals(i, ignite2.cache(cacheName).localPeek(i));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/92acd740/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java
index a263c0d..41e0ed1 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java
@@ -28,6 +28,7 @@ import org.apache.ignite.internal.processors.cache.IgniteCacheStoreCollectionTes
 import org.apache.ignite.internal.processors.cache.distributed.CacheLateAffinityAssignmentFairAffinityTest;
 import org.apache.ignite.internal.processors.cache.distributed.CacheLateAffinityAssignmentNodeJoinValidationTest;
 import org.apache.ignite.internal.processors.cache.distributed.CacheLateAffinityAssignmentTest;
+import org.apache.ignite.internal.processors.cache.distributed.replicated.IgniteCacheSyncRebalanceModeSelfTest;
 import org.apache.ignite.internal.processors.cache.store.IgniteCacheWriteBehindNoUpdateSelfTest;
 
 /**
@@ -52,6 +53,7 @@ public class IgniteCacheTestSuite5 extends TestSuite {
         suite.addTestSuite(CacheLateAffinityAssignmentFairAffinityTest.class);
         suite.addTestSuite(CacheLateAffinityAssignmentNodeJoinValidationTest.class);
         suite.addTestSuite(EntryVersionConsistencyReadThroughTest.class);
+        suite.addTestSuite(IgniteCacheSyncRebalanceModeSelfTest.class);
 
         suite.addTest(IgniteCacheReadThroughEvictionsVariationsSuite.suite());
 


Mime
View raw message