ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anovi...@apache.org
Subject [10/50] [abbrv] ignite git commit: IGNITE-2009: Fixed leak in cached SQL queries.
Date Tue, 01 Dec 2015 09:02:22 GMT
IGNITE-2009: Fixed leak in cached SQL queries.


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

Branch: refs/heads/ignite-843-rc2
Commit: fc10b3e40fadd7ad792aaea63fe270c6413c5068
Parents: 3080f61
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Fri Nov 27 16:48:01 2015 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Fri Nov 27 16:48:01 2015 +0300

----------------------------------------------------------------------
 .../processors/query/h2/IgniteH2Indexing.java   | 24 +++++++++++++-------
 1 file changed, 16 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/fc10b3e4/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 cc452c1..1437a16 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
@@ -49,6 +49,7 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import javax.cache.Cache;
 import javax.cache.CacheException;
@@ -255,7 +256,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
                 set(c);
 
                 // Reset statement cache when new connection is created.
-                stmtCache.get().clear();
+                stmtCache.remove(Thread.currentThread());
             }
 
             return c;
@@ -280,12 +281,8 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     /** */
     private volatile GridKernalContext ctx;
 
-    /** */
-    private final ThreadLocal<StatementCache> stmtCache = new ThreadLocal<StatementCache>()
{
-        @Override protected StatementCache initialValue() {
-            return new StatementCache(PREPARED_STMT_CACHE_SIZE);
-        }
-    };
+    /** Statement cache. */
+    private final ConcurrentHashMap<Thread, StatementCache> stmtCache = new ConcurrentHashMap<>();
 
     /** */
     private final GridBoundedConcurrentLinkedHashMap<T3<String, String, Boolean>,
TwoStepCachedQuery> twoStepCache =
@@ -313,7 +310,18 @@ public class IgniteH2Indexing implements GridQueryIndexing {
      */
     private PreparedStatement prepareStatement(Connection c, String sql, boolean useStmtCache)
throws SQLException {
         if (useStmtCache) {
-            StatementCache cache = stmtCache.get();
+            Thread curThread = Thread.currentThread();
+
+            StatementCache cache = stmtCache.get(curThread);
+
+            if (cache == null) {
+                StatementCache cache0 = new StatementCache(PREPARED_STMT_CACHE_SIZE);
+
+                cache = stmtCache.putIfAbsent(curThread, cache0);
+
+                if (cache == null)
+                    cache = cache0;
+            }
 
             PreparedStatement stmt = cache.get(sql);
 


Mime
View raw message