ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject ignite git commit: IGNITE-5542 CacheGroup configuration from cluster is merged with local settings
Date Wed, 02 Aug 2017 15:14:53 GMT
Repository: ignite
Updated Branches:
  refs/heads/master b27768288 -> 88818ecc5


IGNITE-5542 CacheGroup configuration from cluster is merged with local settings


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

Branch: refs/heads/master
Commit: 88818ecc5ad882eb7a6b0b1bb4a7b1131b724a78
Parents: b277682
Author: Sergey Chugunov <sergey.chugunov@gmail.com>
Authored: Wed Aug 2 18:14:46 2017 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Wed Aug 2 18:14:46 2017 +0300

----------------------------------------------------------------------
 .../processors/cache/CacheGroupDescriptor.java  |  20 ++-
 .../processors/cache/ClusterCachesInfo.java     |  25 +++
 .../processors/cache/GridCacheAttributes.java   |  35 +++++
 .../processors/cache/GridCacheUtils.java        |   1 +
 .../CacheGroupLocalConfigurationSelfTest.java   | 155 +++++++++++++++++++
 .../testsuites/IgniteCacheTestSuite2.java       |   2 +
 6 files changed, 237 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/88818ecc/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupDescriptor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupDescriptor.java
index c4976e5..20301a6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupDescriptor.java
@@ -83,7 +83,7 @@ public class CacheGroupDescriptor {
         this.rcvdFrom = rcvdFrom;
         this.startTopVer = startTopVer;
         this.deploymentId = deploymentId;
-        this.cacheCfg = cacheCfg;
+        this.cacheCfg = new CacheConfiguration<>(cacheCfg);
         this.caches = caches;
     }
 
@@ -197,6 +197,24 @@ public class CacheGroupDescriptor {
     }
 
     /**
+     * Method to merge this CacheGroup descriptor with another one.
+     *
+     * @param otherDesc CacheGroup descriptor that must be merged with this one.
+     */
+    void mergeWith(CacheGroupDescriptor otherDesc) {
+        assert otherDesc != null && otherDesc.config() != null: otherDesc;
+
+        CacheConfiguration otherCfg = otherDesc.config();
+
+        cacheCfg.setRebalanceDelay(otherCfg.getRebalanceDelay());
+        cacheCfg.setRebalanceBatchesPrefetchCount(otherCfg.getRebalanceBatchesPrefetchCount());
+        cacheCfg.setRebalanceBatchSize(otherCfg.getRebalanceBatchSize());
+        cacheCfg.setRebalanceOrder(otherCfg.getRebalanceOrder());
+        cacheCfg.setRebalanceThrottle(otherCfg.getRebalanceThrottle());
+        cacheCfg.setRebalanceTimeout(otherCfg.getRebalanceTimeout());
+    }
+
+    /**
      * @return Start version for dynamically started group.
      */
     @Nullable public AffinityTopologyVersion startTopologyVersion() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/88818ecc/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
index 1a05b96..bb51a3b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
@@ -285,6 +285,22 @@ class ClusterCachesInfo {
             CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "preloadBatchSize",
                 "Preload batch size", locAttr.rebalanceBatchSize(), rmtAttr.rebalanceBatchSize(),
false);
 
+            CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "rebalanceDelay",
+                "Rebalance delay", locAttr.rebalanceDelay(), rmtAttr.rebalanceDelay(), false);
+
+            CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "rebalanceBatchesPrefetchCount",
+                "Rebalance batches prefetch count", locAttr.rebalanceBatchesPrefetchCount(),
+                rmtAttr.rebalanceBatchesPrefetchCount(), false);
+
+            CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "rebalanceOrder",
+                "Rebalance order", locAttr.rebalanceOrder(), rmtAttr.rebalanceOrder(), false);
+
+            CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "rebalanceThrottle",
+                "Rebalance throttle", locAttr.rebalanceThrottle(), rmtAttr.rebalanceThrottle(),
false);
+
+            CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "rebalanceTimeout",
+                "Rebalance timeout", locAttr.rebalanceTimeout(), rmtAttr.rebalanceTimeout(),
false);
+
             CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "writeSynchronizationMode",
                 "Write synchronization mode", locAttr.writeSynchronization(), rmtAttr.writeSynchronization(),
                 true);
