Skip to content

Commit 8a039f1

Browse files
committed
Fix code and add checkRequestFutureMapEmpty to test
1 parent 098546c commit 8a039f1

File tree

3 files changed

+49
-24
lines changed

3 files changed

+49
-24
lines changed

modules/core/src/main/java/org/apache/ignite/internal/QueryMXBeanImpl.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,10 @@ private static class CancelScan implements IgniteClosure<T3<UUID, String, Long>,
176176
return null;
177177
}
178178

179-
GridCacheQueryManager qryMgr = ctx.queries();
179+
GridCacheQueryRequest cancelReq = GridCacheQueryRequest.cancelRequest(ctx, arg.get3(), false);
180180

181-
if (qryMgr instanceof GridCacheDistributedQueryManager) {
182-
GridCacheDistributedQueryManager distQryMgr = (GridCacheDistributedQueryManager) qryMgr;
183-
184-
GridCacheQueryRequest cancelReq = GridCacheQueryRequest.cancelRequest(ctx, arg.get3(), false);
185-
186-
distQryMgr.processQueryRequest(arg.get1(), cancelReq);
187-
188-
} else {
189-
qryMgr.removeQueryResult(arg.get1(), arg.get3());
190-
}
181+
GridCacheDistributedQueryManager distQryMgr = (GridCacheDistributedQueryManager) ctx.queries();
182+
distQryMgr.processQueryRequest(arg.get1(), cancelReq);
191183

192184
return null;
193185
}

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.concurrent.ConcurrentHashMap;
2828
import java.util.concurrent.ConcurrentMap;
2929
import org.apache.ignite.IgniteCheckedException;
30+
import org.apache.ignite.cache.query.QueryCancelledException;
3031
import org.apache.ignite.cluster.ClusterNode;
3132
import org.apache.ignite.events.DiscoveryEvent;
3233
import org.apache.ignite.events.Event;
@@ -231,7 +232,7 @@ protected void removeQueryFuture(long reqId) {
231232
GridCacheQueryResponse closedResponse = new GridCacheQueryResponse(
232233
cctx.cacheId(),
233234
req.id(),
234-
new NoSuchElementException("Iterator has been closed."),
235+
new QueryCancelledException("Iterator has been closed."),
235236
cctx.deploymentEnabled()
236237
);
237238

modules/indexing/src/test/java/org/apache/ignite/util/KillCommandsTests.java

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@
1717

1818
package org.apache.ignite.util;
1919

20-
import java.util.Collection;
21-
import java.util.Iterator;
22-
import java.util.List;
23-
import java.util.Map;
24-
import java.util.NoSuchElementException;
25-
import java.util.UUID;
20+
import java.util.*;
2621
import java.util.concurrent.ConcurrentMap;
2722
import java.util.concurrent.CountDownLatch;
2823
import java.util.concurrent.TimeUnit;
@@ -157,12 +152,6 @@ public static void checkScanQueryCancelBeforeFetching(
157152
// Cancel first query.
158153
qryCanceler.accept(qryInfo);
159154

160-
// Checking that second query works fine after canceling first.
161-
for (int i = 0; i < PAGE_SZ * PAGES_CNT - 1; i++)
162-
assertNotNull(iter2.next());
163-
164-
qry2.close();
165-
166155
// Fetch of the next page should throw the exception. New page is delivered in parallel to iterating.
167156
try {
168157
for (int i = 0; i < PAGE_SZ * PAGES_CNT - 1; i++)
@@ -180,7 +169,15 @@ public static void checkScanQueryCancelBeforeFetching(
180169
}
181170
}
182171

172+
// Checking that second query works fine after canceling first.
173+
for (int i = 0; i < PAGE_SZ * PAGES_CNT - 1; i++)
174+
assertNotNull(iter2.next());
175+
183176
checkScanQueryResources(cli, srvs, qryInfo.get3());
177+
178+
qry2.close();
179+
180+
checkRequestFutureMapEmpty(cli, srvs, qryInfo.get1());
184181
}
185182

186183
/**
@@ -259,6 +256,41 @@ private static void checkScanQueryResources(IgniteEx cli, List<IgniteEx> srvs, l
259256
}
260257
}
261258

259+
260+
/**
261+
* Checks that RequestFutureMap is empty on all nodes after query cancellation.
262+
*
263+
* @param cli Client node.
264+
* @param srvs Server nodes.
265+
* @param originNodeId Origin node ID.
266+
*/
267+
private static void checkRequestFutureMapEmpty(
268+
IgniteEx cli,
269+
List<IgniteEx> srvs,
270+
UUID originNodeId
271+
) {
272+
List<IgniteEx> allNodes = new ArrayList<>(srvs);
273+
allNodes.add(cli);
274+
275+
for (IgniteEx node : allNodes) {
276+
int cacheId = CU.cacheId(DEFAULT_CACHE_NAME);
277+
GridCacheContext<?, ?> ctx = node.context().cache().context().cacheContext(cacheId);
278+
279+
if (ctx == null) {
280+
continue;
281+
}
282+
283+
GridCacheQueryManager<?, ?> qryMgr = ctx.queries();
284+
285+
Map<UUID, GridCacheQueryManager.RequestFutureMap> qryIters = GridTestUtils.getFieldValue(qryMgr, "qryIters");
286+
GridCacheQueryManager.RequestFutureMap futMap = qryIters.get(originNodeId);
287+
288+
if (futMap != null) {
289+
assertTrue("RequestFutureMap not empty on node " + node.localNode().id() + ": size = " + futMap.size(), futMap.isEmpty());
290+
}
291+
}
292+
}
293+
262294
/**
263295
* Gets scan query info.
264296
*

0 commit comments

Comments
 (0)