ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [33/50] [abbrv] ignite git commit: ignite-split2 - fixes
Date Mon, 15 Feb 2016 07:52:17 GMT
ignite-split2 - fixes


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

Branch: refs/heads/ignite-1232
Commit: 9397c199122e2cdccab89b4026eb40e965962a90
Parents: b1a38a9
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Sun Dec 20 18:41:51 2015 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Sun Dec 20 18:41:51 2015 +0300

----------------------------------------------------------------------
 .../processors/query/h2/IgniteH2Indexing.java   | 93 ++++++++------------
 .../query/h2/opt/GridH2CollocationModel.java    | 28 +++---
 .../query/h2/opt/GridH2TreeIndex.java           |  7 +-
 .../query/h2/twostep/GridMapQueryExecutor.java  | 12 +--
 .../h2/twostep/GridReduceQueryExecutor.java     |  6 +-
 5 files changed, 68 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/9397c199/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 b16b48e..23e7ec4 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
@@ -120,7 +120,6 @@ import org.apache.ignite.resources.LoggerResource;
 import org.apache.ignite.spi.indexing.IndexingQueryFilter;
 import org.h2.api.JavaObjectSerializer;
 import org.h2.command.CommandInterface;
-import org.h2.command.dml.OptimizerHints;
 import org.h2.engine.Session;
 import org.h2.engine.SysProperties;
 import org.h2.index.Index;
