Repository: ignite Updated Branches: refs/heads/master dc38a2562 -> dc6023d99
IGNITE-8545: SQL: added cache query parallelism validation. This closes #4702. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/dc6023d9 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/dc6023d9 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/dc6023d9 Branch: refs/heads/master Commit: dc6023d9901d88f87b6f7488b6f0d7ecf2f5d0c6 Parents: dc38a25 Author: Max-Pudov <pudov....@gmail.com> Authored: Thu Sep 20 18:14:56 2018 +0300 Committer: devozerov <voze...@gridgain.com> Committed: Thu Sep 20 18:14:56 2018 +0300 ---------------------------------------------------------------------- .../processors/cache/ClusterCachesInfo.java | 3 + .../processors/cache/GridCacheAttributes.java | 5 + .../query/IgniteSqlQueryParallelismTest.java | 202 +++++++++++++++++++ .../IgniteCacheQuerySelfTestSuite.java | 2 + 4 files changed, 212 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/dc6023d9/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 572e33e..8bed063 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 @@ -358,6 +358,9 @@ class ClusterCachesInfo { CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "affinityKeyBackups", "Affinity key backups", locAttr.affinityKeyBackups(), rmtAttr.affinityKeyBackups(), true); + + CU.checkAttributeMismatch(log, rmtAttr.cacheName(), rmt, "qryParallelism", + "Query parallelism", locAttr.qryParallelism(), rmtAttr.qryParallelism(), true); } } } http://git-wip-us.apache.org/repos/asf/ignite/blob/dc6023d9/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 faad1ec..01daee2 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 @@ -76,6 +76,11 @@ public class GridCacheAttributes implements Serializable { } /** + * @return Query parallelism. + */ + public int qryParallelism() { return ccfg.getQueryParallelism(); } + + /** * @return Cache mode. */ public CacheMode cacheMode() { http://git-wip-us.apache.org/repos/asf/ignite/blob/dc6023d9/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlQueryParallelismTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlQueryParallelismTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlQueryParallelismTest.java new file mode 100644 index 0000000..e432108 --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlQueryParallelismTest.java @@ -0,0 +1,202 @@ +/* + * 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.query; + +import java.io.Serializable; +import java.util.concurrent.Callable; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; +import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * A test against setting different values of query parallelism in cache configurations of the same cache. + */ +@SuppressWarnings("unchecked") +public class IgniteSqlQueryParallelismTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** */ + private boolean isClient = false; + + /** */ + private int qryParallelism = 4; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + cfg.setPeerClassLoadingEnabled(false); + + cfg.setClientMode(isClient); + + CacheConfiguration ccfg1 = cacheConfig("pers", Integer.class, Person2.class).setQueryParallelism(qryParallelism); + CacheConfiguration ccfg2 = cacheConfig("org", Integer.class, Organization.class).setQueryParallelism(qryParallelism); + + cfg.setCacheConfiguration(ccfg1, ccfg2); + + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + disco.setIpFinder(ipFinder); + + cfg.setDiscoverySpi(disco); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + startGridsMultiThreaded(3, false); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + stopAllGrids(); + } + + /** + * @param name Cache name. + * @param idxTypes Indexed types. + * @return Cache configuration. + */ + private static CacheConfiguration cacheConfig(String name, Class<?>... idxTypes) { + return new CacheConfiguration() + .setName(name) + .setCacheMode(CacheMode.PARTITIONED) + .setAtomicityMode(CacheAtomicityMode.ATOMIC) + .setBackups(1) + .setIndexedTypes(idxTypes); + } + + /** + * @throws Exception If failed. + */ + public void testIndexSegmentationOnClient() throws Exception { + IgniteCache<Object, Object> c1 = ignite(0).cache("org"); + IgniteCache<Object, Object> c2 = ignite(0).cache("pers"); + + c1.put(1, new Organization("o1")); + c1.put(2, new Organization("o2")); + c2.put(1, new Person2(1, "o1")); + c2.put(2, new Person2(2, "o2")); + c2.put(3, new Person2(3, "o3")); + + String select0 = "select o.name n1, p.name n2 from \"pers\".Person2 p join \"org\".Organization o on p.name = o.name"; + + GridTestUtils.assertThrows(log, new Callable<Object>() { + @Override public Object call() throws Exception { + isClient = true; + qryParallelism = 2; + + Ignite client = startGrid(4); + + return null; + } + }, IgniteCheckedException .class, "Query parallelism mismatch"); + } + + /** + * @throws Exception If failed. + */ + public void testIndexSegmentation() throws Exception { + IgniteCache<Object, Object> c1 = ignite(0).cache("org"); + IgniteCache<Object, Object> c2 = ignite(0).cache("pers"); + + c1.put(1, new Organization("o1")); + c1.put(2, new Organization("o2")); + c2.put(1, new Person2(1, "o1")); + c2.put(2, new Person2(2, "o2")); + c2.put(3, new Person2(3, "o3")); + + String select0 = "select o.name n1, p.name n2 from \"pers\".Person2 p join \"org\".Organization o on p.name = o.name"; + + GridTestUtils.assertThrows(log, new Callable<Object>() { + @Override public Object call() throws Exception { + qryParallelism = 2; + + Ignite client = startGrid(4); + + return null; + } + }, IgniteCheckedException .class, "Query parallelism mismatch"); + + } + + /** + * + */ + private static class Person2 implements Serializable { + /** */ + @QuerySqlField(index = true) + int orgId; + + /** */ + @QuerySqlField + String name; + + /** + * + */ + public Person2() { + // No-op. + } + + /** + * @param orgId Organization ID. + * @param name Name. + */ + public Person2(int orgId, String name) { + this.orgId = orgId; + this.name = name; + } + } + + /** + * + */ + private static class Organization implements Serializable { + /** */ + @QuerySqlField + String name; + + /** + * + */ + public Organization() { + // No-op. + } + + /** + * @param name Organization name. + */ + public Organization(String name) { + this.name = name; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/dc6023d9/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java index 6645099..7c8b2f8 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java @@ -158,6 +158,7 @@ import org.apache.ignite.internal.processors.query.IgniteSqlGroupConcatNotColloc import org.apache.ignite.internal.processors.query.IgniteSqlKeyValueFieldsTest; import org.apache.ignite.internal.processors.query.IgniteSqlNotNullConstraintTest; import org.apache.ignite.internal.processors.query.IgniteSqlParameterizedQueryTest; +import org.apache.ignite.internal.processors.query.IgniteSqlQueryParallelismTest; import org.apache.ignite.internal.processors.query.IgniteSqlRoutingTest; import org.apache.ignite.internal.processors.query.IgniteSqlSchemaIndexingTest; import org.apache.ignite.internal.processors.query.IgniteSqlSegmentedIndexMultiNodeSelfTest; @@ -426,6 +427,7 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite { suite.addTestSuite(IgniteCacheDistributedJoinQueryConditionsTest.class); suite.addTestSuite(IgniteCacheDistributedJoinTest.class); suite.addTestSuite(IgniteSqlDistributedJoinSelfTest.class); + suite.addTestSuite(IgniteSqlQueryParallelismTest.class); // Other. suite.addTestSuite(CacheIteratorScanQueryTest.class);