use of org.apache.ignite.cache.query.QueryRetryException in project ignite by apache.
the class DynamicIndexAbstractSelfTest method assertSqlSimpleData.
/**
* Assert SQL simple data state.
*
* @param node Node.
* @param sql SQL query.
* @param expSize Expected size.
*/
protected static void assertSqlSimpleData(Ignite node, String sql, int expSize) {
try {
SqlQuery qry = new SqlQuery(typeName(ValueClass.class), sql).setArgs(SQL_ARG_1);
List<Cache.Entry<BinaryObject, BinaryObject>> res = node.cache(CACHE_NAME).withKeepBinary().query(qry).getAll();
Set<Long> ids = new HashSet<>();
for (Cache.Entry<BinaryObject, BinaryObject> entry : res) {
long id = entry.getKey().field(FIELD_KEY);
long field1 = entry.getValue().field(FIELD_NAME_1_ESCAPED);
long field2 = entry.getValue().field(FIELD_NAME_2_ESCAPED);
assertTrue(field1 >= SQL_ARG_1);
assertEquals(id, field1);
assertEquals(id, field2);
assertTrue(ids.add(id));
}
assertEquals("Size mismatch [node=" + node.name() + ", exp=" + expSize + ", actual=" + res.size() + ", ids=" + ids + ']', expSize, res.size());
} catch (Exception e) {
// Swallow QueryRetryException.
if (X.cause(e, QueryRetryException.class) == null)
throw e;
}
}
use of org.apache.ignite.cache.query.QueryRetryException in project ignite by apache.
the class AbstractQueryTableLockAndConnectionPoolSelfTest method checkTablesLockQueryAndDropColumnMultithreaded.
/**
* @param node Ignite node to execute query.
* @throws Exception If failed.
*/
private void checkTablesLockQueryAndDropColumnMultithreaded(final Ignite node) throws Exception {
final AtomicBoolean end = new AtomicBoolean(false);
final int qryThreads = 10;
// Do many concurrent queries.
IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new Runnable() {
@Override
public void run() {
while (!end.get()) {
try {
FieldsQueryCursor<List<?>> cursor = execute(node, new SqlFieldsQuery("SELECT pers.id, pers.name FROM \"pers\".PERSON").setLazy(lazy()).setPageSize(PAGE_SIZE_SMALL));
cursor.getAll();
} catch (Exception e) {
if (e.getMessage().contains("Failed to parse query. Column \"PERS.ID\" not found")) {
// Swallow exception when column is dropped.
} else if (X.cause(e, QueryRetryException.class) == null) {
log.error("Unexpected exception", e);
fail("Unexpected exception. " + e);
} else if (!lazy()) {
log.error("Unexpected exception", e);
fail("Unexpected QueryRetryException.");
}
}
}
}
}, qryThreads, "usr-qry");
long tEnd = U.currentTimeMillis() + TEST_DUR;
while (U.currentTimeMillis() < tEnd) {
execute(node, new SqlFieldsQuery("ALTER TABLE \"pers\".Person DROP COLUMN name")).getAll();
execute(node, new SqlFieldsQuery("ALTER TABLE \"pers\".Person ADD COLUMN name varchar")).getAll();
}
// Test is OK in case DDL operations is passed on hi load queries pressure.
end.set(true);
fut.get();
checkConnectionLeaks(Ignition.allGrids().size());
}
use of org.apache.ignite.cache.query.QueryRetryException in project ignite by apache.
the class GridReduceQueryExecutor method fail.
/**
* @param r Query run.
* @param nodeId Failed node ID.
* @param msg Error message.
*/
private void fail(ReduceQueryRun r, UUID nodeId, String msg, byte failCode) {
if (r != null) {
CacheException e;
String mapperFailedMsg = "Failed to execute map query on remote node [nodeId=" + nodeId + ", errMsg=" + msg + ']';
if (failCode == GridQueryFailResponse.CANCELLED_BY_ORIGINATOR)
e = new CacheException(mapperFailedMsg, new QueryCancelledException());
else if (failCode == GridQueryFailResponse.RETRY_QUERY)
e = new CacheException(mapperFailedMsg, new QueryRetryException(msg));
else
e = new CacheException(mapperFailedMsg);
r.setStateOnException(nodeId, e);
}
}
use of org.apache.ignite.cache.query.QueryRetryException in project ignite by apache.
the class GridMapQueryExecutor method onNextPageRequest.
/**
* @param node Node.
* @param req Request.
*/
public void onNextPageRequest(final ClusterNode node, final GridQueryNextPageRequest req) {
try (TraceSurroundings ignored = MTC.support(ctx.tracing().create(SQL_NEXT_PAGE_REQ, MTC.span()))) {
long reqId = req.queryRequestId();
final MapNodeResults nodeRess = qryRess.get(node.id());
if (nodeRess == null) {
sendError(node, reqId, new CacheException("No node result found for request: " + req));
return;
} else if (nodeRess.cancelled(reqId)) {
sendQueryCancel(node, reqId);
return;
}
final MapQueryResults qryResults = nodeRess.get(reqId, req.segmentId());
if (qryResults == null)
sendError(node, reqId, new CacheException("No query result found for request: " + req));
else if (qryResults.cancelled())
sendQueryCancel(node, reqId);
else {
try {
MapQueryResult res = qryResults.result(req.query());
assert res != null;
try {
// Session isn't set for lazy=false queries.
// Also session == null when result already closed.
res.lock();
res.lockTables();
res.checkTablesVersions();
Boolean dataPageScanEnabled = isDataPageScanEnabled(req.getFlags());
GridQueryNextPageResponse msg = prepareNextPage(nodeRess, node, qryResults, req.query(), req.segmentId(), req.pageSize(), dataPageScanEnabled);
if (msg != null)
sendNextPage(node, msg);
} finally {
try {
res.unlockTables();
} finally {
res.unlock();
}
}
} catch (Exception e) {
QueryRetryException retryEx = X.cause(e, QueryRetryException.class);
if (retryEx != null)
sendError(node, reqId, retryEx);
else {
SQLException sqlEx = X.cause(e, SQLException.class);
if (sqlEx != null && sqlEx.getErrorCode() == ErrorCode.STATEMENT_WAS_CANCELED)
sendQueryCancel(node, reqId);
else
sendError(node, reqId, e);
}
qryResults.cancel();
}
}
}
}
Aggregations