You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2019/02/04 08:16:52 UTC

[ignite] 01/08: Converted multiplier to enum.

This is an automated email from the ASF dual-hosted git repository.

vozerov pushed a commit to branch col_model
in repository https://gitbox.apache.org/repos/asf/ignite.git

commit 160e04c0580f7a50fae9403ddcb45e4e08675445
Author: devozerov <vo...@gridgain.com>
AuthorDate: Fri Feb 1 17:40:33 2019 +0300

    Converted multiplier to enum.
---
 .../processors/query/h2/opt/GridH2IndexBase.java   |  3 +-
 .../query/h2/opt/join/CollocationModel.java        | 54 +++++++++-------------
 .../h2/opt/join/CollocationModelMultiplier.java    | 54 ++++++++++++++++++++++
 3 files changed, 78 insertions(+), 33 deletions(-)

diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
index ab9929d..f353aff 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
@@ -30,6 +30,7 @@ import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree;
 import org.apache.ignite.internal.processors.query.QueryUtils;
 import org.apache.ignite.internal.processors.query.h2.H2Cursor;
 import org.apache.ignite.internal.processors.query.h2.H2Utils;
+import org.apache.ignite.internal.processors.query.h2.opt.join.CollocationModelMultiplier;
 import org.apache.ignite.internal.processors.query.h2.opt.join.CursorIteratorWrapper;
 import org.apache.ignite.internal.processors.query.h2.opt.join.DistributedLookupBatch;
 import org.apache.ignite.internal.processors.query.h2.opt.join.CollocationModel;
