Search in sources :

Example 6 with QueryRetryException

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;
    }
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery) BinaryObject(org.apache.ignite.binary.BinaryObject) QueryRetryException(org.apache.ignite.cache.query.QueryRetryException) HashSet(java.util.HashSet) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Example 7 with QueryRetryException

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) QueryRetryException(org.apache.ignite.cache.query.QueryRetryException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) CacheException(javax.cache.CacheException)

Example 8 with QueryRetryException

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);
    }
}
Also used : QueryRetryException(org.apache.ignite.cache.query.QueryRetryException) CacheException(javax.cache.CacheException) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException)

Example 9 with QueryRetryException

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();
            }
        }
    }
}
Also used : QueryRetryException(org.apache.ignite.cache.query.QueryRetryException) CacheException(javax.cache.CacheException) SQLException(java.sql.SQLException) GridQueryNextPageResponse(org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryNextPageResponse) TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) QueryRetryException(org.apache.ignite.cache.query.QueryRetryException) GridH2RetryException(org.apache.ignite.internal.processors.query.h2.opt.GridH2RetryException) SQLException(java.sql.SQLException) CacheException(javax.cache.CacheException)

Aggregations

QueryRetryException (org.apache.ignite.cache.query.QueryRetryException)9 CacheException (javax.cache.CacheException)6 FieldsQueryCursor (org.apache.ignite.cache.query.FieldsQueryCursor)4 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)4 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 QueryCancelledException (org.apache.ignite.cache.query.QueryCancelledException)3 SQLException (java.sql.SQLException)2 GridH2RetryException (org.apache.ignite.internal.processors.query.h2.opt.GridH2RetryException)2 GridQueryNextPageResponse (org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryNextPageResponse)2 TraceSurroundings (org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Cache (javax.cache.Cache)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1