You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2018/05/10 12:02:09 UTC

ignite git commit: IGNITE-8424 Add directory sorting and skip duplicated config file in order to consistently start nodes.

Repository: ignite
Updated Branches:
  refs/heads/master 98e22cbd7 -> bec3e9bf9


IGNITE-8424 Add directory sorting and skip duplicated config file in order to consistently start nodes.

Signed-off-by: Andrey Gura <ag...@apache.org>


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

Branch: refs/heads/master
Commit: bec3e9bf9e0c9c5b4bbcda7eb226ffc821665b6e
Parents: 98e22cb
Author: Ivan Daschinskiy <iv...@gmail.com>
Authored: Thu May 10 14:56:35 2018 +0300
Committer: Andrey Gura <ag...@apache.org>
Committed: Thu May 10 14:56:35 2018 +0300

----------------------------------------------------------------------
 .../persistence/file/FilePageStoreManager.java  |  21 ++-
 ...nitePdsDuplicatedCacheConfigurationTest.java | 161 +++++++++++++++++++
 .../ignite/testsuites/IgnitePdsTestSuite.java   |   2 +
 3 files changed, 182 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/bec3e9bf/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 661694d..de99724 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
@@ -30,6 +30,7 @@ import java.nio.file.DirectoryStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.StandardCopyOption;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
@@ -623,6 +624,8 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen
 
         Map<String, StoredCacheData> ccfgs = new HashMap<>();
 