@@ -941,6 +957,9 @@ class ClusterCachesInfo {
 
         CacheNodeCommonDiscoveryData cachesData = (CacheNodeCommonDiscoveryData)data.commonData();
 
+        // CacheGroup configurations that were created from local node configuration.
+        Map<Integer, CacheGroupDescriptor> locCacheGrps = new HashMap<>(registeredCacheGroups());
+
         // Replace locally registered data with actual data received from cluster.
         registeredCaches.clear();
         registeredCacheGrps.clear();
@@ -956,6 +975,12 @@ class ClusterCachesInfo {
                 grpData.deploymentId(),
                 grpData.caches());
 
+            if (locCacheGrps.containsKey(grpDesc.groupId())) {
+                CacheGroupDescriptor locGrpCfg = locCacheGrps.get(grpDesc.groupId());
+
+                grpDesc.mergeWith(locGrpCfg);
+            }
+
             CacheGroupDescriptor old = registeredCacheGrps.put(grpDesc.groupId(), grpDesc);
 
             assert old == null : old;

http://git-wip-us.apache.org/repos/asf/ignite/blob/88818ecc/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java
index 32871ea..d64ee8b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java
@@ -203,6 +203,41 @@ public class GridCacheAttributes implements Serializable {
     }
 
     /**
+     * @return Rebalance delay.
+     */
+    public long rebalanceDelay() {
+        return ccfg.getRebalanceDelay();
+    }
+
+    /**
+     * @return Rebalance prefetch count.
+     */
+    public long rebalanceBatchesPrefetchCount() {
+        return ccfg.getRebalanceBatchesPrefetchCount();
+    }
+
+    /**
+     * @return Rebalance order.
+     */
+    public int rebalanceOrder() {
+        return ccfg.getRebalanceOrder();
+    }
+
+    /**
+     * @return Rebalance throttle.
+     */
+    public long rebalanceThrottle() {
+        return ccfg.getRebalanceThrottle();
+    }
+
+    /**
+     * @return Rebalance timeout.
+     */
+    public long rebalanceTimeout() {
+        return ccfg.getRebalanceTimeout();
+    }
+
+    /**
      * @return Synchronization mode.
      */
     public CacheWriteSynchronizationMode writeSynchronization() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/88818ecc/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
index a07b166..f0b8170 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
@@ -992,6 +992,7 @@ public class GridCacheUtils {
             }
         }
     }
