Repository: ignite
Updated Branches:
  refs/heads/master 03dd9eb78 -> 05f5c070e


IGNITE-10823: SQL: Close tracked cursors on RunningQueryManager on node stop. 
This closes #5754.


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

Branch: refs/heads/master
Commit: 05f5c070e9ec1d00ace5f9ac7d5395d89fa36fba
Parents: 03dd9eb
Author: Yuriy Gerzhedovich <ygerzhedov...@gridgain.com>
Authored: Fri Dec 28 15:01:07 2018 +0300
Committer: devozerov <voze...@gridgain.com>
Committed: Fri Dec 28 15:01:07 2018 +0300

----------------------------------------------------------------------
 .../processors/query/RunningQueryManager.java   | 17 +++++++-
 .../processors/query/h2/IgniteH2Indexing.java   |  3 +-
 .../processors/query/RunningQueriesTest.java    | 44 ++++++++++++++++++++
 3 files changed, 61 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/05f5c070/modules/core/src/main/java/org/apache/ignite/internal/processors/query/RunningQueryManager.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/RunningQueryManager.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/RunningQueryManager.java
index d86d1f2..17b7894 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/RunningQueryManager.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/RunningQueryManager.java
@@ -25,7 +25,6 @@ import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.atomic.AtomicLong;
 import org.apache.ignite.internal.processors.cache.query.GridCacheQueryType;
 import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.util.typedef.internal.U;
 import org.jetbrains.annotations.Nullable;
 
 /**
@@ -123,6 +122,22 @@ public class RunningQueryManager {
             run.cancel();
     }
 
+    /**
+     * Cancel all executing queries and deregistering all of them.
+     */
+    public void stop() {
+        for (GridRunningQueryInfo r : runs.values()) {
+            try {
+                unregister(r.id());
+
+                r.cancel();
+            }
+            catch (Exception ignore) {
+                // No-op.
+            }
+        }
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(RunningQueryManager.class, this);

http://git-wip-us.apache.org/repos/asf/ignite/blob/05f5c070/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 f042089..53530a3 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
@@ -2489,9 +2489,8 @@ public class IgniteH2Indexing implements 
GridQueryIndexing {
 
         GridH2QueryContext.clearLocalNodeStop(nodeId);
 
+        runningQueryMgr.stop();
         schemaMgr.stop();
-
-        // Close system H2 connection to INFORMATION_SCHEMA
         connMgr.stop();
 
         if (log.isDebugEnabled())

http://git-wip-us.apache.org/repos/asf/ignite/blob/05f5c070/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/RunningQueriesTest.java
----------------------------------------------------------------------
diff --git 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/RunningQueriesTest.java
 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/RunningQueriesTest.java
index 4c29007..a98bd66 100644
--- 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/RunningQueriesTest.java
+++ 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/RunningQueriesTest.java
@@ -105,6 +105,8 @@ public class RunningQueriesTest extends 
GridCommonAbstractTest {
     @Override protected void beforeTest() throws Exception {
         super.beforeTest();
 
+        newBarrier(1);
+
         ignite.destroyCache(DEFAULT_CACHE_NAME);
 
         IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(new 
CacheConfiguration<Integer, Integer>()
@@ -193,7 +195,32 @@ public class RunningQueriesTest extends 
GridCommonAbstractTest {
     }
 
     /**
+     * Check clenup running queries on node stop.
+     *
+     * @throws Exception Exception in case of failure.
+     */
+    @Test
+    public void tesctCloseRunningQueriesOnNodeStop() throws Exception {
+        IgniteCache<Object, Object> cache = ignite.cache(DEFAULT_CACHE_NAME);
+
+        for (int i = 0; i < 10000; i++)
+            cache.put(i, i);
+
+        cache.query(new SqlFieldsQuery("SELECT * FROM Integer order by _key"));
+
+        Assert.assertEquals("Should be one running query",
+            1,
+            ignite.context().query().runningQueries(-1).size());
+
+        ignite.close();
+
+        assertNoRunningQueries();
+    }
+
+    /**
      * Check tracking running queries for Select.
+     *
+     * @throws Exception Exception in case of failure.
      */
     @Test
     public void testQueries() throws Exception {
@@ -229,6 +256,8 @@ public class RunningQueriesTest extends 
GridCommonAbstractTest {
 
     /**
      * Check tracking running queries for DELETE.
+     *
+     * @throws Exception Exception in case of failure.
      */
     @Test
     public void testQueryDmlDelete() throws Exception {
@@ -237,6 +266,8 @@ public class RunningQueriesTest extends 
GridCommonAbstractTest {
 
     /**
      * Check tracking running queries for INSERT.
+     *
+     * @throws Exception Exception in case of failure.
      */
     @Test
     public void testQueryDmlInsert() throws Exception {
@@ -245,6 +276,8 @@ public class RunningQueriesTest extends 
GridCommonAbstractTest {
 
     /**
      * Check tracking running queries for UPDATE.
+     *
+     * @throws Exception Exception in case of failure.
      */
     @Test
     public void testQueryDmlUpdate() throws Exception {
@@ -255,6 +288,7 @@ public class RunningQueriesTest extends 
GridCommonAbstractTest {
      * Check tracking running queries for DML.
      *
      * @param dmlQry DML query.
+     * @throws Exception Exception in case of failure.
      */
     public void testQueryDML(String dmlQry) throws Exception {
         newBarrier(2);
@@ -286,6 +320,8 @@ public class RunningQueriesTest extends 
GridCommonAbstractTest {
 
     /**
      * Check tracking running queries for DROP INDEX.
+     *
+     * @throws Exception Exception in case of failure.
      */
     @Test
     public void testQueryDdlDropIndex() throws Exception {
@@ -300,6 +336,8 @@ public class RunningQueriesTest extends 
GridCommonAbstractTest {
 
     /**
      * Check tracking running queries for CREATE INDEX.
+     *
+     * @throws Exception Exception in case of failure.
      */
     @Test
     public void testQueryDdlCreateIndex() throws Exception {
@@ -312,6 +350,8 @@ public class RunningQueriesTest extends 
GridCommonAbstractTest {
 
     /**
      * Check tracking running queries for DROP TABLE.
+     *
+     * @throws Exception Exception in case of failure.
      */
     @Test
     public void testQueryDdlDropTable() throws Exception {
@@ -324,6 +364,8 @@ public class RunningQueriesTest extends 
GridCommonAbstractTest {
 
     /**
      * Check tracking running queries for CREATE TABLE.
+     *
+     * @throws Exception Exception in case of failure.
      */
     @Test
     public void testQueryDdlCreateTable() throws Exception {
@@ -332,6 +374,8 @@ public class RunningQueriesTest extends 
GridCommonAbstractTest {
 
     /**
      * Check tracking running queries for DDL.
+     *
+     * @throws Exception Exception in case of failure.
      */
     public void testQueryDDL(String sql) throws Exception {
         newBarrier(2);

Reply via email to