Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6EE13200C4E for ; Wed, 22 Mar 2017 12:12:51 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 6D870160B98; Wed, 22 Mar 2017 11:12:51 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7644C160B97 for ; Wed, 22 Mar 2017 12:12:50 +0100 (CET) Received: (qmail 96125 invoked by uid 500); 22 Mar 2017 11:12:49 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 95960 invoked by uid 99); 22 Mar 2017 11:12:47 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Mar 2017 11:12:47 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C6DEBDFC15; Wed, 22 Mar 2017 11:12:47 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vozerov@apache.org To: commits@ignite.apache.org Date: Wed, 22 Mar 2017 11:12:47 -0000 Message-Id: <47b85dd479cb4c5fafa507da7291057c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [01/23] ignite git commit: IGNITE-4671 - FairAffinityFunction fails on node restart with backupFilter set and no backups archived-at: Wed, 22 Mar 2017 11:12:51 -0000 Repository: ignite Updated Branches: refs/heads/ignite-4565-ddl 41a7beac9 -> 815f0cbdc 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/ignite-4565-ddl Commit: 9df5e94d5cf14ddd55e29b81989177a7798f7e1a Parents: caa3acb Author: dkarachentsev Authored: Tue Feb 21 15:34:59 2017 +0300 Committer: dkarachentsev 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 assigment = assignments.get(part); + List assignment = assignments.get(part); - assert assigment.size() > 0; + if (assignment.isEmpty()) + return true; List 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 assigment = assignments.get(part); + List assignment = assignments.get(part); - assert assigment.size() > 0; + if (assignment.isEmpty()) + return true; - List backups = assigment.subList(1, assigment.size()); + List backups = assignment.subList(1, assignment.size()); return !F.exist(backups, new IgnitePredicate() { @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 BACKUP_FILTER = new P2() { + @Override public boolean apply(ClusterNode node, ClusterNode node2) { + return true; + } + }; + + /** */ + private final static P2> AFF_BACKUP_FILTER = new P2>() { + @Override public boolean apply(ClusterNode node, List 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 startAsyncGrid(final int idx) { + return GridTestUtils.runAsync(new Callable() { + @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 fut0 = startAsyncGrid(0); + IgniteInternalFuture fut1 = startAsyncGrid(1); + IgniteInternalFuture fut2 = startAsyncGrid(2); + + IgniteEx ignite = fut0.get(); + fut1.get(); + fut2.get(); + + IgniteCache 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);