@@ -728,21 +727,12 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     @Override public GridQueryFieldsResult queryLocalSqlFields(@Nullable final String spaceName,
final String qry,
         @Nullable final Collection<Object> params, final IndexingQueryFilter filters,
boolean enforceJoinOrder)
         throws IgniteCheckedException {
-        initLocalQueryContext(filters);
+        Connection conn = connectionForSpace(spaceName);
 
-        try {
-            Connection conn = connectionForSpace(spaceName);
-
-            enforceJoinOrder(enforceJoinOrder);
-
-            ResultSet rs;
+        initLocalQueryContext(conn, enforceJoinOrder, filters);
 
-            try {
-                rs = executeSqlQueryWithTimer(spaceName, conn, qry, params, true);
-            }
-            finally {
-                enforceJoinOrder(false);
-            }
+        try {
+            ResultSet rs = executeSqlQueryWithTimer(spaceName, conn, qry, params, true);
 
             List<GridQueryFieldMetadata> meta = null;
 
@@ -888,25 +878,6 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     }
 
     /**
-     * Executes query.
-     *
-     * @param space Space.
-     * @param qry Query.
-     * @param params Query parameters.
-     * @param tbl Target table of query to generate select.
-     * @return Result set.
-     * @throws IgniteCheckedException If failed.
-     */
-    private ResultSet executeQuery(String space, String qry, @Nullable Collection<Object>
params,
-        TableDescriptor tbl) throws IgniteCheckedException {
-        Connection conn = connectionForThread(tbl.schema());
-
-        String sql = generateQuery(qry, tbl);
-
-        return executeSqlQueryWithTimer(space, conn, sql, params, true);
-    }
-
-    /**
      * Binds parameters to prepared statement.
      *
      * @param stmt Prepared statement.
@@ -923,12 +894,28 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     }
 
     /**
+     * @param conn Connection.
+     * @param enforceJoinOrder Enforce join order of tables.
      * @param filter Filter.
      */
-    private void initLocalQueryContext(IndexingQueryFilter filter) {
+    private void initLocalQueryContext(Connection conn, boolean enforceJoinOrder, IndexingQueryFilter
filter) {
+        setupConnection(conn, false, enforceJoinOrder);
+
         GridH2QueryContext.set(new GridH2QueryContext(nodeId, nodeId, 0, LOCAL).filter(filter).distributedJoins(false));
     }
 
+    /**
+     * @param conn Connection to use.
+     * @param distributedJoins If distributed joins are enabled.
+     * @param enforceJoinOrder Enforce join order of tables.
+     */
+    public void setupConnection(Connection conn, boolean distributedJoins, boolean enforceJoinOrder)
{
+        Session s = session(conn);
+
+        s.setForceJoinOrder(enforceJoinOrder);
+        s.setJoinBatchEnabled(distributedJoins);
+    }
+
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
     @Override public <K, V> GridCloseableIterator<IgniteBiTuple<K, V>>
queryLocalSql(@Nullable String spaceName,
@@ -939,10 +926,14 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         if (tbl == null)
             throw new CacheException("Failed to find SQL table for type: " + type.name());
 
-        initLocalQueryContext(filter);
+        String sql = generateQuery(qry, tbl);
+
+        Connection conn = connectionForThread(tbl.schema());
+
+        initLocalQueryContext(conn, false, filter);
 
         try {
-            ResultSet rs = executeQuery(spaceName, qry, params, tbl);
+            ResultSet rs = executeSqlQueryWithTimer(spaceName, conn, sql, params, true);
 
             return new KeyValIterator(rs);
         }
@@ -1026,18 +1017,6 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     }
 
     /**
-     * @param enforce If {@code true}, then table join order will be enforced.
-     */
-    public void enforceJoinOrder(boolean enforce) {
-        OptimizerHints hints = null;
-        if (enforce) {
-            hints = new OptimizerHints();
-            hints.setJoinReorderEnabled(false);
-        }
-        OptimizerHints.set(hints);
-    }
-
-    /**
      * @param cctx Cache context.
      * @return {@code true} If the given cache is partitioned.
      */
@@ -1059,8 +1038,9 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         final String sqlQry = qry.getSql();
 
         Connection c = connectionForSpace(space);
+
         final boolean enforceJoinOrder = qry.isEnforceJoinOrder();
-        final boolean distributedJoins = qry.isDistributedJoins();
+        final boolean distributedJoins = qry.isDistributedJoins() && isPartitioned(cctx);
         final boolean groupByCollocated = qry.isCollocated();
 
         GridCacheTwoStepQuery twoStepQry;
@@ -1076,12 +1056,11 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         }
         else {
             final UUID locNodeId = ctx.localNodeId();
-            Session ses = session(c);
+
+            setupConnection(c, distributedJoins, enforceJoinOrder);
 
             GridH2QueryContext.set(new GridH2QueryContext(locNodeId, locNodeId, 0, PREPARE)
-                .distributedJoins(distributedJoins && isPartitioned(cctx)));
-            enforceJoinOrder(enforceJoinOrder);
-            ses.setJoinBatchEnabled(false);
+                .distributedJoins(distributedJoins));
 
             PreparedStatement stmt;
 
@@ -1092,8 +1071,6 @@ public class IgniteH2Indexing implements GridQueryIndexing {
                 throw new CacheException("Failed to parse query: " + sqlQry, e);
             }
             finally {
-                ses.setJoinBatchEnabled(true);
-                enforceJoinOrder(false);
                 GridH2QueryContext.clear(false);
             }
 
@@ -1429,7 +1406,11 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         if (tbl == null)
             return -1;
 
-        ResultSet rs = executeSqlQuery(connectionForSpace(spaceName),
+        Connection conn = connectionForSpace(spaceName);
+
+        setupConnection(conn, false, false);
+
+        ResultSet rs = executeSqlQuery(conn,
             "SELECT COUNT(*) FROM " + tbl.fullTableName(), null, false);
 
         try {

http://git-wip-us.apache.org/repos/asf/ignite/blob/9397c199/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2CollocationModel.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2CollocationModel.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2CollocationModel.java
index 2a1437c..95a2432 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2CollocationModel.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2CollocationModel.java
@@ -23,6 +23,7 @@ import java.util.List;
 import org.h2.command.dml.Query;
 import org.h2.command.dml.Select;
 import org.h2.command.dml.SelectUnion;
+import org.h2.expression.Comparison;
 import org.h2.expression.Expression;
 import org.h2.expression.ExpressionColumn;
 import org.h2.index.IndexCondition;
@@ -40,10 +41,10 @@ public final class GridH2CollocationModel {
     public static final int MULTIPLIER_COLLOCATED = 1;
 
     /** */
-    private static final int MULTIPLIER_UNICAST = 20;
+    private static final int MULTIPLIER_UNICAST = 50;
 
     /** */
-    private static final int MULTIPLIER_BROADCAST = 80;
+    private static final int MULTIPLIER_BROADCAST = 200;
 
     /** */
     private final GridH2CollocationModel upper;
@@ -285,7 +286,7 @@ public final class GridH2CollocationModel {
         for (int i = 0; i < idxConditions.size(); i++) {
             IndexCondition c = idxConditions.get(i);
 
-            if (c.getCompareType() == IndexCondition.EQUALITY &&
+            if (c.getCompareType() == Comparison.EQUAL &&
                 c.getColumn().getColumnId() == affColId && c.isEvaluatable()) {
                 affKeyConditionFound = true;
 
@@ -451,9 +452,13 @@ public final class GridH2CollocationModel {
         if (child == null && create && isChildTableOrView(i, null)) {
             TableFilter f = childFilters[i];
 
-            children[i] = child = f.getTable().isView() ?
-                buildCollocationModel(this, i, getSubQuery(f), null) :
-                createChildModel(this, i, null);
+            if (f.getTable().isView())
+                child = buildCollocationModel(this, i, getSubQuery(f), null);
+            else
+                child = createChildModel(this, i, null);
+
+            assert child != null;
+            assert children[i] == child;
         }
 
         return child;
@@ -558,10 +563,13 @@ public final class GridH2CollocationModel {
 
             SelectUnion union = (SelectUnion)qry;
 
-            GridH2CollocationModel a = buildCollocationModel(upper, filter, union.getLeft(),
unions);
-            GridH2CollocationModel b = buildCollocationModel(upper, filter, union.getRight(),
unions);
+            GridH2CollocationModel left = buildCollocationModel(upper, filter, union.getLeft(),
unions);
+            GridH2CollocationModel right = buildCollocationModel(upper, filter, union.getRight(),
unions);
+
+            assert left != null;
+            assert right != null;
 
-            return a == null ? b : a;
+            return upper != null ? upper : left;
         }
 
         Select select = (Select)qry;
@@ -586,7 +594,7 @@ public final class GridH2CollocationModel {
                 createChildModel(cm, i, null);
         }
 
-        return upper == null ? cm : null;
+        return upper != null ? upper : cm;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/9397c199/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 5641222..13414bd 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
@@ -1423,7 +1423,7 @@ public class GridH2TreeIndex extends GridH2IndexBase implements Comparator<GridS
 
                 if (res != null) {
                     switch (res.status()) {
-                        case GridH2IndexRangeResponse.STATUS_OK:
+                        case STATUS_OK:
                             List<GridH2RowRange> ranges0 = res.ranges();
 
                             remainingRanges -= ranges0.size();
@@ -1454,11 +1454,12 @@ public class GridH2TreeIndex extends GridH2IndexBase implements Comparator<GridS
                                 throw new IgniteInterruptedException(e.getMessage());
                             }
 
+                            // Retry to send the request once more after some time.
                             send(singletonList(node), req);
 
-                            continue;
+                            break;
 
-                        case GridH2IndexRangeResponse.STATUS_ERROR:
+                        case STATUS_ERROR:
                             throw new CacheException(res.error());
 
                         default:

http://git-wip-us.apache.org/repos/asf/ignite/blob/9397c199/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 d8b1180..7b7711a 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
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.processors.query.h2.twostep;
 
 import java.lang.reflect.Field;
+import java.sql.Connection;
 import java.sql.ResultSet;
 import java.util.AbstractCollection;
 import java.util.ArrayList;
@@ -511,19 +512,22 @@ public class GridMapQueryExecutor {
                 }
             }
 
+            Connection conn = h2.connectionForSpace(mainCache);
+
+            // Here we enforce join order to have the same behavior on all the nodes.
+            h2.setupConnection(conn, distributedJoins, true);
+
             GridH2QueryContext.set(qctx);
 
             // qctx is set, we have to release reservations inside of it.
             reserved = null;
 
-            h2.enforceJoinOrder(true);
-
             try {
                 // Run queries.
                 int i = 0;
 
                 for (GridCacheSqlQuery qry : qrys) {
-                    ResultSet rs = h2.executeSqlQueryWithTimer(mainCache, h2.connectionForSpace(mainCache),
qry.query(),
+                    ResultSet rs = h2.executeSqlQueryWithTimer(mainCache, conn, qry.query(),
                         F.asList(qry.parameters()), true);
 
                     if (ctx.event().isRecordable(EVT_CACHE_QUERY_EXECUTED)) {
@@ -559,8 +563,6 @@ public class GridMapQueryExecutor {
                 }
             }
             finally {
-                h2.enforceJoinOrder(false);
-
                 GridH2QueryContext.clear(distributedJoins);
 
                 if (!F.isEmpty(snapshotedTbls)) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/9397c199/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 6004629..fffb822 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
@@ -679,11 +679,11 @@ public class GridReduceQueryExecutor {
                     else {
                         UUID locNodeId = ctx.localNodeId();
 
+                        h2.setupConnection(r.conn, false, enforceJoinOrder);
+
                         GridH2QueryContext.set(new GridH2QueryContext(locNodeId, locNodeId,
qryReqId, REDUCE)
                             .pageSize(r.pageSize).distributedJoins(false));
 
-                        h2.enforceJoinOrder(enforceJoinOrder);
-
                         try {
                             if (qry.explain())
                                 return explainPlan(r.conn, space, qry);
@@ -699,8 +699,6 @@ public class GridReduceQueryExecutor {
                             resIter = new Iter(res);
                         }
                         finally {
-                            h2.enforceJoinOrder(false);
-
                             GridH2QueryContext.clear(false);
                         }
                     }


Mime
View raw message