use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class KillQueryTest method testCancelQueryIfPartitionsCantBeReservedOnMapNodes.
/**
* Check if query hangs (due to reducer spins retrying to reserve partitions but they can't be reserved), we still
* able to cancel it. Used mocked indexing simulates 100% unability.
*/
@Test
public void testCancelQueryIfPartitionsCantBeReservedOnMapNodes() throws Exception {
// Releases thread that kills query when map nodes receive query request. At least one map node received is ok.
GridMessageListener qryStarted = (node, msg, plc) -> {
if (msg instanceof GridH2QueryRequest)
TestSQLFunctions.cancelLatch.countDown();
};
for (int i = 0; i < NODES_COUNT; i++) grid(i).context().io().addMessageListener(GridTopic.TOPIC_QUERY, qryStarted);
// Suspends distributed queries on the map nodes.
MockedIndexing.failReservations = true;
try {
IgniteInternalFuture cancelFut = cancel(1, asyncCancel);
GridTestUtils.assertThrows(log, () -> {
ignite.cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery("select * from Integer where _val <> 42")).getAll();
return null;
}, CacheException.class, "The query was cancelled while executing.");
cancelFut.get(CHECK_RESULT_TIMEOUT);
} finally {
for (int i = 0; i < NODES_COUNT; i++) grid(i).context().io().removeMessageListener(GridTopic.TOPIC_QUERY, qryStarted);
}
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class KillQueryTest method checkPartitions.
/**
* Test if user specified partitions for query explicitly, such query is cancealble.
*
* @param partitions user specified partitions, could contain partitions that are mapped on one or both nodes.
*/
public void checkPartitions(int[] partitions) throws Exception {
TestSQLFunctions.reset();
IgniteInternalFuture cancelRes = cancel(1, asyncCancel);
GridTestUtils.assertThrows(log, () -> {
ignite.cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery("select * from Integer where _key in " + "(select abs(_key) from Integer where awaitLatchCancelled() = 0) and shouldNotBeCalledInCaseOfCancellation()").setPartitions(partitions)).getAll();
return null;
}, CacheException.class, "The query was cancelled while executing.");
// Ensures that there were no exceptions within async cancellation process.
cancelRes.get(CHECK_RESULT_TIMEOUT);
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class KillQueryTest method testCancelLocalLazyQueryNative.
/**
* Check that local query can be canceled either using async or non-async method. Local query is performed using
* cache.query() API with "local" property "true".
*/
@Test
public void testCancelLocalLazyQueryNative() throws Exception {
IgniteInternalFuture cancelRes = cancel(1, asyncCancel);
GridTestUtils.assertThrowsAnyCause(log, () -> {
ignite.cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery("select * from Integer where _key in " + "(select _key from Integer where awaitLatchCancelled() = 0) and shouldNotBeCalledMoreThan(128)").setLocal(true).setLazy(true)).getAll();
return null;
}, QueryCancelledException.class, "The query was cancelled while executing.");
// Ensures that there were no exceptions within async cancellation process.
cancelRes.get(CHECK_RESULT_TIMEOUT);
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class KillQueryTest method testKillAlreadyKilledQuery.
/**
* Trying to kill already killed query. No exceptions expected.
*/
@Test
public void testKillAlreadyKilledQuery() throws Exception {
IgniteCache<Object, Object> cache = ignite.cache(DEFAULT_CACHE_NAME);
FieldsQueryCursor<List<?>> cur = cache.query(new SqlFieldsQuery("select * from Integer where awaitLatchCancelled() = 0"));
List<GridRunningQueryInfo> runningQueries = (List<GridRunningQueryInfo>) ignite.context().query().runningQueries(-1);
GridRunningQueryInfo runQryInfo = runningQueries.get(0);
SqlFieldsQuery killQry = createKillQuery(runQryInfo.globalQueryId(), asyncCancel);
IgniteCache<Object, Object> reqCache = igniteForKillRequest.cache(DEFAULT_CACHE_NAME);
IgniteInternalFuture killFut = cancel(1, asyncCancel);
GridTestUtils.assertThrows(log, () -> cur.iterator().next(), QueryCancelledException.class, "The query was cancelled while executing");
killFut.get(CHECK_RESULT_TIMEOUT);
GridTestUtils.assertThrows(log, () -> reqCache.query(killQry), CacheException.class, "Query with provided ID doesn't exist");
cur.close();
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class KillQueryOnClientDisconnectTest method cancelAndCheckClientDisconnect.
/**
* Cancels current query, actual cancel will wait <code>cancelLatch</code> to be releaseds.
* Checked that Cancellation wasn't complete due to clint was disconnected.
*
* @return <code>IgniteInternalFuture</code> to check whether exception was thrown.
*/
protected IgniteInternalFuture cancelAndCheckClientDisconnect() {
return GridTestUtils.runAsync(() -> {
try {
TestSQLFunctions.cancelLatch.await();
List<GridRunningQueryInfo> runningQueries = (List<GridRunningQueryInfo>) serverNode().context().query().runningQueries(-1);
assertEquals(1, runningQueries.size());
IgniteInternalFuture fut = GridTestUtils.runAsync(() -> {
clientNode().cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery("KILL QUERY '" + runningQueries.get(0).globalQueryId() + "'"));
});
doSleep(500);
TestSQLFunctions.reqLatch.countDown();
GridTestUtils.assertThrows(log, () -> fut.get(TIMEOUT), IgniteCheckedException.class, "Failed to cancel query because local client node has been disconnected from the cluster");
} catch (Exception e) {
log.error("Unexpected exception.", e);
Assert.fail("Unexpected exception");
}
});
}
Aggregations