Repository: ignite
Updated Branches:
  refs/heads/ignite-2.7 9d2a4d5e3 -> 33f746562


IGNITE-9864: SQL: fixed timeout handling. This closes #4973.


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

Branch: refs/heads/ignite-2.7
Commit: 33f7465620000535a38705b3cddaf2660c8ef5ac
Parents: 9d2a4d5
Author: tledkov-gridgain <[email protected]>
Authored: Tue Oct 16 14:45:42 2018 +0300
Committer: devozerov <[email protected]>
Committed: Tue Oct 16 14:46:57 2018 +0300

----------------------------------------------------------------------
 .../processors/query/h2/IgniteH2Indexing.java   |  6 ++--
 .../h2/twostep/GridReduceQueryExecutor.java     | 16 ++++++---
 ...butedQueryStopOnCancelOrTimeoutSelfTest.java | 37 +++++++++++---------
 ...cheQueryAbstractDistributedJoinSelfTest.java |  5 +++
 ...nCancelOrTimeoutDistributedJoinSelfTest.java | 23 ++++++------
 .../Cache/Query/CacheQueriesTest.cs             |  6 ++--
 .../Client/Cache/SqlQueryTest.cs                |  2 +-
 7 files changed, 56 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/33f74656/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 be70343..162e3c5 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