+
     /**
      * @param cfg1 Existing configuration.
      * @param cfg2 Cache configuration to start.

http://git-wip-us.apache.org/repos/asf/ignite/blob/88818ecc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGroupLocalConfigurationSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGroupLocalConfigurationSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGroupLocalConfigurationSelfTest.java
new file mode 100644
index 0000000..51f9001
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGroupLocalConfigurationSelfTest.java
@@ -0,0 +1,155 @@
+/*
+ * 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;
+
+import java.util.Map;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ *
+ */
+public class CacheGroupLocalConfigurationSelfTest extends GridCommonAbstractTest {
+    /** */
+    private static final String SECOND_NODE_NAME = "secondNode";
+
+    /** */
+    private static final int NON_STANDARD_REBALANCE_VALUE = 101;
+
+    /** */
+    private static final String NON_DEFAULT_GROUP_NAME = "cacheGroup";
+
+    /** */
+    private boolean useNonDfltCacheGrp = true;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws
Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        if (igniteInstanceName.equals(SECOND_NODE_NAME)) {
+            CacheConfiguration ccfg = new CacheConfiguration()
+                .setName(DEFAULT_CACHE_NAME)
+                .setRebalanceDelay(NON_STANDARD_REBALANCE_VALUE)
+                .setRebalanceBatchesPrefetchCount(NON_STANDARD_REBALANCE_VALUE)
+                .setRebalanceBatchSize(NON_STANDARD_REBALANCE_VALUE)
+                .setRebalanceOrder(NON_STANDARD_REBALANCE_VALUE)
+                .setRebalanceThrottle(NON_STANDARD_REBALANCE_VALUE)
+                .setRebalanceTimeout(NON_STANDARD_REBALANCE_VALUE);
+
+            if (useNonDfltCacheGrp)
+                ccfg.setGroupName(NON_DEFAULT_GROUP_NAME);
+
+            cfg.setCacheConfiguration(ccfg);
+        }
+        else {
+            CacheConfiguration ccfg = new CacheConfiguration()
+                .setName(DEFAULT_CACHE_NAME);
+
+            if (useNonDfltCacheGrp)
+                ccfg.setGroupName(NON_DEFAULT_GROUP_NAME);
+
+            cfg.setCacheConfiguration(ccfg);
+        }
+
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * Test validates that all cache group configuration attributes from local config
+     * that must not be overwritten by grid config are preserved for default cache group.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDefaultGroupLocalAttributesPreserved() throws Exception {
+        useNonDfltCacheGrp = false;
+
+        executeTest();
+    }
+
+    /**
+     * Test validates that all cache group configuration attributes from local config
+     * that must not be overwritten by grid config are preserved for non-default cache group.
+     *
+     * @throws Exception If failed.
+     */
+    public void testNonDefaultGroupLocalAttributesPreserved() throws Exception {
+        useNonDfltCacheGrp = true;
+
+        executeTest();
+    }
+
+    /**
+     * Executes actual test logic.
+     *
+     * @throws Exception If failed.
+     */
+    private void executeTest() throws Exception {
+        startGrid(0);
+
+        IgniteKernal ignite = (IgniteKernal) startGrid("secondNode");
+
+        GridCacheProcessor cacheProc = ignite.context().cache();
+
+        Map<Integer, CacheGroupContext> cacheGrps = U.field(cacheProc, "cacheGrps");
+
+        CacheConfiguration cacheGroupCfg = findGroupConfig(cacheGrps,
+            useNonDfltCacheGrp ? NON_DEFAULT_GROUP_NAME : DEFAULT_CACHE_NAME);
+
+        assertNotNull("Default cache group must be presented", cacheGroupCfg);
+
+        assertEquals("Rebalance delay", cacheGroupCfg.getRebalanceDelay(), NON_STANDARD_REBALANCE_VALUE);
+
+        assertEquals("Rebalance batches prefetch count",
+            cacheGroupCfg.getRebalanceBatchesPrefetchCount(),
+            NON_STANDARD_REBALANCE_VALUE);
+
+        assertEquals("Rebalance batch size", cacheGroupCfg.getRebalanceBatchSize(), NON_STANDARD_REBALANCE_VALUE);
+
+        assertEquals("Rebalance order", cacheGroupCfg.getRebalanceOrder(), NON_STANDARD_REBALANCE_VALUE);
+
+        assertEquals("Rebalance throttle", cacheGroupCfg.getRebalanceThrottle(), NON_STANDARD_REBALANCE_VALUE);
+
+        assertEquals("Rebalance timeout", cacheGroupCfg.getRebalanceTimeout(), NON_STANDARD_REBALANCE_VALUE);
+    }
+
+    /**
+     * @param cacheGrps All configured cache groups.
+     * @param groupName Name of group to find.
+     * @return Cache configuration.
+     */
+    private CacheConfiguration findGroupConfig(Map<Integer, CacheGroupContext> cacheGrps,
@Nullable String groupName) {
+        if (groupName == null)
+            groupName = DEFAULT_CACHE_NAME;
+
+        for (CacheGroupContext grpCtx : cacheGrps.values()) {
+            if (groupName.equals(grpCtx.cacheOrGroupName()))
+                return grpCtx.config();
+        }
+
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/88818ecc/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
index 9ed7ee3..513f909 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
@@ -28,6 +28,7 @@ import org.apache.ignite.internal.processors.cache.CacheDhtLocalPartitionAfterRe
 import org.apache.ignite.internal.processors.cache.CacheEnumOperationsSingleNodeTest;
 import org.apache.ignite.internal.processors.cache.CacheEnumOperationsTest;
 import org.apache.ignite.internal.processors.cache.CacheExchangeMessageDuplicatedStateTest;
+import org.apache.ignite.internal.processors.cache.CacheGroupLocalConfigurationSelfTest;
 import org.apache.ignite.internal.processors.cache.CacheMemoryPolicyConfigurationTest;
 import org.apache.ignite.internal.processors.cache.CacheOptimisticTransactionsWithFilterSingleServerTest;
 import org.apache.ignite.internal.processors.cache.CacheOptimisticTransactionsWithFilterTest;
@@ -259,6 +260,7 @@ public class IgniteCacheTestSuite2 extends TestSuite {
         suite.addTest(new TestSuite(MemoryPolicyConfigValidationTest.class));
         suite.addTest(new TestSuite(MemoryPolicyInitializationTest.class));
         suite.addTest(new TestSuite(CacheMemoryPolicyConfigurationTest.class));
+        suite.addTest(new TestSuite(CacheGroupLocalConfigurationSelfTest.class));
         suite.addTest(new TestSuite(CacheEnumOperationsSingleNodeTest.class));
         suite.addTest(new TestSuite(CacheEnumOperationsTest.class));
         suite.addTest(new TestSuite(IgniteCacheIncrementTxTest.class));


Mime
View raw message