Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 1BBDD200CA6 for ; Mon, 29 May 2017 16:32:12 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 1A5BD160BD9; Mon, 29 May 2017 14:32:12 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 418A6160BDF for ; Mon, 29 May 2017 16:32:11 +0200 (CEST) Received: (qmail 62998 invoked by uid 500); 29 May 2017 14:32:10 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 62945 invoked by uid 99); 29 May 2017 14:32:10 -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, 29 May 2017 14:32:10 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 31875E110C; Mon, 29 May 2017 14:32:10 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.apache.org Date: Mon, 29 May 2017 14:32:13 -0000 Message-Id: In-Reply-To: <1b37b15ab6864d2abdc2a6aad8572d52@git.apache.org> References: <1b37b15ab6864d2abdc2a6aad8572d52@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [04/22] ignite git commit: IGNITE-5310: Fix to DML statement cache to decouple it from Ignite cache. This closes #2018. archived-at: Mon, 29 May 2017 14:32:12 -0000 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 Authored: Sat May 27 16:40:43 2017 +0300 Committer: devozerov 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> planCache = new ConcurrentHashMap<>(); + private final ConcurrentMap 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> 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 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); + } +}