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/05/29 14:32:13 UTC

[04/22] ignite git commit: IGNITE-5310: Fix to DML statement cache to decouple it from Ignite cache. This closes #2018.

IGNITE-5310: Fix to DML statement cache to decouple it from Ignite cache. This closes #2018.


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

Branch: refs/heads/ignite-5075
Commit: b673bdb58ccf9bf5a959cf43423ba4316535caa6
Parents: 40851c7
Author: devozerov <vo...@gridgain.com>
Authored: Sat May 27 16:40:43 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Sat May 27 16:40:43 2017 +0300

----------------------------------------------------------------------
 .../query/h2/DmlStatementsProcessor.java        | 27 ++++----
 .../processors/query/h2/H2DmlPlanKey.java       | 66 ++++++++++++++++++++
 2 files changed, 79 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b673bdb5/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
index 47b5ef4..0474aeb 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
@@ -30,7 +30,6 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.TimeUnit;
 import javax.cache.processor.EntryProcessor;
@@ -105,7 +104,8 @@ public class DmlStatementsProcessor {
     private static final int PLAN_CACHE_SIZE = 1024;
 
     /** Update plans cache. */
-    private final ConcurrentMap<String, ConcurrentMap<String, UpdatePlan>> planCache = new ConcurrentHashMap<>();
+    private final ConcurrentMap<H2DmlPlanKey, UpdatePlan> planCache =
+        new GridBoundedConcurrentLinkedHashMap<>(PLAN_CACHE_SIZE);
 
     /**
      * Constructor.
@@ -125,7 +125,14 @@ public class DmlStatementsProcessor {
      * @param cacheName Cache name.
      */
     public void onCacheStop(String cacheName) {
-        planCache.remove(idx.schema(cacheName));
+        Iterator<Map.Entry<H2DmlPlanKey, UpdatePlan>> iter = planCache.entrySet().iterator();
+
+        while (iter.hasNext()) {
+            UpdatePlan plan = iter.next().getValue();
+
+            if (F.eq(cacheName, plan.tbl.cacheName()))
+                iter.remove();
+        }
     }
 
     /**
@@ -408,17 +415,9 @@ public class DmlStatementsProcessor {
         throws IgniteCheckedException {
         Prepared p = GridSqlQueryParser.prepared(prepStmt);
 
-        ConcurrentMap<String, UpdatePlan> cachePlans = planCache.get(schema);
-
-        if (cachePlans == null) {
-            cachePlans = new GridBoundedConcurrentLinkedHashMap<>(PLAN_CACHE_SIZE);
-
-            cachePlans = U.firstNotNull(planCache.putIfAbsent(schema, cachePlans), cachePlans);
-        }
+        H2DmlPlanKey planKey = new H2DmlPlanKey(schema, p.getSQL());
 
-        // getSQL returns field value, so it's fast
-        // Don't look for re-runs in cache, we don't cache them
-        UpdatePlan res = (errKeysPos == null ? cachePlans.get(p.getSQL()) : null);
+        UpdatePlan res = (errKeysPos == null ? planCache.get(planKey) : null);
 
         if (res != null)
             return res;
@@ -427,7 +426,7 @@ public class DmlStatementsProcessor {
 
         // Don't cache re-runs
         if (errKeysPos == null)
-            return U.firstNotNull(cachePlans.putIfAbsent(p.getSQL(), res), res);
+            return U.firstNotNull(planCache.putIfAbsent(planKey, res), res);
         else
             return res;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/b673bdb5/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2DmlPlanKey.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2DmlPlanKey.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2DmlPlanKey.java
new file mode 100644
index 0000000..3a43ea1
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2DmlPlanKey.java
@@ -0,0 +1,66 @@
+/*
+ * 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;
+
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+/**
+ * H2 DML plan key.
+ */
+public class H2DmlPlanKey {
+    /** Schema name. */
+    private final String schemaName;
+
+    /** SQL. */
+    private final String sql;
+
+    /**
+     * Constructor.
+     *
+     * @param schemaName Schema name.
+     * @param sql SQL.
+     */
+    public H2DmlPlanKey(String schemaName, String sql) {
+        this.schemaName = schemaName;
+        this.sql = sql;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        return 31 * (schemaName != null ? schemaName.hashCode() : 0) + (sql != null ? sql.hashCode() : 0);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        H2DmlPlanKey other = (H2DmlPlanKey)o;
+
+        return F.eq(sql, other.sql) && F.eq(schemaName, other.schemaName);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(H2DmlPlanKey.class, this);
+    }
+}