@@ -1455,6 +1455,8 @@ public class IgniteH2Indexing implements 
GridQueryIndexing {
 
         if (timeoutMillis > 0)
             ses.setQueryTimeout(timeoutMillis);
+        else
+            ses.setQueryTimeout(0);
 
         try {
             return stmt.executeQuery();
@@ -1466,10 +1468,6 @@ public class IgniteH2Indexing implements 
GridQueryIndexing {
 
             throw new IgniteCheckedException("Failed to execute SQL query. " + 
e.getMessage(), e);
         }
-        finally {
-            if (timeoutMillis > 0)
-                ses.setQueryTimeout(0);
-        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/33f74656/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
----------------------------------------------------------------------
diff --git 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
index 62c5c78..d9c542b 100644
--- 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
+++ 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
@@ -287,11 +287,16 @@ public class GridReduceQueryExecutor {
      */
     private void fail(ReduceQueryRun r, UUID nodeId, String msg, byte 
failCode) {
         if (r != null) {
-            CacheException e = new CacheException("Failed to execute map query 
on remote node [nodeId=" + nodeId +
-                ", errMsg=" + msg + ']');
+            CacheException e;
 
-            if (failCode == GridQueryFailResponse.CANCELLED_BY_ORIGINATOR)
-                e.addSuppressed(new QueryCancelledException());
+            if (failCode == GridQueryFailResponse.CANCELLED_BY_ORIGINATOR) {
+                e = new CacheException("Failed to execute map query on remote 
node [nodeId=" + nodeId +
+                    ", errMsg=" + msg + ']', new QueryCancelledException());
+            }
+            else {
+                e = new CacheException("Failed to execute map query on remote 
node [nodeId=" + nodeId +
+                    ", errMsg=" + msg + ']');
+            }
 
             r.setStateOnException(nodeId, e);
         }
@@ -1218,6 +1223,9 @@ public class GridReduceQueryExecutor {
             }
         }
 
+        r.setStateOnException(ctx.localNodeId(),
+            new CacheException("Query is canceled.", new 
QueryCancelledException()));
+
         if (!runs.remove(qryReqId, r))
             U.warn(log, "Query run was already removed: " + qryReqId);
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/33f74656/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest.java
 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest.java
index 8542f43..67a9501 100644
--- 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest.java
+++ 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest.java
@@ -100,82 +100,82 @@ public class 
IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest extends Gr
 
     /** */
     public void testRemoteQueryExecutionTimeout() throws Exception {
-        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_1, 500, 
TimeUnit.MILLISECONDS, true);
+        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_1, 500, 
TimeUnit.MILLISECONDS, true, true);
     }
 
     /** */
     public void testRemoteQueryWithMergeTableTimeout() throws Exception {
-        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_2, 500, 
TimeUnit.MILLISECONDS, true);
+        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_2, 500, 
TimeUnit.MILLISECONDS, true, false);
     }
 
     /** */
     public void testRemoteQueryExecutionCancel0() throws Exception {
-        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_1, 1, TimeUnit.MILLISECONDS, 
false);
+        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_1, 1, TimeUnit.MILLISECONDS, 
false, true);
     }
 
     /** */
     public void testRemoteQueryExecutionCancel1() throws Exception {
-        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_1, 500, 
TimeUnit.MILLISECONDS, false);
+        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_1, 500, 
TimeUnit.MILLISECONDS, false, true);
     }
 
     /** */
     public void testRemoteQueryExecutionCancel2() throws Exception {
-        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_1, 1, TimeUnit.SECONDS, 
false);
+        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_1, 1, TimeUnit.SECONDS, 
false, true);
     }
 
     /** */
     public void testRemoteQueryExecutionCancel3() throws Exception {
-        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_1, 3, TimeUnit.SECONDS, 
false);
+        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_1, 3, TimeUnit.SECONDS, 
false, true);
     }
 
     /** */
     public void testRemoteQueryWithMergeTableCancel0() throws Exception {
-        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_2, 1, TimeUnit.MILLISECONDS, 
false);
+        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_2, 1, TimeUnit.MILLISECONDS, 
false, false);
     }
 
     /** */
     public void testRemoteQueryWithMergeTableCancel1() throws Exception {
-        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_2, 500, 
TimeUnit.MILLISECONDS, false);
+        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_2, 500, 
TimeUnit.MILLISECONDS, false, false);
     }
 
     /** */
     public void testRemoteQueryWithMergeTableCancel2() throws Exception {
-        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_2, 1_500, 
TimeUnit.MILLISECONDS, false);
+        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_2, 1_500, 
TimeUnit.MILLISECONDS, false, false);
     }
 
     /** */
     public void testRemoteQueryWithMergeTableCancel3() throws Exception {
-        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_2, 3, TimeUnit.SECONDS, 
false);
+        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_2, 3, TimeUnit.SECONDS, 
false, false);
     }
 
     /** */
     public void testRemoteQueryWithoutMergeTableCancel0() throws Exception {
-        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_3, 1, TimeUnit.MILLISECONDS, 
false);
+        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_3, 1, TimeUnit.MILLISECONDS, 
false, false);
     }
 
     /** */
     public void testRemoteQueryWithoutMergeTableCancel1() throws Exception {
-        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_3, 500, 
TimeUnit.MILLISECONDS, false);
+        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_3, 500, 
TimeUnit.MILLISECONDS, false, false);
     }
 
     /** */
     public void testRemoteQueryWithoutMergeTableCancel2() throws Exception {
-        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_3, 1_000, 
TimeUnit.MILLISECONDS, false);
+        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_3, 1_000, 
TimeUnit.MILLISECONDS, false, false);
     }
 
     /** */
     public void testRemoteQueryWithoutMergeTableCancel3() throws Exception {
-        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_3, 3, TimeUnit.SECONDS, 
false);
+        testQueryCancel(CACHE_SIZE, VAL_SIZE, QRY_3, 3, TimeUnit.SECONDS, 
false, false);
     }
 
     /** */
     public void testRemoteQueryAlreadyFinishedStop() throws Exception {
-        testQueryCancel(100, VAL_SIZE, QRY_3, 3, TimeUnit.SECONDS, false);
+        testQueryCancel(100, VAL_SIZE, QRY_3, 3, TimeUnit.SECONDS, false, 
false);
     }
 
     /** */
     private void testQueryCancel(int keyCnt, int valSize, String sql, int 
timeoutUnits, TimeUnit timeUnit,
-                                 boolean timeout) throws Exception {
+                                 boolean timeout, boolean checkCanceled) 
throws Exception {
         try (Ignite client = startGrid("client")) {
             IgniteCache<Object, Object> cache = 
client.cache(DEFAULT_CACHE_NAME);
 
@@ -215,7 +215,10 @@ public class 
IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest extends Gr
             }
 
             try (QueryCursor<List<?>> ignored = cursor) {
-                cursor.iterator();
+                cursor.getAll();
+
+                if (checkCanceled)
+                    fail("Query not canceled");
             }
             catch (CacheException ex) {
                 log().error("Got expected exception", ex);

http://git-wip-us.apache.org/repos/asf/ignite/blob/33f74656/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryAbstractDistributedJoinSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryAbstractDistributedJoinSelfTest.java
 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryAbstractDistributedJoinSelfTest.java
index 7e23c88..48b43a7 100644
--- 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryAbstractDistributedJoinSelfTest.java
+++ 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryAbstractDistributedJoinSelfTest.java
@@ -67,6 +67,11 @@ public class IgniteCacheQueryAbstractDistributedJoinSelfTest 
extends GridCommonA
         "where pr.companyId = co._key\n" +
         "order by co._key, pr._key ";
 
+    protected static final String QRY_LONG = "select pe.id, co.id, pr._key\n" +
+        "from \"pe\".Person pe, \"pr\".Product pr, \"co\".Company co, 
\"pu\".Purchase pu\n" +
+        "where pe._key = pu.personId and pu.productId = pr._key and 
pr.companyId = co._key \n" +
+        "order by pe.id desc";
+
     /** */
     protected static final int GRID_CNT = 2;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/33f74656/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest.java
 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest.java
index 03a8d49..9f8a2fc 100644
--- 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest.java
+++ 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest.java
@@ -40,47 +40,47 @@ import org.apache.ignite.internal.util.typedef.internal.U;
 public class IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest 
extends IgniteCacheQueryAbstractDistributedJoinSelfTest {
     /** */
     public void testCancel1() throws Exception {
-        testQueryCancel(grid(0), "pe", QRY_0, 1, TimeUnit.MILLISECONDS, false);
+        testQueryCancel(grid(0), "pe", QRY_LONG, 1, TimeUnit.MILLISECONDS, 
false, true);
     }
 
     /** */
     public void testCancel2() throws Exception {
-        testQueryCancel(grid(0), "pe", QRY_0, 50, TimeUnit.MILLISECONDS, 
false);
+        testQueryCancel(grid(0), "pe", QRY_LONG, 50, TimeUnit.MILLISECONDS, 
false, true);
     }
 
     /** */
     public void testCancel3() throws Exception {
-        testQueryCancel(grid(0), "pe", QRY_0, 100, TimeUnit.MILLISECONDS, 
false);
+        testQueryCancel(grid(0), "pe", QRY_LONG, 100, TimeUnit.MILLISECONDS, 
false, false);
     }
 
     /** */
     public void testCancel4() throws Exception {
-        testQueryCancel(grid(0), "pe", QRY_0, 500, TimeUnit.MILLISECONDS, 
false);
+        testQueryCancel(grid(0), "pe", QRY_LONG, 500, TimeUnit.MILLISECONDS, 
false, false);
     }
 
     /** */
     public void testTimeout1() throws Exception {
-        testQueryCancel(grid(0), "pe", QRY_0, 1, TimeUnit.MILLISECONDS, true);
+        testQueryCancel(grid(0), "pe", QRY_LONG, 1, TimeUnit.MILLISECONDS, 
true, true);
     }
 
     /** */
     public void testTimeout2() throws Exception {
-        testQueryCancel(grid(0), "pe", QRY_0, 50, TimeUnit.MILLISECONDS, true);
+        testQueryCancel(grid(0), "pe", QRY_LONG, 50, TimeUnit.MILLISECONDS, 
true, true);
     }
 
     /** */
     public void testTimeout3() throws Exception {
-        testQueryCancel(grid(0), "pe", QRY_0, 100, TimeUnit.MILLISECONDS, 
true);
+        testQueryCancel(grid(0), "pe", QRY_LONG, 100, TimeUnit.MILLISECONDS, 
true, false);
     }
 
     /** */
     public void testTimeout4() throws Exception {
-        testQueryCancel(grid(0), "pe", QRY_0, 500, TimeUnit.MILLISECONDS, 
true);
+        testQueryCancel(grid(0), "pe", QRY_LONG, 500, TimeUnit.MILLISECONDS, 
true, false);
     }
 
     /** */
     private void testQueryCancel(Ignite ignite, String cacheName, String sql, 
int timeoutUnits, TimeUnit timeUnit,
-                           boolean timeout) throws Exception {
+                           boolean timeout, boolean checkCanceled) throws 
Exception {
         SqlFieldsQuery qry = new SqlFieldsQuery(sql).setDistributedJoins(true);
 
         IgniteCache<Object, Object> cache = ignite.cache(cacheName);
@@ -101,7 +101,10 @@ public class 
IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest extend
         }
 
         try (QueryCursor<List<?>> ignored = cursor) {
-            cursor.iterator();
+            cursor.getAll();
+
+            if (checkCanceled)
+                fail("Query not canceled");
         }
         catch (CacheException ex) {
             log().error("Got expected exception", ex);

http://git-wip-us.apache.org/repos/asf/ignite/blob/33f74656/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs
----------------------------------------------------------------------
diff --git 
a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs
 
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs
index ceeeb37..f9c318f 100644
--- 
a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs
+++ 
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs
@@ -761,11 +761,11 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
         public void TestSqlQueryTimeout()
         {
             var cache = Cache();
-            PopulateCache(cache, false, 20000, x => true);
+            PopulateCache(cache, false, 30000, x => true);
 
-            var sqlQry = new SqlQuery(typeof(QueryPerson), "WHERE age < 500 
AND name like '%1%'")
+            var sqlQry = new SqlQuery(typeof(QueryPerson), "WHERE age < 2000")
             {
-                Timeout = TimeSpan.FromMilliseconds(2)
+                Timeout = TimeSpan.FromMilliseconds(1)
             };
 
             // ReSharper disable once ReturnValueOfPureMethodIsNotUsed

http://git-wip-us.apache.org/repos/asf/ignite/blob/33f74656/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/SqlQueryTest.cs
----------------------------------------------------------------------
diff --git 
a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/SqlQueryTest.cs
 
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/SqlQueryTest.cs
index d99fd156..760a48d 100644
--- 
a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/SqlQueryTest.cs
+++ 
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/SqlQueryTest.cs
@@ -152,7 +152,7 @@ namespace Apache.Ignite.Core.Tests.Client.Cache
 
             cache.PutAll(Enumerable.Range(1, 1000).ToDictionary(x => x, x => 
new Person(x)));
 
-            var qry = new SqlFieldsQuery("select * from Person p0, Person p1, 
Person p2'")
+            var qry = new SqlFieldsQuery("select * from Person p0, Person p1, 
Person p2")
             {
                 Timeout = TimeSpan.FromMilliseconds(1)
             };

Reply via email to