Repository: ignite Updated Branches: refs/heads/master 743b25fae -> 8ef84661f
IGNITE-10624 Update deployment id for cache context after join to topology - Fixes #5629. Signed-off-by: Pavel Kovalenko <jokse...@gmail.com> Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/8ef84661 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/8ef84661 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/8ef84661 Branch: refs/heads/master Commit: 8ef84661f450f775f1f6b2ad7d893fead75d97aa Parents: 743b25f Author: Pavel Kovalenko <jokse...@gmail.com> Authored: Mon Dec 17 11:07:34 2018 +0300 Committer: Pavel Kovalenko <jokse...@gmail.com> Committed: Mon Dec 17 11:07:34 2018 +0300 ---------------------------------------------------------------------- .../processors/cache/CacheGroupContext.java | 17 +- .../processors/cache/GridCacheContext.java | 24 +- .../processors/cache/GridCacheContextInfo.java | 9 +- .../processors/cache/GridCacheProcessor.java | 33 +- .../processors/query/GridQueryProcessor.java | 2 +- .../db/IgniteLogicalRecoveryTest.java | 50 +++ .../loadtests/hashmap/GridCacheTestContext.java | 3 + .../cache/index/BasicIndexMultinodeTest.java | 28 ++ .../processors/cache/index/BasicIndexTest.java | 344 +++++++++++-------- .../IgniteBinaryCacheQueryTestSuite.java | 2 + 10 files changed, 322 insertions(+), 190 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/8ef84661/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupContext.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupContext.java index a482b5e..2f379a0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupContext.java @@ -788,19 +788,20 @@ public class CacheGroupContext { UUID originalReceivedFrom, boolean affinityNode ) throws IgniteCheckedException { - if (recoveryMode.compareAndSet(true, false)) { - affNode = affinityNode; + if (!recoveryMode.compareAndSet(true, false)) + return; - rcvdFrom = originalReceivedFrom; + affNode = affinityNode; - locStartVer = startVer; + rcvdFrom = originalReceivedFrom; - persistGlobalWalState(globalWalEnabled); + locStartVer = startVer; - initializeIO(); + persistGlobalWalState(globalWalEnabled); - ctx.affinity().onCacheGroupCreated(this); - } + initializeIO(); + + ctx.affinity().onCacheGroupCreated(this); } /** http://git-wip-us.apache.org/repos/asf/ignite/blob/8ef84661/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java index 9d282aa..ffb1886 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java @@ -245,7 +245,7 @@ public class GridCacheContext<K, V> implements Externalizable { private volatile AffinityTopologyVersion locStartTopVer; /** Dynamic cache deployment ID. */ - private IgniteUuid dynamicDeploymentId; + private volatile IgniteUuid dynamicDeploymentId; /** Updates allowed flag. */ private boolean updatesAllowed; @@ -316,8 +316,10 @@ public class GridCacheContext<K, V> implements Externalizable { CacheGroupContext grp, CacheType cacheType, AffinityTopologyVersion locStartTopVer, + IgniteUuid deploymentId, boolean affNode, boolean updatesAllowed, + boolean statisticsEnabled, boolean recoveryMode, /* @@ -406,8 +408,11 @@ public class GridCacheContext<K, V> implements Externalizable { readFromBackup = cacheCfg.isReadFromBackup(); + this.dynamicDeploymentId = deploymentId; this.recoveryMode = recoveryMode; + statisticsEnabled(statisticsEnabled); + assert kernalContext().recoveryMode() == recoveryMode; if (!recoveryMode) { @@ -421,10 +426,9 @@ public class GridCacheContext<K, V> implements Externalizable { * Called when cache was restored during recovery and node has joined to topology. * * @param topVer Cache topology join version. - * @param statisticsEnabled Flag indicates is statistics enabled or not for that cache. - * Value may be changed after node joined to topology. + * @param clusterWideDesc Cluster-wide cache descriptor received during exchange. */ - public void finishRecovery(AffinityTopologyVersion topVer, boolean statisticsEnabled) { + public void finishRecovery(AffinityTopologyVersion topVer, DynamicCacheDescriptor clusterWideDesc) { assert recoveryMode : this; recoveryMode = false; @@ -433,9 +437,10 @@ public class GridCacheContext<K, V> implements Externalizable { locMacs = localNode().attribute(ATTR_MACS); - this.statisticsEnabled = statisticsEnabled; - assert locMacs != null; + + this.statisticsEnabled = clusterWideDesc.cacheConfiguration().isStatisticsEnabled(); + this.dynamicDeploymentId = clusterWideDesc.deploymentId(); } /** @@ -467,13 +472,6 @@ public class GridCacheContext<K, V> implements Externalizable { } /** - * @param dynamicDeploymentId Dynamic deployment ID. - */ - void dynamicDeploymentId(IgniteUuid dynamicDeploymentId) { - this.dynamicDeploymentId = dynamicDeploymentId; - } - - /** * @return Dynamic deployment ID. */ public IgniteUuid dynamicDeploymentId() { http://git-wip-us.apache.org/repos/asf/ignite/blob/8ef84661/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContextInfo.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContextInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContextInfo.java index e72d183..673c32e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContextInfo.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContextInfo.java @@ -60,7 +60,7 @@ public class GridCacheContextInfo<K, V> { this.gridCacheContext = gridCacheContext; this.ctx = gridCacheContext.kernalContext(); this.config = gridCacheContext.config(); - this.dynamicDeploymentId = gridCacheContext.dynamicDeploymentId(); + this.dynamicDeploymentId = null; this.groupId = gridCacheContext.groupId(); this.cacheId = gridCacheContext.cacheId(); this.clientCache = clientCache; @@ -136,6 +136,13 @@ public class GridCacheContextInfo<K, V> { * @return Dynamic deployment ID. */ public IgniteUuid dynamicDeploymentId() { + GridCacheContext ctx = gridCacheContext; + + if (ctx != null) + return ctx.dynamicDeploymentId(); + + assert dynamicDeploymentId != null : "Deployment id is not set and cache context is not initialized: " + this; + return dynamicDeploymentId; } http://git-wip-us.apache.org/repos/asf/ignite/blob/8ef84661/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 fe56dcc..885ee22 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 @@ -1573,8 +1573,10 @@ public class GridCacheProcessor extends GridProcessorAdapter { grp, desc.cacheType(), locStartTopVer, + desc.deploymentId(), affNode, updatesAllowed, + desc.cacheConfiguration().isStatisticsEnabled(), recoveryMode, /* * Managers in starting order! @@ -1594,8 +1596,6 @@ public class GridCacheProcessor extends GridProcessorAdapter { affMgr ); - cacheCtx.statisticsEnabled(desc.cacheConfiguration().isStatisticsEnabled()); - cacheCtx.cacheObjectContext(cacheObjCtx); GridCacheAdapter cache = null; @@ -1710,8 +1710,10 @@ public class GridCacheProcessor extends GridProcessorAdapter { grp, desc.cacheType(), locStartTopVer, + desc.deploymentId(), affNode, true, + desc.cacheConfiguration().isStatisticsEnabled(), recoveryMode, /* * Managers in starting order! @@ -1731,8 +1733,6 @@ public class GridCacheProcessor extends GridProcessorAdapter { affMgr ); - cacheCtx.statisticsEnabled(desc.cacheConfiguration().isStatisticsEnabled()); - cacheCtx.cacheObjectContext(cacheObjCtx); GridDhtCacheAdapter dht = null; @@ -2233,7 +2233,11 @@ public class GridCacheProcessor extends GridProcessorAdapter { if (cacheCtx.isRecoveryMode()) finishRecovery(exchTopVer, cacheCtx); else { - ctx.query().onCacheStart(new GridCacheContextInfo(cacheCtx, clientCache), desc.schema() != null ? desc.schema() : new QuerySchema(), desc.sql()); + ctx.query().onCacheStart( + new GridCacheContextInfo(cacheCtx, clientCache), + desc.schema() != null ? desc.schema() : new QuerySchema(), + desc.sql() + ); onCacheStarted(cacheCtx); } @@ -2298,7 +2302,7 @@ public class GridCacheProcessor extends GridProcessorAdapter { false ); - initCacheContext(cacheCtx, ccfg, desc.deploymentId()); + initCacheContext(cacheCtx, ccfg); return cacheCtx; } @@ -2330,9 +2334,10 @@ public class GridCacheProcessor extends GridProcessorAdapter { * @param cacheContext Cache context. * @throws IgniteCheckedException If failed. */ - private void finishRecovery(AffinityTopologyVersion cacheStartVer, - GridCacheContext<?, ?> cacheContext) throws IgniteCheckedException { - + private void finishRecovery( + AffinityTopologyVersion cacheStartVer, + GridCacheContext<?, ?> cacheContext + ) throws IgniteCheckedException { CacheGroupContext groupContext = cacheContext.group(); // Take cluster-wide cache descriptor and try to update local cache and cache group parameters. @@ -2344,7 +2349,7 @@ public class GridCacheProcessor extends GridProcessorAdapter { isLocalAffinity(updatedDescriptor.cacheConfiguration()) ); - cacheContext.finishRecovery(cacheStartVer, updatedDescriptor.cacheConfiguration().isStatisticsEnabled()); + cacheContext.finishRecovery(cacheStartVer, updatedDescriptor); if (cacheContext.config().getAtomicityMode() == TRANSACTIONAL_SNAPSHOT) sharedCtx.coordinators().ensureStarted(); @@ -2467,16 +2472,12 @@ public class GridCacheProcessor extends GridProcessorAdapter { * * @param cacheCtx Cache context to initializtion. * @param cfg Cache configuration. - * @param deploymentId Dynamic deployment ID. * @throws IgniteCheckedException if failed. */ private void initCacheContext( GridCacheContext<?, ?> cacheCtx, - CacheConfiguration cfg, - IgniteUuid deploymentId + CacheConfiguration cfg ) throws IgniteCheckedException { - cacheCtx.dynamicDeploymentId(deploymentId); - GridCacheAdapter cache = cacheCtx.cache(); sharedCtx.addCacheContext(cacheCtx); @@ -2584,7 +2585,7 @@ public class GridCacheProcessor extends GridProcessorAdapter { true ); - initCacheContext(cacheCtx, cfg, desc.deploymentId()); + initCacheContext(cacheCtx, cfg); cacheCtx.onStarted(); http://git-wip-us.apache.org/repos/asf/ignite/blob/8ef84661/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java index da5233a..65c8205 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java @@ -150,7 +150,7 @@ public class GridQueryProcessor extends GridProcessorAdapter { private final ConcurrentMap<QueryTypeNameKey, QueryTypeDescriptorImpl> typesByName = new ConcurrentHashMap<>(); /** */ - private final GridQueryIndexing idx; + private final @Nullable GridQueryIndexing idx; /** Value object context. */ private final CacheQueryObjectValueContext valCtx; http://git-wip-us.apache.org/repos/asf/ignite/blob/8ef84661/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgniteLogicalRecoveryTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgniteLogicalRecoveryTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgniteLogicalRecoveryTest.java index b919e41..f2f8dba 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgniteLogicalRecoveryTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgniteLogicalRecoveryTest.java @@ -23,6 +23,7 @@ import java.nio.ByteBuffer; import java.nio.file.OpenOption; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Objects; @@ -208,6 +209,8 @@ public class IgniteLogicalRecoveryTest extends GridCommonAbstractTest { cacheLoader.consistencyCheck(node); checkNoRebalanceAfterRecovery(); + + checkCacheContextsConsistencyAfterRecovery(); } /** @@ -242,6 +245,8 @@ public class IgniteLogicalRecoveryTest extends GridCommonAbstractTest { checkNoRebalanceAfterRecovery(); cacheLoader.consistencyCheck(node); + + checkCacheContextsConsistencyAfterRecovery(); } /** @@ -304,6 +309,8 @@ public class IgniteLogicalRecoveryTest extends GridCommonAbstractTest { for (int idx = 0; idx < 3; idx++) cacheLoader.consistencyCheck(grid(idx)); + + checkCacheContextsConsistencyAfterRecovery(); } /** @@ -337,6 +344,8 @@ public class IgniteLogicalRecoveryTest extends GridCommonAbstractTest { for (int idx = 0; idx < 3; idx++) cacheLoader.consistencyCheck(grid(idx)); + + checkCacheContextsConsistencyAfterRecovery(); } /** @@ -394,6 +403,47 @@ public class IgniteLogicalRecoveryTest extends GridCommonAbstractTest { cacheLoader.consistencyCheck(grid(idx)); } + /** + * Checks that cache contexts have consistent parameters after recovery finished and nodes have joined to topology. + */ + private void checkCacheContextsConsistencyAfterRecovery() throws Exception { + IgniteEx crd = grid(0); + + Collection<String> cacheNames = crd.cacheNames(); + + for (String cacheName : cacheNames) { + for (int nodeIdx = 1; nodeIdx < 3; nodeIdx++) { + IgniteEx node = grid(nodeIdx); + + GridCacheContext one = cacheContext(crd, cacheName); + GridCacheContext other = cacheContext(node, cacheName); + + checkCacheContextsConsistency(one, other); + } + } + } + + /** + * @return Cache context with given name from node. + */ + private GridCacheContext cacheContext(IgniteEx node, String cacheName) { + return node.cachex(cacheName).context(); + } + + /** + * Checks that cluster-wide parameters are consistent between two caches. + * + * @param one Cache context. + * @param other Cache context. + */ + private void checkCacheContextsConsistency(GridCacheContext one, GridCacheContext other) { + Assert.assertEquals(one.statisticsEnabled(), other.statisticsEnabled()); + Assert.assertEquals(one.dynamicDeploymentId(), other.dynamicDeploymentId()); + Assert.assertEquals(one.keepBinary(), other.keepBinary()); + Assert.assertEquals(one.updatesAllowed(), other.updatesAllowed()); + Assert.assertEquals(one.group().receivedFrom(), other.group().receivedFrom()); + } + /** {@inheritDoc} */ @Override protected FailureHandler getFailureHandler(String igniteInstanceName) { return new StopNodeFailureHandler(); http://git-wip-us.apache.org/repos/asf/ignite/blob/8ef84661/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java b/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java index 02857ae..ad04ded 100644 --- a/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridCacheTestContext.java @@ -49,6 +49,7 @@ import org.apache.ignite.internal.processors.cache.store.CacheOsStoreManager; import org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager; import org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager; import org.apache.ignite.internal.processors.plugin.CachePluginManager; +import org.apache.ignite.lang.IgniteUuid; import org.apache.ignite.testframework.junits.GridTestKernalContext; import static org.apache.ignite.testframework.junits.GridAbstractTest.defaultCacheConfiguration; @@ -88,9 +89,11 @@ public class GridCacheTestContext<K, V> extends GridCacheContext<K, V> { null, CacheType.USER, AffinityTopologyVersion.ZERO, + IgniteUuid.randomUuid(), true, true, false, + false, new CacheCompressionManager(), new GridCacheEventManager(), new CacheOsStoreManager(null, new CacheConfiguration()), http://git-wip-us.apache.org/repos/asf/ignite/blob/8ef84661/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexMultinodeTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexMultinodeTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexMultinodeTest.java new file mode 100644 index 0000000..37c82c2 --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexMultinodeTest.java @@ -0,0 +1,28 @@ +/* + * 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.index; + +/** + * A set of basic tests for caches with indexes in multi-node environment. + */ +public class BasicIndexMultinodeTest extends BasicIndexTest { + /** {@inheritDoc} */ + @Override protected int gridCount() { + return 3; + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/8ef84661/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java index 6425dbf..bd05de1 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java @@ -25,8 +25,8 @@ import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; import org.apache.ignite.IgniteCache; -import org.apache.ignite.cache.CacheKeyConfiguration; import org.apache.ignite.cache.QueryEntity; import org.apache.ignite.cache.QueryIndex; import org.apache.ignite.cache.query.SqlFieldsQuery; @@ -34,8 +34,10 @@ 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.IgniteInternalCache; import org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager; +import org.apache.ignite.internal.util.typedef.G; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; @@ -55,31 +57,30 @@ public class BasicIndexTest extends GridCommonAbstractTest { private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); /** */ - private Collection<QueryIndex> indexes; + private Collection<QueryIndex> indexes = Collections.emptyList(); /** */ private Integer inlineSize; /** */ - private Boolean isPersistenceEnabled; + private boolean isPersistenceEnabled; /** */ - private String affKeyFieldName; + private int gridCount = 1; - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { - assertNotNull(indexes); - assertNotNull(inlineSize); - assertNotNull(isPersistenceEnabled); - - for (QueryIndex index : indexes) { + for (QueryIndex index : indexes) index.setInlineSize(inlineSize); - } IgniteConfiguration igniteCfg = super.getConfiguration(igniteInstanceName); + igniteCfg.setConsistentId(igniteInstanceName); + igniteCfg.setDiscoverySpi( new TcpDiscoverySpi().setIpFinder(IP_FINDER) ); @@ -102,13 +103,6 @@ public class BasicIndexTest extends GridCommonAbstractTest { )) .setSqlIndexMaxInlineSize(inlineSize); - if (affKeyFieldName != null) { - ccfg.setKeyConfiguration(new CacheKeyConfiguration() - .setTypeName(Key.class.getTypeName()) - .setAffinityKeyFieldName(affKeyFieldName) - ); - } - igniteCfg.setCacheConfiguration(ccfg); if (isPersistenceEnabled) { @@ -122,7 +116,9 @@ public class BasicIndexTest extends GridCommonAbstractTest { return igniteCfg; } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @Override protected void beforeTest() throws Exception { super.beforeTest(); @@ -131,44 +127,41 @@ public class BasicIndexTest extends GridCommonAbstractTest { cleanPersistenceDir(); } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @Override protected void afterTest() throws Exception { stopAllGrids(); cleanPersistenceDir(); - indexes = null; - - inlineSize = null; - - isPersistenceEnabled = null; - - affKeyFieldName = null; - super.afterTest(); } + /** + * @return Grid count used in test. + */ + protected int gridCount() { + return gridCount; + } + /** */ @Test public void testNoIndexesNoPersistence() throws Exception { - indexes = Collections.emptyList(); - - isPersistenceEnabled = false; - - int[] inlineSizes = { 0, 10, 20, 50, 100 }; + int[] inlineSizes = {0, 10, 20, 50, 100}; for (int i : inlineSizes) { log().info("Checking inlineSize=" + i); inlineSize = i; - startGrid(); + startGridsMultiThreaded(gridCount()); populateCache(); checkAll(); - stopGrid(); + stopAllGrids(); } } @@ -184,40 +177,34 @@ public class BasicIndexTest extends GridCommonAbstractTest { new QueryIndex("valPojo") ); - isPersistenceEnabled = false; - - int[] inlineSizes = { 0, 10, 20, 50, 100 }; + int[] inlineSizes = {0, 10, 20, 50, 100}; for (int i : inlineSizes) { log().info("Checking inlineSize=" + i); inlineSize = i; - startGrid(); + startGridsMultiThreaded(gridCount()); populateCache(); checkAll(); - stopGrid(); + stopAllGrids(); } } /** */ @Test public void testDynamicIndexesNoPersistence() throws Exception { - indexes = Collections.emptyList(); - - isPersistenceEnabled = false; - - int[] inlineSizes = { 0, 10, 20, 50, 100 }; + int[] inlineSizes = {0, 10, 20, 50, 100}; for (int i : inlineSizes) { log().info("Checking inlineSize=" + i); inlineSize = i; - startGrid(); + startGridsMultiThreaded(gridCount()); populateCache(); @@ -232,41 +219,35 @@ public class BasicIndexTest extends GridCommonAbstractTest { checkAll(); - stopGrid(); + stopAllGrids(); } } /** */ @Test public void testNoIndexesWithPersistence() throws Exception { - indexes = Collections.emptyList(); - isPersistenceEnabled = true; - int[] inlineSizes = { 0, 10, 20, 50, 100 }; + int[] inlineSizes = {0, 10, 20, 50, 100}; for (int i : inlineSizes) { log().info("Checking inlineSize=" + i); inlineSize = i; - startGrid(); - - grid().cluster().active(true); + startGridsMultiThreaded(gridCount()); populateCache(); checkAll(); - stopGrid(); + stopAllGrids(); - startGrid(); - - grid().cluster().active(true); + startGridsMultiThreaded(gridCount()); checkAll(); - stopGrid(); + stopAllGrids(); cleanPersistenceDir(); } @@ -286,30 +267,26 @@ public class BasicIndexTest extends GridCommonAbstractTest { isPersistenceEnabled = true; - int[] inlineSizes = { 0, 10, 20, 50, 100 }; + int[] inlineSizes = {0, 10, 20, 50, 100}; for (int i : inlineSizes) { log().info("Checking inlineSize=" + i); inlineSize = i; - startGrid(); - - grid().cluster().active(true); + startGridsMultiThreaded(gridCount()); populateCache(); checkAll(); - stopGrid(); - - startGrid(); + stopAllGrids(); - grid().cluster().active(true); + startGridsMultiThreaded(gridCount()); checkAll(); - stopGrid(); + stopAllGrids(); cleanPersistenceDir(); } @@ -318,20 +295,16 @@ public class BasicIndexTest extends GridCommonAbstractTest { /** */ @Test public void testDynamicIndexesWithPersistence() throws Exception { - indexes = Collections.emptyList(); - isPersistenceEnabled = true; - int[] inlineSizes = { 0, 10, 20, 50, 100 }; + int[] inlineSizes = {0, 10, 20, 50, 100}; for (int i : inlineSizes) { log().info("Checking inlineSize=" + i); inlineSize = i; - startGrid(); - - grid().cluster().active(true); + startGridsMultiThreaded(gridCount()); populateCache(); @@ -346,15 +319,57 @@ public class BasicIndexTest extends GridCommonAbstractTest { checkAll(); - stopGrid(); + stopAllGrids(); - startGrid(); + startGridsMultiThreaded(gridCount()); - grid().cluster().active(true); + checkAll(); + + stopAllGrids(); + + cleanPersistenceDir(); + } + } + + /** */ + public void testDynamicIndexesDropWithPersistence() throws Exception { + isPersistenceEnabled = true; + + int[] inlineSizes = {0, 10, 20, 50, 100}; + + for (int i : inlineSizes) { + log().info("Checking inlineSize=" + i); + + inlineSize = i; + + startGridsMultiThreaded(gridCount()); + + populateCache(); + + String[] cols = { + "keyStr", + "keyLong", + "keyPojo", + "valStr", + "valLong", + "valPojo" + }; + + createDynamicIndexes(cols); + + checkAll(); + + dropDynamicIndexes(cols); + + checkAll(); + + stopAllGrids(); + + startGridsMultiThreaded(gridCount()); checkAll(); - stopGrid(); + stopAllGrids(); cleanPersistenceDir(); } @@ -363,44 +378,38 @@ public class BasicIndexTest extends GridCommonAbstractTest { /** */ @Test public void testNoIndexesWithPersistenceIndexRebuild() throws Exception { - indexes = Collections.emptyList(); - isPersistenceEnabled = true; - int[] inlineSizes = { 0, 10, 20, 50, 100 }; + int[] inlineSizes = {0, 10, 20, 50, 100}; for (int i : inlineSizes) { log().info("Checking inlineSize=" + i); inlineSize = i; - startGrid(); - - grid().cluster().active(true); + startGridsMultiThreaded(gridCount()); populateCache(); checkAll(); - Path idxPath = getIndexBinPath(); + List<Path> idxPaths = getIndexBinPaths(); // Shutdown gracefully to ensure there is a checkpoint with index.bin. // Otherwise index.bin rebuilding may not work. - grid().cluster().active(false); - - stopGrid(); + grid(0).cluster().active(false); - assertTrue(U.delete(idxPath)); + stopAllGrids(); - startGrid(); + idxPaths.forEach(idxPath -> assertTrue(U.delete(idxPath))); - grid().cluster().active(true); + startGridsMultiThreaded(gridCount()); - grid().cache(DEFAULT_CACHE_NAME).indexReadyFuture().get(); + grid(0).cache(DEFAULT_CACHE_NAME).indexReadyFuture().get(); checkAll(); - stopGrid(); + stopAllGrids(); cleanPersistenceDir(); } @@ -420,40 +429,36 @@ public class BasicIndexTest extends GridCommonAbstractTest { isPersistenceEnabled = true; - int[] inlineSizes = { 0, 10, 20, 50, 100 }; + int[] inlineSizes = {0, 10, 20, 50, 100}; for (int i : inlineSizes) { log().info("Checking inlineSize=" + i); inlineSize = i; - startGrid(); - - grid().cluster().active(true); + startGridsMultiThreaded(gridCount()); populateCache(); checkAll(); - Path idxPath = getIndexBinPath(); + List<Path> idxPaths = getIndexBinPaths(); // Shutdown gracefully to ensure there is a checkpoint with index.bin. // Otherwise index.bin rebuilding may not work. - grid().cluster().active(false); - - stopGrid(); + grid(0).cluster().active(false); - assertTrue(U.delete(idxPath)); + stopAllGrids(); - startGrid(); + idxPaths.forEach(idxPath -> assertTrue(U.delete(idxPath))); - grid().cluster().active(true); + startGridsMultiThreaded(gridCount()); - grid().cache(DEFAULT_CACHE_NAME).indexReadyFuture().get(); + grid(0).cache(DEFAULT_CACHE_NAME).indexReadyFuture().get(); checkAll(); - stopGrid(); + stopAllGrids(); cleanPersistenceDir(); } @@ -462,20 +467,16 @@ public class BasicIndexTest extends GridCommonAbstractTest { /** */ @Test public void testDynamicIndexesWithPersistenceIndexRebuild() throws Exception { - indexes = Collections.emptyList(); - isPersistenceEnabled = true; - int[] inlineSizes = { 0, 10, 20, 50, 100 }; + int[] inlineSizes = {0, 10, 20, 50, 100}; for (int i : inlineSizes) { log().info("Checking inlineSize=" + i); inlineSize = i; - startGrid(); - - grid().cluster().active(true); + startGridsMultiThreaded(gridCount()); populateCache(); @@ -490,25 +491,23 @@ public class BasicIndexTest extends GridCommonAbstractTest { checkAll(); - Path idxPath = getIndexBinPath(); + List<Path> idxPaths = getIndexBinPaths(); // Shutdown gracefully to ensure there is a checkpoint with index.bin. // Otherwise index.bin rebuilding may not work. - grid().cluster().active(false); - - stopGrid(); + grid(0).cluster().active(false); - assertTrue(U.delete(idxPath)); + stopAllGrids(); - startGrid(); + idxPaths.forEach(idxPath -> assertTrue(U.delete(idxPath))); - grid().cluster().active(true); + startGridsMultiThreaded(gridCount()); - grid().cache(DEFAULT_CACHE_NAME).indexReadyFuture().get(); + grid(0).cache(DEFAULT_CACHE_NAME).indexReadyFuture().get(); checkAll(); - stopGrid(); + stopAllGrids(); cleanPersistenceDir(); } @@ -516,7 +515,7 @@ public class BasicIndexTest extends GridCommonAbstractTest { /** */ private void checkAll() { - IgniteCache<Key, Val> cache = grid().cache(DEFAULT_CACHE_NAME); + IgniteCache<Key, Val> cache = grid(0).cache(DEFAULT_CACHE_NAME); checkRemovePut(cache); @@ -533,7 +532,7 @@ public class BasicIndexTest extends GridCommonAbstractTest { /** */ private void populateCache() { - IgniteCache<Key, Val> cache = grid().cache(DEFAULT_CACHE_NAME); + IgniteCache<Key, Val> cache = grid(0).cache(DEFAULT_CACHE_NAME); // Be paranoid and populate first even indexes in ascending order, then odd indexes in descending // to check that inserting in the middle works. @@ -570,9 +569,9 @@ public class BasicIndexTest extends GridCommonAbstractTest { assertEquals(100, data.size()); for (List<?> row : data) { - Key key = (Key)row.get(0); + Key key = (Key) row.get(0); - Val val = (Val)row.get(1); + Val val = (Val) row.get(1); long i = key.keyLong; @@ -629,9 +628,9 @@ public class BasicIndexTest extends GridCommonAbstractTest { assertEquals(10, data.size()); for (List<?> row : data) { - Key key = (Key)row.get(0); + Key key = (Key) row.get(0); - Val val = (Val)row.get(1); + Val val = (Val) row.get(1); long i = key.keyLong; @@ -657,9 +656,9 @@ public class BasicIndexTest extends GridCommonAbstractTest { assertEquals(10, data.size()); for (List<?> row : data) { - Key key = (Key)row.get(0); + Key key = (Key) row.get(0); - Val val = (Val)row.get(1); + Val val = (Val) row.get(1); long i = key.keyLong; @@ -671,29 +670,54 @@ public class BasicIndexTest extends GridCommonAbstractTest { } } - /** Must be called when the grid is up. */ - private Path getIndexBinPath() { - IgniteInternalCache<Object, Object> cachex = grid().cachex(DEFAULT_CACHE_NAME); + /** + * Must be called when the grid is up. + */ + private List<Path> getIndexBinPaths() { + return G.allGrids().stream() + .map(grid -> (IgniteEx) grid) + .map(grid -> { + IgniteInternalCache<Object, Object> cachex = grid.cachex(DEFAULT_CACHE_NAME); - assertNotNull(cachex); + assertNotNull(cachex); - FilePageStoreManager pageStoreMgr = (FilePageStoreManager)cachex.context().shared().pageStore(); + FilePageStoreManager pageStoreMgr = (FilePageStoreManager) cachex.context().shared().pageStore(); - assertNotNull(pageStoreMgr); + assertNotNull(pageStoreMgr); - File cacheWorkDir = pageStoreMgr.cacheWorkDir(cachex.configuration()); + File cacheWorkDir = pageStoreMgr.cacheWorkDir(cachex.configuration()); - return cacheWorkDir.toPath().resolve("index.bin"); + return cacheWorkDir.toPath().resolve("index.bin"); + }) + .collect(Collectors.toList()); } /** */ private void createDynamicIndexes(String... cols) { - IgniteCache<Key, Val> cache = grid().cache(DEFAULT_CACHE_NAME); + IgniteCache<Key, Val> cache = grid(0).cache(DEFAULT_CACHE_NAME); for (String col : cols) { + String indexName = col + "_idx"; + String schemaName = DEFAULT_CACHE_NAME; + + cache.query(new SqlFieldsQuery( + String.format("create index %s on \"%s\".Val(%s) INLINE_SIZE %s;", indexName, schemaName, col, inlineSize) + )).getAll(); + } + + cache.indexReadyFuture().get(); + } + + /** */ + private void dropDynamicIndexes(String... cols) { + IgniteCache<Key, Val> cache = grid(0).cache(DEFAULT_CACHE_NAME); + + for (String col : cols) { + String indexName = col + "_idx"; + cache.query(new SqlFieldsQuery( - "create index on Val(" + col + ") INLINE_SIZE " + inlineSize - )); + String.format("drop index %s;", indexName) + )).getAll(); } cache.indexReadyFuture().get(); @@ -727,7 +751,9 @@ public class BasicIndexTest extends GridCommonAbstractTest { keyPojo = pojo; } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @Override public boolean equals(Object o) { if (this == o) return true; @@ -735,19 +761,23 @@ public class BasicIndexTest extends GridCommonAbstractTest { if (o == null || getClass() != o.getClass()) return false; - Key key = (Key)o; + Key key = (Key) o; return keyLong == key.keyLong && Objects.equals(keyStr, key.keyStr) && Objects.equals(keyPojo, key.keyPojo); } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @Override public int hashCode() { return Objects.hash(keyStr, keyLong, keyPojo); } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @Override public String toString() { return S.toString(Key.class, this); } @@ -771,7 +801,9 @@ public class BasicIndexTest extends GridCommonAbstractTest { valPojo = pojo; } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @Override public boolean equals(Object o) { if (this == o) return true; @@ -779,19 +811,23 @@ public class BasicIndexTest extends GridCommonAbstractTest { if (o == null || getClass() != o.getClass()) return false; - Val val = (Val)o; + Val val = (Val) o; return valLong == val.valLong && Objects.equals(valStr, val.valStr) && Objects.equals(valPojo, val.valPojo); } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @Override public int hashCode() { return Objects.hash(valStr, valLong, valPojo); } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @Override public String toString() { return S.toString(Val.class, this); } @@ -807,7 +843,9 @@ public class BasicIndexTest extends GridCommonAbstractTest { this.pojoLong = pojoLong; } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @Override public boolean equals(Object o) { if (this == o) return true; @@ -815,17 +853,21 @@ public class BasicIndexTest extends GridCommonAbstractTest { if (o == null || getClass() != o.getClass()) return false; - Pojo pojo = (Pojo)o; + Pojo pojo = (Pojo) o; return pojoLong == pojo.pojoLong; } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @Override public int hashCode() { return Objects.hash(pojoLong); } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @Override public String toString() { return S.toString(Pojo.class, this); } http://git-wip-us.apache.org/repos/asf/ignite/blob/8ef84661/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java index d510b11..363ab8a 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java @@ -119,6 +119,7 @@ import org.apache.ignite.internal.processors.cache.distributed.replicated.Ignite import org.apache.ignite.internal.processors.cache.distributed.replicated.IgniteCacheReplicatedQueryP2PDisabledSelfTest; import org.apache.ignite.internal.processors.cache.distributed.replicated.IgniteCacheReplicatedQuerySelfTest; import org.apache.ignite.internal.processors.cache.encryption.EncryptedSqlTableTest; +import org.apache.ignite.internal.processors.cache.index.BasicIndexMultinodeTest; import org.apache.ignite.internal.processors.cache.index.BasicIndexTest; import org.apache.ignite.internal.processors.cache.index.ComplexPrimaryKeyUnwrapSelfTest; import org.apache.ignite.internal.processors.cache.index.DuplicateKeyValueClassesSelfTest; @@ -270,6 +271,7 @@ public class IgniteBinaryCacheQueryTestSuite extends TestSuite { suite.addTestSuite(MultipleStatementsSqlQuerySelfTest.class); suite.addTestSuite(BasicIndexTest.class); + suite.addTestSuite(BasicIndexMultinodeTest.class); // Misc tests. suite.addTestSuite(QueryEntityValidationSelfTest.class);