Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A66AF17E3F for ; Mon, 13 Apr 2015 12:24:08 +0000 (UTC) Received: (qmail 22992 invoked by uid 500); 13 Apr 2015 12:24:08 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 22953 invoked by uid 500); 13 Apr 2015 12:24:08 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 22944 invoked by uid 99); 13 Apr 2015 12:24:08 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Apr 2015 12:24:08 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 13 Apr 2015 12:23:38 +0000 Received: (qmail 18254 invoked by uid 99); 13 Apr 2015 12:23:29 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Apr 2015 12:23:29 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 83FE0E0A90; Mon, 13 Apr 2015 12:23:29 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vozerov@apache.org To: commits@ignite.incubator.apache.org Date: Mon, 13 Apr 2015 12:23:56 -0000 Message-Id: <0060d378c9d940669441a31a451f441e@git.apache.org> In-Reply-To: <3a341a894e514edf9d4104fbed431bc4@git.apache.org> References: <3a341a894e514edf9d4104fbed431bc4@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [29/50] incubator-ignite git commit: ignite-718 - minor + test X-Virus-Checked: Checked by ClamAV on apache.org ignite-718 - minor + test Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/37f8fbe9 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/37f8fbe9 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/37f8fbe9 Branch: refs/heads/ignite-gg-9915 Commit: 37f8fbe97d4705d087331e3ba3c9a0595072979d Parents: 6a53351 Author: S.Vladykin Authored: Sat Apr 11 20:32:13 2015 +0300 Committer: S.Vladykin Committed: Sat Apr 11 20:32:13 2015 +0300 ---------------------------------------------------------------------- .../apache/ignite/IgniteSystemProperties.java | 7 ++ .../query/h2/twostep/GridMergeIndex.java | 12 ++- .../cache/IgniteCacheLargeResultSelfTest.java | 104 +++++++++++++++++++ 3 files changed, 118 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/37f8fbe9/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java index c4b30d6..ca7857c 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java @@ -337,6 +337,13 @@ public final class IgniteSystemProperties { public static final String IGNITE_JCACHE_DEFAULT_ISOLATED = "IGNITE_CACHE_CLIENT"; /** + * Property controlling maximum number of SQL result rows which can be fetched into a merge table. + * If there are less rows than this threshold then multiple passes throw a table will be possible, + * otherwise only one pass (e.g. only result streaming is possible). + */ + public static final String IGNITE_SQL_MERGE_TABLE_MAX_SIZE = "IGNITE_SQL_MERGE_TABLE_MAX_SIZE"; + + /** * Enforces singleton. */ private IgniteSystemProperties() { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/37f8fbe9/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndex.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndex.java index 5138013..407341e 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndex.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndex.java @@ -30,15 +30,17 @@ import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; +import static org.apache.ignite.IgniteSystemProperties.*; + /** * Merge index. */ public abstract class GridMergeIndex extends BaseIndex { /** */ - private static final int MAX_FETCH_SIZE = 100000; // TODO configure + private static final int MAX_FETCH_SIZE = getInteger(IGNITE_SQL_MERGE_TABLE_MAX_SIZE, 10_000); /** All rows number. */ - private final AtomicInteger rowsCnt = new AtomicInteger(0); + private final AtomicInteger expectedRowsCnt = new AtomicInteger(0); /** Remaining rows per source node ID. */ private final ConcurrentMap remainingRows = new ConcurrentHashMap8<>(); @@ -74,7 +76,7 @@ public abstract class GridMergeIndex extends BaseIndex { /** {@inheritDoc} */ @Override public long getRowCount(Session session) { - return rowsCnt.get(); + return expectedRowsCnt.get(); } /** {@inheritDoc} */ @@ -114,7 +116,7 @@ public abstract class GridMergeIndex extends BaseIndex { assert !cnt.initialized : "Counter is already initialized."; cnt.addAndGet(allRows); - rowsCnt.addAndGet(allRows); + expectedRowsCnt.addAndGet(allRows); // We need this separate flag to handle case when the first source contains only one page // and it will signal that all remaining counters are zero and fetch is finished. @@ -167,7 +169,7 @@ public abstract class GridMergeIndex extends BaseIndex { * @return {@code true} If we have fetched all the remote rows. */ public boolean fetchedAll() { - return fetchedCnt == rowsCnt.get(); + return fetchedCnt == expectedRowsCnt.get(); } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/37f8fbe9/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheLargeResultSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheLargeResultSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheLargeResultSelfTest.java new file mode 100644 index 0000000..3f88ad6 --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheLargeResultSelfTest.java @@ -0,0 +1,104 @@ +/* + * 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 org.apache.ignite.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.cache.query.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.spi.discovery.tcp.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; +import org.apache.ignite.testframework.junits.common.*; + +import java.util.*; + +import static org.apache.ignite.cache.CacheAtomicityMode.*; +import static org.apache.ignite.cache.CacheMode.*; + +/** + */ +public class IgniteCacheLargeResultSelfTest extends GridCommonAbstractTest { + /** */ + private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + disco.setIpFinder(ipFinder); + + cfg.setDiscoverySpi(disco); + + CacheConfiguration cacheCfg = defaultCacheConfiguration(); + + cacheCfg.setCacheMode(PARTITIONED); + cacheCfg.setAtomicityMode(TRANSACTIONAL); + cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + cacheCfg.setSwapEnabled(false); + cacheCfg.setBackups(1); + cacheCfg.setIndexedTypes( + Integer.class, Integer.class + ); + + cfg.setCacheConfiguration(cacheCfg); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + startGridsMultiThreaded(3); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + stopAllGrids(); + } + + /** + */ + public void testLargeResult() { + // Fill cache. + IgniteCache c = ignite(0).cache(null); + + for (int i = 0; i < 50_000; i++) // default max merge table size is 10000 + c.put(i, i); + + try(QueryCursor> res = c.query( + new SqlFieldsQuery("select _val from Integer where _key between ? and ?") + .setArgs(10_000, 40_000))){ + + int cnt = 0; + + for (List row : res) { + cnt++; + + int val = (Integer)row.get(0); + + assertTrue(val >= 10_000 && val <= 40_000); + } + + assertEquals(30_001, cnt); // Streaming of a large result works well. + } + + // Currently we have no ways to do multiple passes through a merge table. + } +}