Repository: ignite Updated Branches: refs/heads/ignite-5075 bd0171579 -> 72cb4459e
ignite-5075 Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/72cb4459 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/72cb4459 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/72cb4459 Branch: refs/heads/ignite-5075 Commit: 72cb4459e23773fb0848fc31aaab6fea0914f9e9 Parents: bd01715 Author: sboikov <[email protected]> Authored: Tue May 16 13:49:50 2017 +0300 Committer: sboikov <[email protected]> Committed: Tue May 16 13:49:50 2017 +0300 ---------------------------------------------------------------------- .../processors/cache/ClusterCachesInfo.java | 46 ++++++++++++++++++++ .../processors/cache/GridCacheAttributes.java | 7 +++ .../processors/cache/GridCacheProcessor.java | 12 ++++- .../processors/cache/GridCacheUtils.java | 38 ++++++++++++++++ .../processors/cache/IgniteCacheGroupsTest.java | 37 ++++++++++++++++ 5 files changed, 139 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/72cb4459/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 6f3371a..23a37b0 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 @@ -118,6 +118,8 @@ class ClusterCachesInfo { if (cacheData != null) checkCache(locCfg, cacheData.cacheConfiguration(), cacheData.receivedFrom()); + + validateStartCacheConfiguration(locCfg); } } @@ -942,6 +944,50 @@ class ClusterCachesInfo { } /** + * @param ccfg Cache configuration to start. + * @throws IgniteCheckedException If failed. + */ + void validateStartCacheConfiguration(CacheConfiguration ccfg) throws IgniteCheckedException { + if (ccfg.getGroupName() != null) { + CacheGroupDescriptor grpDesc = registeredCacheGrps.get(ccfg.getGroupName()); + + if (grpDesc != null) { + assert ccfg.getGroupName().equals(grpDesc.groupName()); + + validateCacheGroupConfiguration(grpDesc.config(), ccfg); + } + } + } + + /** + * @param cfg Existing configuration. + * @param startCfg Cache configuration to start. + * @throws IgniteCheckedException If validation failed. + */ + private void validateCacheGroupConfiguration(CacheConfiguration cfg, CacheConfiguration startCfg) + throws IgniteCheckedException { + GridCacheAttributes attr1 = new GridCacheAttributes(cfg); + GridCacheAttributes attr2 = new GridCacheAttributes(startCfg); + + CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "cacheMode", "Cache mode", + cfg.getCacheMode(), startCfg.getCacheMode(), true); + + CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "rebalanceMode", "Rebalance mode", + cfg.getRebalanceMode(), startCfg.getRebalanceMode(), true); + + CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "affinity", "Affinity function", + attr1.cacheAffinityClassName(), attr2.cacheAffinityClassName(), true); + + CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "nodeFilter", "Node filter", + attr1.nodeFilterClassName(), attr2.nodeFilterClassName(), true); + + if (cfg.getCacheMode() == PARTITIONED) { + CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "backups", "Backups", + cfg.getBackups(), startCfg.getBackups(), true); + } + } + + /** * @return Registered caches. */ ConcurrentMap<String, DynamicCacheDescriptor> registeredCaches() { http://git-wip-us.apache.org/repos/asf/ignite/blob/72cb4459/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 1caf60d..96d5a0a 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 @@ -273,6 +273,13 @@ public class GridCacheAttributes implements Serializable { } /** + * @return Node filter class name. + */ + String nodeFilterClassName() { + return className(ccfg.getNodeFilter()); + } + + /** * @param obj Object to get class of. * @return Class name or {@code null}. */ http://git-wip-us.apache.org/repos/asf/ignite/blob/72cb4459/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 3e9c6ed..dddc525 100644 --- 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 @@ -790,7 +790,7 @@ public class GridCacheProcessor extends GridProcessorAdapter { /** * @param grpId Group ID. - * @return + * @return Cache group. */ @Nullable public CacheGroupInfrastructure cacheGroup(int grpId) { return cacheGrps.get(grpId); @@ -2644,6 +2644,16 @@ public class GridCacheProcessor extends GridProcessorAdapter { } } } + if (req.start() && req.startCacheConfiguration() != null) { + CacheConfiguration ccfg = req.startCacheConfiguration(); + + try { + cachesInfo.validateStartCacheConfiguration(ccfg); + } + catch (IgniteCheckedException e) { + fut.onDone(e); + } + } if (fut.isDone()) continue; http://git-wip-us.apache.org/repos/asf/ignite/blob/72cb4459/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 f695768..433f66d 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 @@ -1086,6 +1086,44 @@ public class GridCacheUtils { } } } + /** + * @param cfg1 Existing configuration. + * @param cfg2 Cache configuration to start. + * @param attrName Short attribute name for error message. + * @param attrMsg Full attribute name for error message. + * @param val1 Attribute value in existing configuration. + * @param val2 Attribute value in starting configuration. + * @param fail If true throws IgniteCheckedException in case of attribute values mismatch, otherwise logs warning. + * @throws IgniteCheckedException If validation failed. + */ + public static void validateCacheGroupsAttributesMismatch(IgniteLogger log, + CacheConfiguration cfg1, + CacheConfiguration cfg2, + String attrName, + String attrMsg, + Object val1, + Object val2, + boolean fail) throws IgniteCheckedException { + if (F.eq(val1, val2)) + return; + + if (fail) { + throw new IgniteCheckedException(attrMsg + " mismatch for caches related to the same group " + + "[groupName=" + cfg1.getGroupName() + + ", existingCache=" + cfg1.getName() + + ", existing" + capitalize(attrName) + "=" + val1 + + ", startingCache=" + cfg2.getName() + + ", starting" + capitalize(attrName) + "=" + val2 + ']'); + } + else { + U.warn(log, attrMsg + " mismatch for caches related to the same group " + + "[groupName=" + cfg1.getGroupName() + + ", existingCache=" + cfg1.getName() + + ", existing" + capitalize(attrName) + "=" + val1 + + ", startingCache=" + cfg2.getName() + + ", starting" + capitalize(attrName) + "=" + val2 + ']'); + } + } /** * @param str String. http://git-wip-us.apache.org/repos/asf/ignite/blob/72cb4459/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsTest.java index b06a129..9fb72d7 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsTest.java @@ -21,6 +21,7 @@ import java.io.Serializable; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import javax.cache.CacheException; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteCheckedException; @@ -43,6 +44,7 @@ import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC; import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; import static org.apache.ignite.cache.CacheMode.PARTITIONED; +import static org.apache.ignite.cache.CacheMode.REPLICATED; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; /** @@ -408,6 +410,41 @@ public class IgniteCacheGroupsTest extends GridCommonAbstractTest { } /** + * @throws Exception If failed. + */ + public void testConfigurationConsistencyValidation() throws Exception { + startGrids(2); + + client = true; + + startGrid(2); + + ignite(0).createCache(cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1, false)); + + for (int i = 0; i < 3; i++) { + try { + ignite(i).createCache(cacheConfiguration(GROUP1, "c2", REPLICATED, ATOMIC, Integer.MAX_VALUE, false)); + + fail(); + } + catch (CacheException e) { + assertTrue("Unexpected message: " + e.getMessage(), + e.getMessage().contains("Cache mode mismatch for caches related to the same group [groupName=grp1")); + } + + try { + ignite(i).createCache(cacheConfiguration(GROUP1, "c2", PARTITIONED, ATOMIC, 2, false)); + + fail(); + } + catch (CacheException e) { + assertTrue("Unexpected message: " + e.getMessage(), + e.getMessage().contains("Backups mismatch for caches related to the same group [groupName=grp1")); + } + } + } + + /** * @param rnd Random. * @param cache Cache. */