+        Arrays.sort(files);
+
         for (File file : files) {
             if (file.isDirectory()) {
                 if (file.getName().startsWith(CACHE_DIR_PREFIX)) {
@@ -631,7 +634,14 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen
                     if (conf.exists() && conf.length() > 0) {
                         StoredCacheData cacheData = readCacheData(conf);
 
-                        ccfgs.put(cacheData.config().getName(), cacheData);
+                        String cacheName = cacheData.config().getName();
+
+                        if (!ccfgs.containsKey(cacheName))
+                            ccfgs.put(cacheName, cacheData);
+                        else {
+                            U.warn(log, "Cache with name=" + cacheName + " is already registered, skipping config file "
+                                    + file.getName());
+                        }
                     }
                 }
                 else if (file.getName().startsWith(CACHE_GRP_DIR_PREFIX))
@@ -657,7 +667,14 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen
             if (!file.isDirectory() && file.getName().endsWith(CACHE_DATA_FILENAME) && file.length() > 0) {
                 StoredCacheData cacheData = readCacheData(file);
 
-                ccfgs.put(cacheData.config().getName(), cacheData);
+                String cacheName = cacheData.config().getName();
+
+                if (!ccfgs.containsKey(cacheName))
+                    ccfgs.put(cacheName, cacheData);
+                else {
+                    U.warn(log, "Cache with name=" + cacheName + " is already registered, skipping config file "
+                            + file.getName() + " in group directory " + grpDir.getName());
+                }
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/bec3e9bf/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsDuplicatedCacheConfigurationTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsDuplicatedCacheConfigurationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsDuplicatedCacheConfigurationTest.java
new file mode 100644
index 0000000..66459bd
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsDuplicatedCacheConfigurationTest.java
@@ -0,0 +1,161 @@
+/*
+ * 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.persistence;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor;
+import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
+import org.apache.ignite.internal.processors.cache.StoredCacheData;
+import org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * Tests that ignite can start when caches' configurations with same name in different groups stored.
+ */
+public class IgnitePdsDuplicatedCacheConfigurationTest extends GridCommonAbstractTest {
+    /** */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private static final int CACHES = 4;
+
+    /** */
+    private static final int NODES = 4;
+
+    /** */
+    private static final String ODD_GROUP_NAME = "group-odd";
+
+    /** */
+    private static final String EVEN_GROUP_NAME = "group-even";
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        return cfg.setDiscoverySpi(new TcpDiscoverySpi()
+                .setIpFinder(IP_FINDER))
+                .setDataStorageConfiguration(new DataStorageConfiguration()
+                        .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+                                .setMaxSize(200 * 1024 * 1024)
+                                .setPersistenceEnabled(true)));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        stopAllGrids();
+
+        cleanPersistenceDir();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+
+        cleanPersistenceDir();
+
+        super.afterTest();
+    }
+
+    /**
+     * Tests that ignite can start when caches' configurations with same name in different groups stored.
+     *
+     * @throws Exception If fails.
+     */
+    public void testStartDuplicatedCacheConfigurations() throws Exception {
+        IgniteEx ig0 = (IgniteEx)startGrids(NODES);
+
+        ig0.cluster().active(true);
+
+        startCaches(ig0);
+
+        DynamicCacheDescriptor desc = ig0.context().cache().cacheDescriptor(cacheName(3));
+
+        storeInvalidCacheData(desc);
+
+        stopAllGrids();
+
+        startGrids(NODES);
+
+        desc = ig0.context().cache().cacheDescriptor(cacheName(3));
+
+        assertEquals("expected that group of " + cacheName(3) + " is " + EVEN_GROUP_NAME, EVEN_GROUP_NAME,
+                desc.groupDescriptor().groupName());
+
+    }
+
+    /**
+     * Store cache descriptor to PDS with invalid group name.
+     *
+     * @param cacheDescr Cache descr.
+     * @throws IgniteCheckedException If fails.
+     */
+    private void storeInvalidCacheData(DynamicCacheDescriptor cacheDescr) throws IgniteCheckedException {
+        for (int i = 0; i < NODES; i++) {
+            IgniteEx ig = grid(i);
+
+            GridCacheSharedContext sharedCtx = ig.context().cache().context();
+
+            FilePageStoreManager pageStore = (FilePageStoreManager) sharedCtx.pageStore();
+
+            StoredCacheData corrData = cacheDescr.toStoredData();
+
+            corrData.config().setGroupName(ODD_GROUP_NAME);
+
+            pageStore.storeCacheData(corrData, true);
+        }
+    }
+
+    /**
+     * @param ignite Ignite instance.
+     */
+    private void startCaches(Ignite ignite) {
+        List<CacheConfiguration> ccfg = new ArrayList<>(CACHES);
+
+        for (int i = 0; i < CACHES; i++) {
+            ccfg.add(new CacheConfiguration<>(cacheName(i))
+                    .setGroupName(i % 2 == 0 ? ODD_GROUP_NAME : EVEN_GROUP_NAME)
+                    .setBackups(1)
+                    .setAffinity(new RendezvousAffinityFunction(false, 32)));
+        }
+
+        ignite.createCaches(ccfg);
+    }
+
+    /**
+     * Generate cache name from idx.
+     *
+     * @param idx Index.
+     */
+    private String cacheName(int idx) {
+        return "cache" + idx;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/bec3e9bf/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java
index d11ceb3..1e32320 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java
@@ -21,6 +21,7 @@ import junit.framework.TestSuite;
 import org.apache.ignite.internal.processors.cache.IgniteClusterActivateDeactivateTestWithPersistence;
 import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsDestroyCacheTest;
 import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsDestroyCacheWithoutCheckpointsTest;
+import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsDuplicatedCacheConfigurationTest;
 import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsDynamicCacheTest;
 import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsSingleNodePutGetPersistenceTest;
 import org.apache.ignite.internal.processors.cache.persistence.db.IgnitePdsCacheRestoreTest;
@@ -118,6 +119,7 @@ public class IgnitePdsTestSuite extends TestSuite {
 
         suite.addTestSuite(IgnitePdsDestroyCacheTest.class);
         suite.addTestSuite(IgnitePdsDestroyCacheWithoutCheckpointsTest.class);
+        suite.addTestSuite(IgnitePdsDuplicatedCacheConfigurationTest.class);
 
         suite.addTestSuite(DefaultPageSizeBackwardsCompatibilityTest.class);