ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntikho...@apache.org
Subject [01/12] ignite git commit: IGNITE-4671 - FairAffinityFunction fails on node restart with backupFilter set and no backups
Date Tue, 21 Mar 2017 11:41:24 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 92beda22f -> 19ba8f477


IGNITE-4671 - FairAffinityFunction fails on node restart with backupFilter set and no backups


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

Branch: refs/heads/master
Commit: 9df5e94d5cf14ddd55e29b81989177a7798f7e1a
Parents: caa3acb
Author: dkarachentsev <dkarachentsev@gridgain.com>
Authored: Tue Feb 21 15:34:59 2017 +0300
Committer: dkarachentsev <dkarachentsev@gridgain.com>
Committed: Tue Feb 21 15:34:59 2017 +0300

----------------------------------------------------------------------
 .../affinity/fair/FairAffinityFunction.java     |  33 ++---
 .../affinity/fair/FairAffinityNodesRestart.java | 130 +++++++++++++++++++
 .../ignite/testsuites/IgniteCacheTestSuite.java |   2 +
 3 files changed, 149 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/9df5e94d/modules/core/src/main/java/org/apache/ignite/cache/affinity/fair/FairAffinityFunction.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/affinity/fair/FairAffinityFunction.java
b/modules/core/src/main/java/org/apache/ignite/cache/affinity/fair/FairAffinityFunction.java
index cf1cb02..7acb5b4 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/affinity/fair/FairAffinityFunction.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/affinity/fair/FairAffinityFunction.java
@@ -911,37 +911,37 @@ public class FairAffinityFunction implements AffinityFunction {
             if (exclNeighbors)
                 return allowNeighbors || !neighborsContainPartition(node, part);
             else if (affinityBackupFilter != null) {
-                List<ClusterNode> assigment = assignments.get(part);
+                List<ClusterNode> assignment = assignments.get(part);
 
-                assert assigment.size() > 0;
+                if (assignment.isEmpty())
+                    return true;
 
                 List<ClusterNode> newAssignment;
 
                 if (tier == 0) {
-                    for (int t = 1; t < assigment.size(); t++) {
-                        newAssignment = new ArrayList<>(assigment.size() - 1);
+                    for (int t = 1; t < assignment.size(); t++) {
+                        newAssignment = new ArrayList<>(assignment.size() - 1);
 
                         newAssignment.add(node);
 
                         if (t != 1)
-                            newAssignment.addAll(assigment.subList(1, t));
+                            newAssignment.addAll(assignment.subList(1, t));
 
-                        if (t + 1 < assigment.size())
-                            newAssignment.addAll(assigment.subList(t + 1, assigment.size()));
+                        if (t + 1 < assignment.size())
+                            newAssignment.addAll(assignment.subList(t + 1, assignment.size()));
 
-                        if (!affinityBackupFilter.apply(assigment.get(t), newAssignment))
+                        if (!affinityBackupFilter.apply(assignment.get(t), newAssignment))
                             return false;
-
                     }
 
                     return true;
                 }
-                else if (tier < assigment.size()) {
-                    newAssignment = new ArrayList<>(assigment.size() - 1);
+                else if (tier < assignment.size()) {
+                    newAssignment = new ArrayList<>(assignment.size() - 1);
 
                     int i = 0;
 
-                    for (ClusterNode assignmentNode: assigment) {
+                    for (ClusterNode assignmentNode: assignment) {
                         if (i != tier)
                             newAssignment.add(assignmentNode);
 
@@ -949,17 +949,18 @@ public class FairAffinityFunction implements AffinityFunction {
                     }
                 }
                 else
-                    newAssignment = assigment;
+                    newAssignment = assignment;
 
                 return affinityBackupFilter.apply(node, newAssignment);
             }
             else if (backupFilter != null) {
                 if (tier == 0) {
-                    List<ClusterNode> assigment = assignments.get(part);
+                    List<ClusterNode> assignment = assignments.get(part);
 
-                    assert assigment.size() > 0;
+                    if (assignment.isEmpty())
+                        return true;
 
-                    List<ClusterNode> backups = assigment.subList(1, assigment.size());
+                    List<ClusterNode> backups = assignment.subList(1, assignment.size());
 
                     return !F.exist(backups, new IgnitePredicate<ClusterNode>() {
                         @Override public boolean apply(ClusterNode n) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/9df5e94d/modules/core/src/test/java/org/apache/ignite/cache/affinity/fair/FairAffinityNodesRestart.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/affinity/fair/FairAffinityNodesRestart.java
b/modules/core/src/test/java/org/apache/ignite/cache/affinity/fair/FairAffinityNodesRestart.java
new file mode 100644
index 0000000..37f1bfb
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/cache/affinity/fair/FairAffinityNodesRestart.java
@@ -0,0 +1,130 @@
+/*
+ * 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.cache.affinity.fair;
+
+import java.util.List;
+import java.util.concurrent.Callable;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.util.typedef.P2;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * Tests that FairAffinityFunction doesn't throw exception on nodes restart,
+ * with backup filter set and 0 cache backups.
+ */
+public class FairAffinityNodesRestart extends GridCommonAbstractTest {
+    /** */
+    private final static P2<ClusterNode, ClusterNode> BACKUP_FILTER = new P2<ClusterNode,
ClusterNode>() {
+        @Override public boolean apply(ClusterNode node, ClusterNode node2) {
+            return true;
+        }
+    };
+
+    /** */
+    private final static P2<ClusterNode, List<ClusterNode>> AFF_BACKUP_FILTER
= new P2<ClusterNode, List<ClusterNode>>() {
+        @Override public boolean apply(ClusterNode node, List<ClusterNode> nodes) {
+            return true;
+        }
+    };
+
+    /** */
+    private boolean affBackup;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        CacheConfiguration ccfg = new CacheConfiguration("fair-cache");
+
+        FairAffinityFunction aff = new FairAffinityFunction(32);
+
+        if (!affBackup)
+            aff.setBackupFilter(BACKUP_FILTER);
+        else
+            aff.setAffinityBackupFilter(AFF_BACKUP_FILTER);
+
+        ccfg.setAffinity(aff);
+        ccfg.setBackups(0);
+        ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /**
+     * @param idx Node index.
+     * @return Future.
+     */
+    private IgniteInternalFuture<IgniteEx> startAsyncGrid(final int idx) {
+        return GridTestUtils.runAsync(new Callable<IgniteEx>() {
+            @Override public IgniteEx call() throws Exception {
+                return startGrid(idx);
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testBackupFilter() throws Exception {
+        affBackup = false;
+
+        check();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAffinityBackupFilter() throws Exception {
+        affBackup = true;
+
+        check();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void check() throws Exception {
+        for (int i = 0; i < 2; i++) {
+            IgniteInternalFuture<IgniteEx> fut0 = startAsyncGrid(0);
+            IgniteInternalFuture<IgniteEx> fut1 = startAsyncGrid(1);
+            IgniteInternalFuture<IgniteEx> fut2 = startAsyncGrid(2);
+
+            IgniteEx ignite = fut0.get();
+            fut1.get();
+            fut2.get();
+
+            IgniteCache<Integer, String> cache = ignite.cache("fair-cache");
+
+            for (int j = 0; j < 100; j++)
+                cache.put(i, String.valueOf(i));
+
+            stopGrid(0);
+            stopGrid(1);
+            stopGrid(2);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/9df5e94d/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
index 092d95e..a24f020 100755
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
@@ -27,6 +27,7 @@ import org.apache.ignite.cache.affinity.AffinityHistoryCleanupTest;
 import org.apache.ignite.cache.affinity.fair.FairAffinityDynamicCacheSelfTest;
 import org.apache.ignite.cache.affinity.fair.FairAffinityFunctionNodesSelfTest;
 import org.apache.ignite.cache.affinity.fair.FairAffinityFunctionSelfTest;
+import org.apache.ignite.cache.affinity.fair.FairAffinityNodesRestart;
 import org.apache.ignite.cache.affinity.local.LocalAffinityFunctionTest;
 import org.apache.ignite.cache.store.GridCacheBalancingStoreSelfTest;
 import org.apache.ignite.cache.store.GridCacheLoadOnlyStoreAdapterSelfTest;
@@ -231,6 +232,7 @@ public class IgniteCacheTestSuite extends TestSuite {
         suite.addTestSuite(FairAffinityFunctionNodesSelfTest.class);
         suite.addTestSuite(FairAffinityFunctionSelfTest.class);
         suite.addTestSuite(FairAffinityDynamicCacheSelfTest.class);
+        suite.addTestSuite(FairAffinityNodesRestart.class);
         suite.addTestSuite(GridCacheAffinityBackupsSelfTest.class);
         suite.addTestSuite(IgniteCacheAffinitySelfTest.class);
         suite.addTestSuite(AffinityClientNodeSelfTest.class);


Mime
View raw message