@@ -229,7 +230,7 @@ public abstract class GridH2IndexBase extends BaseIndex {
         // Query expressions can not be distributed as well.
         if (qctx == null || qctx.type() != PREPARE || qctx.distributedJoinMode() == OFF ||
             !ses.isJoinBatchEnabled() || ses.isPreparingQueryExpression())
-            return CollocationModel.MULTIPLIER_COLLOCATED;
+            return CollocationModelMultiplier.MULTIPLIER_COLLOCATED.multiplier();
 
         // We have to clear this cache because normally sub-query plan cost does not depend on anything
         // other than index condition masks and sort order, but in our case it can depend on order
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/join/CollocationModel.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/join/CollocationModel.java
index 03653c7..95895fe 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/join/CollocationModel.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/join/CollocationModel.java
@@ -47,18 +47,6 @@ import org.h2.table.TableView;
  */
 public final class CollocationModel {
     /** */
-    public static final int MULTIPLIER_COLLOCATED = 1;
-
-    /** */
-    private static final int MULTIPLIER_UNICAST = 50;
-
-    /** */
-    private static final int MULTIPLIER_BROADCAST = 200;
-
-    /** */
-    private static final int MULTIPLIER_REPLICATED_NOT_LAST = 10_000;
-
-    /** */
     private final CollocationModel upper;
 
     /** */
@@ -68,7 +56,7 @@ public final class CollocationModel {
     private final boolean view;
 
     /** */
-    private int multiplier;
+    private CollocationModelMultiplier multiplier;
 
     /** */
     private Type type;
@@ -234,7 +222,7 @@ public final class CollocationModel {
 
         // Reset results.
         type = null;
-        multiplier = 0;
+        multiplier = null;
 
         return true;
     }
@@ -252,14 +240,14 @@ public final class CollocationModel {
 
             boolean collocated = true;
             boolean partitioned = false;
-            int maxMultiplier = MULTIPLIER_COLLOCATED;
+            CollocationModelMultiplier maxMultiplier = CollocationModelMultiplier.MULTIPLIER_COLLOCATED;
 
             for (int i = 0; i < childFilters.length; i++) {
                 CollocationModel child = child(i, true);
 
                 Type t = child.type(true);
 
-                if (child.multiplier == MULTIPLIER_REPLICATED_NOT_LAST)
+                if (child.multiplier == CollocationModelMultiplier.MULTIPLIER_REPLICATED_NOT_LAST)
                     maxMultiplier = child.multiplier;
 
                 if (t.isPartitioned()) {
@@ -268,12 +256,12 @@ public final class CollocationModel {
                     if (!t.isCollocated()) {
                         collocated = false;
 
-                        int m = child.multiplier(true);
+                        CollocationModelMultiplier m = child.multiplier(true);
 
-                        if (m > maxMultiplier) {
+                        if (m.multiplier() > maxMultiplier.multiplier()) {
                             maxMultiplier = m;
 
-                            if (maxMultiplier == MULTIPLIER_REPLICATED_NOT_LAST)
+                            if (maxMultiplier == CollocationModelMultiplier.MULTIPLIER_REPLICATED_NOT_LAST)
                                 break;
                         }
                     }
@@ -293,7 +281,7 @@ public final class CollocationModel {
             // Only partitioned tables will do distributed joins.
             if (!(tbl instanceof GridH2Table) || !((GridH2Table)tbl).isPartitioned()) {
                 type = Type.REPLICATED;
-                multiplier = MULTIPLIER_COLLOCATED;
+                multiplier = CollocationModelMultiplier.MULTIPLIER_COLLOCATED;
 
                 return;
             }
@@ -303,7 +291,7 @@ public final class CollocationModel {
             // to all the affinity nodes the "base" does not need to get remote results.
             if (!upper.findPartitionedTableBefore(filter)) {
                 type = Type.PARTITIONED_COLLOCATED;
-                multiplier = MULTIPLIER_COLLOCATED;
+                multiplier = CollocationModelMultiplier.MULTIPLIER_COLLOCATED;
             }
             else {
                 // It is enough to make sure that our previous join by affinity key is collocated, then we are
@@ -311,19 +299,19 @@ public final class CollocationModel {
                 switch (upper.joinedWithCollocated(filter)) {
                     case COLLOCATED_JOIN:
                         type = Type.PARTITIONED_COLLOCATED;
-                        multiplier = MULTIPLIER_COLLOCATED;
+                        multiplier = CollocationModelMultiplier.MULTIPLIER_COLLOCATED;
 
                         break;
 
                     case HAS_AFFINITY_CONDITION:
                         type = Type.PARTITIONED_NOT_COLLOCATED;
-                        multiplier = MULTIPLIER_UNICAST;
+                        multiplier = CollocationModelMultiplier.MULTIPLIER_UNICAST;
 
                         break;
 
                     case NONE:
                         type = Type.PARTITIONED_NOT_COLLOCATED;
-                        multiplier = MULTIPLIER_BROADCAST;
+                        multiplier = CollocationModelMultiplier.MULTIPLIER_BROADCAST;
 
                         break;
 
@@ -333,7 +321,7 @@ public final class CollocationModel {
             }
 
             if (upper.previousReplicated(filter))
-                multiplier = MULTIPLIER_REPLICATED_NOT_LAST;
+                multiplier = CollocationModelMultiplier.MULTIPLIER_REPLICATED_NOT_LAST;
         }
     }
 
@@ -517,7 +505,7 @@ public final class CollocationModel {
      */
     public int calculateMultiplier() {
         // We don't need multiplier for union here because it will be summarized in H2.
-        return multiplier(false);
+        return multiplier(false).multiplier();
     }
 
     /**
@@ -525,21 +513,23 @@ public final class CollocationModel {
      * @return Multiplier.
      */
     @SuppressWarnings("ForLoopReplaceableByForEach")
-    private int multiplier(boolean withUnion) {
+    private CollocationModelMultiplier multiplier(boolean withUnion) {
         calculate();
 
-        assert multiplier != 0;
+        assert multiplier != null;
 
         if (withUnion && unions != null) {
-            int maxMultiplier = 0;
+            CollocationModelMultiplier maxMultiplier = null;
 
             for (int i = 0; i < unions.size(); i++) {
-                int m = unions.get(i).multiplier(false);
+                CollocationModelMultiplier m = unions.get(i).multiplier(false);
 
-                if (m > maxMultiplier)
+                if (maxMultiplier == null || m.multiplier() > maxMultiplier.multiplier())
                     maxMultiplier = m;
             }
 
+            assert maxMultiplier != null;
+
             return maxMultiplier;
         }
 
@@ -698,7 +688,7 @@ public final class CollocationModel {
 
         Type type = mdl.type(true);
 
-        if (!type.isCollocated() && mdl.multiplier == MULTIPLIER_REPLICATED_NOT_LAST)
+        if (!type.isCollocated() && mdl.multiplier == CollocationModelMultiplier.MULTIPLIER_REPLICATED_NOT_LAST)
             throw new CacheException("Failed to execute query: for distributed join " +
                 "all REPLICATED caches must be at the end of the joined tables list.");
 
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/join/CollocationModelMultiplier.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/join/CollocationModelMultiplier.java
new file mode 100644
index 0000000..d173542
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/join/CollocationModelMultiplier.java
@@ -0,0 +1,54 @@
+/*
+ * 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.h2.opt.join;
+
+/**
+ * Multiplier for different collocation types.
+ */
+public enum CollocationModelMultiplier {
+    /** Tables are collocated, cheap. */
+    MULTIPLIER_COLLOCATED(1),
+
+    /** */
+    MULTIPLIER_UNICAST(50),
+
+    /** */
+    MULTIPLIER_BROADCAST(200),
+
+    /** Force REPLICATED tables to be at the end of join sequence. */
+    MULTIPLIER_REPLICATED_NOT_LAST(10_000);
+
+    /** Multiplier value. */
+    private final int multiplier;
+
+    /**
+     * Constructor.
+     *
+     * @param multiplier Multiplier value.
+     */
+    CollocationModelMultiplier(int multiplier) {
+        this.multiplier = multiplier;
+    }
+
+    /**
+     * @return Multiplier value.
+     */
+    public int multiplier() {
+        return multiplier;
+    }
+}