Search in sources :

Example 6 with GridQueryNextPageResponse

use of org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryNextPageResponse in project ignite by apache.

the class GridReduceQueryExecutor method onNextPage.

/**
 * @param node Node.
 * @param msg Message.
 */
private void onNextPage(final ClusterNode node, GridQueryNextPageResponse msg) {
    final long qryReqId = msg.queryRequestId();
    final int qry = msg.query();
    final int seg = msg.segmentId();
    final ReduceQueryRun r = runs.get(qryReqId);
    if (// Already finished with error or canceled.
    r == null)
        return;
    final int pageSize = r.pageSize();
    GridMergeIndex idx = r.indexes().get(msg.query());
    GridResultPage page;
    try {
        page = new GridResultPage(ctx, node.id(), msg) {

            @Override
            public void fetchNextPage() {
                Object errState = r.state();
                if (errState != null) {
                    CacheException err0 = errState instanceof CacheException ? (CacheException) errState : null;
                    if (err0 != null && err0.getCause() instanceof IgniteClientDisconnectedException)
                        throw err0;
                    CacheException e = new CacheException("Failed to fetch data from node: " + node.id());
                    if (err0 != null)
                        e.addSuppressed(err0);
                    throw e;
                }
                try {
                    GridQueryNextPageRequest msg0 = new GridQueryNextPageRequest(qryReqId, qry, seg, pageSize);
                    if (node.isLocal())
                        h2.mapQueryExecutor().onMessage(ctx.localNodeId(), msg0);
                    else
                        ctx.io().sendToGridTopic(node, GridTopic.TOPIC_QUERY, msg0, GridIoPolicy.QUERY_POOL);
                } catch (IgniteCheckedException e) {
                    throw new CacheException("Failed to fetch data from node: " + node.id(), e);
                }
            }
        };
    } catch (Exception e) {
        U.error(log, "Error in message.", e);
        fail(r, node.id(), "Error in message.", GridQueryFailResponse.GENERAL_ERROR);
        return;
    }
    idx.addPage(page);
    if (msg.retry() != null)
        retry(r, msg.retry(), node.id());
    else if (// Do count down on each first page received.
    msg.page() == 0)
        r.latch().countDown();
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheException(javax.cache.CacheException) GridQueryNextPageRequest(org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryNextPageRequest) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) SQLException(java.sql.SQLException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) CacheException(javax.cache.CacheException) TransactionException(org.apache.ignite.transactions.TransactionException)

Aggregations

GridQueryNextPageResponse (org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryNextPageResponse)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgniteException (org.apache.ignite.IgniteException)4 Message (org.apache.ignite.plugin.extensions.communication.Message)3 ArrayList (java.util.ArrayList)2 CacheException (javax.cache.CacheException)2 QueryCancelledException (org.apache.ignite.cache.query.QueryCancelledException)2 SQLException (java.sql.SQLException)1 UUID (java.util.UUID)1 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)1 IgniteSystemProperties.getInteger (org.apache.ignite.IgniteSystemProperties.getInteger)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)1 GridH2RetryException (org.apache.ignite.internal.processors.query.h2.opt.GridH2RetryException)1 GridQueryFailResponse (org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryFailResponse)1 GridQueryNextPageRequest (org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryNextPageRequest)1 GridH2DmlResponse (org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2DmlResponse)1 TransactionException (org.apache.ignite.transactions.TransactionException)1