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 2016/02/15 08:51:58 UTC

[14/50] [abbrv] ignite git commit: ignite-split2 - minor

ignite-split2 - minor


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/94db68ad
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/94db68ad
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/94db68ad

Branch: refs/heads/ignite-1232
Commit: 94db68ad926b6f60e09b6c732ba68ce023fb3831
Parents: f356f4f
Author: S.Vladykin <sv...@gridgain.com>
Authored: Tue Dec 8 02:59:33 2015 +0300
Committer: S.Vladykin <sv...@gridgain.com>
Committed: Tue Dec 8 02:59:33 2015 +0300

----------------------------------------------------------------------
 .../processors/query/h2/IgniteH2Indexing.java   |  2 +-
 .../processors/query/h2/opt/GridH2Table.java    | 27 +++++++++-----
 .../query/h2/sql/GridSqlQuerySplitter.java      | 15 ++------
 .../query/h2/twostep/GridMapQueryExecutor.java  |  2 --
 .../h2/twostep/GridReduceQueryExecutor.java     | 38 ++++++++++++--------
 5 files changed, 45 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/94db68ad/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
index 067af47..89bf44c 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
@@ -1091,7 +1091,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             try {
                 bindParameters(stmt, F.asList(qry.getArgs()));
 
-                twoStepQry = GridSqlQuerySplitter.split((JdbcPreparedStatement)stmt, qry.getArgs(), qry.isCollocated(),
+                twoStepQry = GridSqlQuerySplitter.split((JdbcPreparedStatement)stmt, qry.getArgs(), groupByCollocated,
                     distributedJoins);
 
                 meta = meta(stmt.getMetaData());

http://git-wip-us.apache.org/repos/asf/ignite/blob/94db68ad/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
index 8ee00b9..ac21807 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
@@ -259,7 +259,7 @@ public class GridH2Table extends TableBase {
             ses.addLock(this);
         }
 
-        if (snapshotEnabled && snapshotInLock())
+        if (snapshotInLock())
             snapshotIndexes(null);
 
         return false;
@@ -269,7 +269,10 @@ public class GridH2Table extends TableBase {
      * @return {@code true} If we must snapshot and release index snapshots in {@link #lock(Session, boolean, boolean)}
      * and {@link #unlock(Session)} methods.
      */
-    private static boolean snapshotInLock() {
+    private boolean snapshotInLock() {
+        if (!snapshotEnabled)
+            return false;
+
         GridH2QueryContext qctx = GridH2QueryContext.get();
 
         return qctx == null || // Outside of Ignite query context.
@@ -279,9 +282,11 @@ public class GridH2Table extends TableBase {
 
     /**
      * @param qctx Query context.
-     * @return Snapshots.
      */
-    public Object[] snapshotIndexes(GridH2QueryContext qctx) {
+    public void snapshotIndexes(GridH2QueryContext qctx) {
+        if (!snapshotEnabled)
+            return;
+
         Object[] snapshots;
 
         Lock l;
@@ -294,7 +299,7 @@ public class GridH2Table extends TableBase {
                 snapshots = doSnapshotIndexes(snapshots, qctx);
 
                 if (snapshots != null)
-                    return snapshots; // Reused successfully.
+                    return; // Reused successfully.
             }
 
             l = lock(true, waitTime);
@@ -321,8 +326,6 @@ public class GridH2Table extends TableBase {
         finally {
             unlock(l);
         }
-
-        return snapshots;
     }
 
     /**
@@ -377,6 +380,8 @@ public class GridH2Table extends TableBase {
      */
     @SuppressWarnings("unchecked")
     private Object[] doSnapshotIndexes(Object[] snapshots, GridH2QueryContext qctx) {
+        assert snapshotEnabled;
+
         if (snapshots == null) // Nothing to reuse, create new snapshots.
             snapshots = new Object[idxs.size() - 1];
 
@@ -434,7 +439,7 @@ public class GridH2Table extends TableBase {
         if (ses != null && !sessions.remove(ses))
             return;
 
-        if (snapshotEnabled && snapshotInLock())
+        if (snapshotInLock())
             releaseSnapshots();
     }
 
@@ -442,7 +447,11 @@ public class GridH2Table extends TableBase {
      * Releases snapshots.
      */
     public void releaseSnapshots() {
-        for (int i = 1, len = idxs.size(); i < len; i++)  // Release snapshots on all except first which is scan.
+        if (!snapshotEnabled)
+            return;
+
+        // Release snapshots on all except first which is scan.
+        for (int i = 1, len = idxs.size(); i < len; i++)
             index(i).releaseSnapshot();
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/94db68ad/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
index 1bdb26a..a50c210 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
@@ -45,6 +45,7 @@ import static org.apache.ignite.internal.processors.query.h2.sql.GridSqlFunction
 import static org.apache.ignite.internal.processors.query.h2.sql.GridSqlPlaceholder.EMPTY;
 import static org.apache.ignite.internal.processors.query.h2.sql.GridSqlQueryParser.prepared;
 import static org.apache.ignite.internal.processors.query.h2.sql.GridSqlQueryParser.query;
+import static org.apache.ignite.internal.processors.query.h2.twostep.GridReduceQueryExecutor.toArray;
 
 /**
  * Splits a single SQL query into two step map-reduce query.
@@ -367,7 +368,7 @@ public class GridSqlQuerySplitter {
             findParams(mapQry, params, new ArrayList<>(params.length), paramIdxs).toArray());
 
         map.columns(collectColumns(mapExps));
-        map.parameterIndexes(toIntArray(paramIdxs));
+        map.parameterIndexes(toArray(paramIdxs));
 
         res.addMapQuery(map);
 
@@ -378,23 +379,13 @@ public class GridSqlQuerySplitter {
         GridCacheSqlQuery rdc = new GridCacheSqlQuery(rdcQry.getSQL(),
             findParams(rdcQry, params, new ArrayList<>(), paramIdxs).toArray());
 
-        rdc.parameterIndexes(toIntArray(paramIdxs));
+        rdc.parameterIndexes(toArray(paramIdxs));
         res.skipMergeTbl(rdcQry.simpleQuery());
 
         return rdc;
     }
 
     /**
-     * @param arr Integer array.
-     * @return Primitive int array.
-     */
-    private static int[] toIntArray(IntArray arr) {
-        int[] res = new int[arr.size()];
-        arr.toArray(res);
-        return res;
-    }
-
-    /**
      * @param cols Columns from SELECT clause.
      * @return Map of columns with types.
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/94db68ad/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
index 4fa204f..a88b3d9 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
@@ -19,8 +19,6 @@ package org.apache.ignite.internal.processors.query.h2.twostep;
 
 import java.lang.reflect.Field;
 import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
 import java.util.AbstractCollection;
 import java.util.ArrayList;
 import java.util.Collection;

http://git-wip-us.apache.org/repos/asf/ignite/blob/94db68ad/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
index f80539e..6e9bf21 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
@@ -108,7 +108,7 @@ public class GridReduceQueryExecutor {
     public static final byte QUERY_POOL = GridIoPolicy.SYSTEM_POOL;
 
     /** */
-    private static final IgniteProductVersion DISTRIBUTED_JOIN_SINCE = IgniteProductVersion.fromString("1.6.0");
+    private static final IgniteProductVersion DISTRIBUTED_JOIN_SINCE = IgniteProductVersion.fromString("1.4.0");
 
     /** */
     private GridKernalContext ctx;
@@ -514,15 +514,9 @@ public class GridReduceQueryExecutor {
 
             final long qryReqId = reqIdGen.incrementAndGet();
 
-            final QueryRun r = new QueryRun();
+            final String space = cctx.name();
 
-            r.pageSize = qry.pageSize() <= 0 ? GridCacheTwoStepQuery.DFLT_PAGE_SIZE : qry.pageSize();
-
-            r.idxs = new ArrayList<>(qry.mapQueries().size());
-
-            String space = cctx.name();
-
-            r.conn = (JdbcConnection)h2.connectionForSpace(space);
+            final QueryRun r = new QueryRun(h2.connectionForSpace(space), qry.mapQueries().size(), qry.pageSize());
 
             AffinityTopologyVersion topVer = h2.readyTopologyVersion();
 
@@ -1126,6 +1120,9 @@ public class GridReduceQueryExecutor {
         Message msg,
         @Nullable IgniteBiClosure<ClusterNode, Message, Message> specialize
     ) {
+        if (log.isDebugEnabled())
+            log.debug("Sending: [msg=" + msg + ", nodes=" + nodes + ", specialize=" + specialize + "]");
+
         return h2.send(GridTopic.TOPIC_QUERY, nodes, msg, specialize, locNodeHandler);
     }
 
@@ -1170,7 +1167,7 @@ public class GridReduceQueryExecutor {
      * @param ints Ints.
      * @return Array.
      */
-    private static int[] toArray(IntArray ints) {
+    public static int[] toArray(IntArray ints) {
         int[] res = new int[ints.size()];
 
         ints.toArray(res);
@@ -1186,7 +1183,7 @@ public class GridReduceQueryExecutor {
         if (m == null)
             return null;
 
-        Map<UUID,int[]> res = new HashMap<>(m.size());
+        Map<UUID,int[]> res = new HashMap<>(m.size(), 1f);
 
         for (Map.Entry<ClusterNode,IntArray> entry : m.entrySet())
             res.put(entry.getKey().id(), toArray(entry.getValue()));
@@ -1267,25 +1264,36 @@ public class GridReduceQueryExecutor {
     }
 
     /**
-     *
+     * Query run.
      */
     private static class QueryRun {
         /** */
-        private List<GridMergeIndex> idxs;
+        private final List<GridMergeIndex> idxs;
 
         /** */
         private CountDownLatch latch;
 
         /** */
-        private JdbcConnection conn;
+        private final JdbcConnection conn;
 
         /** */
-        private int pageSize;
+        private final int pageSize;
 
         /** Can be either CacheException in case of error or AffinityTopologyVersion to retry if needed. */
         private final AtomicReference<Object> state = new AtomicReference<>();
 
         /**
+         * @param conn Connection.
+         * @param idxsCnt Number of indexes.
+         * @param pageSize Page size.
+         */
+        private QueryRun(Connection conn, int idxsCnt, int pageSize) {
+            this.conn = (JdbcConnection)conn;
+            this.idxs = new ArrayList<>(idxsCnt);
+            this.pageSize = pageSize > 0 ? pageSize : GridCacheTwoStepQuery.DFLT_PAGE_SIZE;
+        }
+
+        /**
          * @param o Fail state object.
          * @param nodeId Node ID.
          */