You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2017/04/17 08:22:08 UTC
[46/50] [abbrv] ignite git commit: IGNITE-4992: Fix Segmented SQL
Index self tests. - Fixes #1801.
IGNITE-4992: Fix Segmented SQL Index self tests. - Fixes #1801.
Signed-off-by: Sergi Vladykin <se...@gmail.com>
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/0c0cf2c0
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/0c0cf2c0
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/0c0cf2c0
Branch: refs/heads/ignite-1561-1
Commit: 0c0cf2c00355ae2aec340473ed19dc5f0e0ddef0
Parents: 8fa438c
Author: Andrey V. Mashenkov <an...@gmail.com>
Authored: Sun Apr 16 15:28:20 2017 +0300
Committer: Sergi Vladykin <se...@gmail.com>
Committed: Sun Apr 16 15:28:20 2017 +0300
----------------------------------------------------------------------
.../query/h2/opt/GridH2TreeIndex.java | 2 +-
...gniteSqlSegmentedIndexMultiNodeSelfTest.java | 28 ++++
.../query/IgniteSqlSegmentedIndexSelfTest.java | 154 +++++++++++--------
.../IgniteCacheQuerySelfTestSuite.java | 2 +
4 files changed, 118 insertions(+), 68 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/0c0cf2c0/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java
index 4a12c78..cf75395 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java
@@ -290,7 +290,7 @@ public class GridH2TreeIndex extends GridH2IndexBase implements Comparator<GridS
* @return Row.
*/
@Override public GridH2Row findOne(GridH2Row row) {
- int seg = threadLocalSegment();
+ int seg = segmentForRow(row);
return segments[seg].findOne(row);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/0c0cf2c0/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSegmentedIndexMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSegmentedIndexMultiNodeSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSegmentedIndexMultiNodeSelfTest.java
new file mode 100644
index 0000000..549ea5e
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSegmentedIndexMultiNodeSelfTest.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.query;
+
+/**
+ * Tests for correct distributed queries with index consisted of many segments running on multi-node grid.
+ */
+public class IgniteSqlSegmentedIndexMultiNodeSelfTest extends IgniteSqlSegmentedIndexSelfTest {
+ /** {@inheritDoc} */
+ @Override protected int nodesCount() {
+ return 4;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/0c0cf2c0/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSegmentedIndexSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSegmentedIndexSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSegmentedIndexSelfTest.java
index 8408ad0..1715a56 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSegmentedIndexSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSegmentedIndexSelfTest.java
@@ -18,11 +18,13 @@
package org.apache.ignite.internal.processors.query;
import java.io.Serializable;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import javax.cache.Cache;
+import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.cache.CacheAtomicityMode;
import org.apache.ignite.cache.CacheKeyConfiguration;
@@ -45,8 +47,22 @@ public class IgniteSqlSegmentedIndexSelfTest extends GridCommonAbstractTest {
private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
/** */
- private static int QRY_PARALLELISM_LVL = 97;
+ private static final String ORG_CACHE_NAME = "org";
+
+ /** */
+ private static final String PERSON_CAHE_NAME = "pers";
+
+ /** */
+ private static final int ORG_CACHE_SIZE = 500;
+
+ /** */
+ private static final int PERSON_CACHE_SIZE = 1000;
+
+ /** */
+ private static final int ORPHAN_ROWS = 10;
+ /** */
+ private static int QRY_PARALLELISM_LVL = 97;
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
@@ -67,9 +83,26 @@ public class IgniteSqlSegmentedIndexSelfTest extends GridCommonAbstractTest {
return cfg;
}
+ /** @return number of nodes to be prestarted. */
+ protected int nodesCount() {
+ return 1;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ startGridsMultiThreaded(nodesCount(), false);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+ }
+
/** {@inheritDoc} */
@Override protected void afterTest() throws Exception {
- stopAllGrids(true);
+ super.afterTest();
+
+ grid(0).destroyCaches(Arrays.asList(PERSON_CAHE_NAME, ORG_CACHE_NAME));
}
/**
@@ -88,14 +121,11 @@ public class IgniteSqlSegmentedIndexSelfTest extends GridCommonAbstractTest {
}
/**
- * Run tests on single-node grid
* @throws Exception If failed.
*/
- public void testSingleNodeIndexSegmentation() throws Exception {
- startGridsMultiThreaded(1, true);
-
- ignite(0).createCache(cacheConfig("pers", true, Integer.class, Person.class));
- ignite(0).createCache(cacheConfig("org", true, Integer.class, Organization.class));
+ public void testSegmentedIndex() throws Exception {
+ ignite(0).createCache(cacheConfig(PERSON_CAHE_NAME, true, Integer.class, Person.class));
+ ignite(0).createCache(cacheConfig(ORG_CACHE_NAME, true, Integer.class, Organization.class));
fillCache();
@@ -106,13 +136,14 @@ public class IgniteSqlSegmentedIndexSelfTest extends GridCommonAbstractTest {
/**
* Run tests on single-node grid
+ *
* @throws Exception If failed.
*/
- public void testSingleNodeIndexSegmentationWithSwapEnabled() throws Exception {
- startGridsMultiThreaded(1, true);
-
- final IgniteCache<Object, Object> cache = ignite(0).createCache(cacheConfig("org", true, Integer.class, Organization.class)
- .setEvictionPolicy(new FifoEvictionPolicy(10)).setOnheapCacheEnabled(true));
+ public void testSegmentedIndexWithEvictionPolicy() throws Exception {
+ final IgniteCache<Object, Object> cache = ignite(0).createCache(
+ cacheConfig(ORG_CACHE_NAME, true, Integer.class, Organization.class)
+ .setEvictionPolicy(new FifoEvictionPolicy(10))
+ .setOnheapCacheEnabled(true));
for (int i = 0; i < 20; i++)
cache.put(i, new Organization("org-" + i));
@@ -126,30 +157,12 @@ public class IgniteSqlSegmentedIndexSelfTest extends GridCommonAbstractTest {
/**
* Run tests on multi-node grid
+ *
* @throws Exception If failed.
*/
- public void testMultiNodeIndexSegmentation() throws Exception {
- startGridsMultiThreaded(4, true);
-
- ignite(0).createCache(cacheConfig("pers", true, Integer.class, Person.class));
- ignite(0).createCache(cacheConfig("org", true, Integer.class, Organization.class));
-
- fillCache();
-
- checkDistributedQueryWithSegmentedIndex();
-
- checkLocalQueryWithSegmentedIndex();
- }
-
- /**
- * Run tests on multi-node grid
- * @throws Exception If failed.
- */
- public void testMultiNodeSegmentedPartitionedWithReplicated() throws Exception {
- startGridsMultiThreaded(4, true);
-
- ignite(0).createCache(cacheConfig("pers", true, Integer.class, Person.class));
- ignite(0).createCache(cacheConfig("org", false, Integer.class, Organization.class));
+ public void testSegmentedPartitionedWithReplicated() throws Exception {
+ ignite(0).createCache(cacheConfig(PERSON_CAHE_NAME, true, Integer.class, Person.class));
+ ignite(0).createCache(cacheConfig(ORG_CACHE_NAME, false, Integer.class, Organization.class));
fillCache();
@@ -160,71 +173,78 @@ public class IgniteSqlSegmentedIndexSelfTest extends GridCommonAbstractTest {
/**
* Check distributed joins.
+ *
* @throws Exception If failed.
*/
public void checkDistributedQueryWithSegmentedIndex() throws Exception {
- IgniteCache<Integer, Person> c1 = ignite(0).cache("pers");
+ for (int i = 0; i < nodesCount(); i++) {
+ IgniteCache<Integer, Person> c1 = ignite(i).cache(PERSON_CAHE_NAME);
- int expectedPersons = 0;
+ int expectedPersons = 0;
- for (Cache.Entry<Integer, Person> e : c1) {
- final Integer orgId = e.getValue().orgId;
+ for (Cache.Entry<Integer, Person> e : c1) {
+ final Integer orgId = e.getValue().orgId;
- if (10 <= orgId && orgId < 500)
- expectedPersons++;
- }
+ // We have as orphan ORG rows as orphan PERSON rows.
+ if (ORPHAN_ROWS <= orgId && orgId < 500)
+ expectedPersons++;
+ }
- String select0 = "select o.name n1, p.name n2 from \"pers\".Person p, \"org\".Organization o where p.orgId = o._key";
+ String select0 = "select o.name n1, p.name n2 from \"pers\".Person p, \"org\".Organization o where p.orgId = o._key";
- List<List<?>> result = c1.query(new SqlFieldsQuery(select0).setDistributedJoins(true)).getAll();
+ List<List<?>> result = c1.query(new SqlFieldsQuery(select0).setDistributedJoins(true)).getAll();
- assertEquals(expectedPersons, result.size());
+ assertEquals(expectedPersons, result.size());
+ }
}
/**
* Test local query.
+ *
* @throws Exception If failed.
*/
public void checkLocalQueryWithSegmentedIndex() throws Exception {
- IgniteCache<Integer, Person> c1 = ignite(0).cache("pers");
- IgniteCache<Integer, Organization> c2 = ignite(0).cache("org");
+ for (int i = 0; i < nodesCount(); i++) {
+ final Ignite node = ignite(i);
- Set<Integer> localOrgIds = new HashSet<>();
+ IgniteCache<Integer, Person> c1 = node.cache(PERSON_CAHE_NAME);
+ IgniteCache<Integer, Organization> c2 = node.cache(ORG_CACHE_NAME);
- for (Cache.Entry<Integer, Organization> e : c2.localEntries())
- localOrgIds.add(e.getKey());
+ Set<Integer> localOrgIds = new HashSet<>();
- int expectedPersons = 0;
+ for (Cache.Entry<Integer, Organization> e : c2.localEntries())
+ localOrgIds.add(e.getKey());
- for (Cache.Entry<Integer, Person> e : c1.localEntries()) {
- final Integer orgId = e.getValue().orgId;
+ int expectedPersons = 0;
- if (localOrgIds.contains(orgId))
- expectedPersons++;
- }
+ for (Cache.Entry<Integer, Person> e : c1.localEntries()) {
+ final Integer orgId = e.getValue().orgId;
+
+ if (localOrgIds.contains(orgId))
+ expectedPersons++;
+ }
- String select0 = "select o.name n1, p.name n2 from \"pers\".Person p, \"org\".Organization o where p.orgId = o._key";
+ String select0 = "select o.name n1, p.name n2 from \"pers\".Person p, \"org\".Organization o where p.orgId = o._key";
- List<List<?>> result = c1.query(new SqlFieldsQuery(select0).setLocal(true)).getAll();
+ List<List<?>> result = c1.query(new SqlFieldsQuery(select0).setLocal(true)).getAll();
- assertEquals(expectedPersons, result.size());
+ assertEquals(expectedPersons, result.size());
+ }
}
/** */
private void fillCache() {
- IgniteCache<Object, Object> c1 = ignite(0).cache("pers");
-
- IgniteCache<Object, Object> c2 = ignite(0).cache("org");
-
- final int orgCount = 500;
+ IgniteCache<Object, Object> c1 = ignite(0).cache(PERSON_CAHE_NAME);
+ IgniteCache<Object, Object> c2 = ignite(0).cache(ORG_CACHE_NAME);
- for (int i = 0; i < orgCount; i++)
+ for (int i = 0; i < ORG_CACHE_SIZE; i++)
c2.put(i, new Organization("org-" + i));
final Random random = new Random();
- for (int i = 0; i < 1000; i++) {
- int orgID = 10 + random.nextInt(orgCount + 10);
+ for (int i = 0; i < PERSON_CACHE_SIZE; i++) {
+ // We have as orphan ORG rows as orphan PERSON rows.
+ int orgID = ORPHAN_ROWS + random.nextInt(ORG_CACHE_SIZE + ORPHAN_ROWS);
c1.put(i, new Person(orgID, "pers-" + i));
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/0c0cf2c0/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 2d3ee0d..43083a8 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
@@ -91,6 +91,7 @@ import org.apache.ignite.internal.processors.cache.query.IndexingSpiQueryTxSelfT
import org.apache.ignite.internal.processors.query.IgniteQueryDedicatedPoolTest;
import org.apache.ignite.internal.processors.query.IgniteSqlEntryCacheModeAgnosticTest;
import org.apache.ignite.internal.processors.query.IgniteSqlSchemaIndexingTest;
+import org.apache.ignite.internal.processors.query.IgniteSqlSegmentedIndexMultiNodeSelfTest;
import org.apache.ignite.internal.processors.query.IgniteSqlSegmentedIndexSelfTest;
import org.apache.ignite.internal.processors.query.IgniteSqlSplitterSelfTest;
import org.apache.ignite.internal.processors.query.h2.GridH2IndexingInMemSelfTest;
@@ -130,6 +131,7 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite {
// Queries tests.
suite.addTestSuite(IgniteSqlSplitterSelfTest.class);
suite.addTestSuite(IgniteSqlSegmentedIndexSelfTest.class);
+ suite.addTestSuite(IgniteSqlSegmentedIndexMultiNodeSelfTest.class);
suite.addTestSuite(IgniteSqlSchemaIndexingTest.class);
suite.addTestSuite(GridCacheQueryIndexDisabledSelfTest.class);
suite.addTestSuite(IgniteCacheQueryLoadSelfTest.class);