Search in sources :

Example 1 with GridQueryNextPageResponse

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

the class GridMapQueryExecutor method sendNextPage.

/**
     * @param nodeRess Results.
     * @param node Node.
     * @param qr Query results.
     * @param qry Query.
     * @param segmentId Index segment ID.
     * @param pageSize Page size.
     */
private void sendNextPage(NodeResults nodeRess, ClusterNode node, QueryResults qr, int qry, int segmentId, int pageSize) {
    QueryResult res = qr.result(qry);
    assert res != null;
    if (res.closed)
        return;
    int page = res.page;
    List<Value[]> rows = new ArrayList<>(Math.min(64, pageSize));
    boolean last = res.fetchNextPage(rows, pageSize);
    if (last) {
        res.close();
        if (qr.isAllClosed())
            nodeRess.remove(qr.qryReqId, segmentId, qr);
    }
    try {
        boolean loc = node.isLocal();
        GridQueryNextPageResponse msg = new GridQueryNextPageResponse(qr.qryReqId, segmentId, qry, page, page == 0 ? res.rowCnt : -1, res.cols, loc ? null : toMessages(rows, new ArrayList<Message>(res.cols)), loc ? rows : null);
        if (loc)
            h2.reduceQueryExecutor().onMessage(ctx.localNodeId(), msg);
        else
            ctx.io().sendToGridTopic(node, GridTopic.TOPIC_QUERY, msg, QUERY_POOL);
    } catch (IgniteCheckedException e) {
        log.error("Failed to send message.", e);
        throw new IgniteException(e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Message(org.apache.ignite.plugin.extensions.communication.Message) IgniteException(org.apache.ignite.IgniteException) GridQueryNextPageResponse(org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryNextPageResponse) ArrayList(java.util.ArrayList)

Example 2 with GridQueryNextPageResponse

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

the class GridMapQueryExecutor method sendNextPage.

/**
 * @param nodeRess Results.
 * @param node Node.
 * @param qr Query results.
 * @param qry Query.
 * @param segmentId Index segment ID.
 * @param pageSize Page size.
 */
private void sendNextPage(MapNodeResults nodeRess, ClusterNode node, MapQueryResults qr, int qry, int segmentId, int pageSize) {
    MapQueryResult res = qr.result(qry);
    assert res != null;
    if (res.closed())
        return;
    int page = res.page();
    List<Value[]> rows = new ArrayList<>(Math.min(64, pageSize));
    boolean last = res.fetchNextPage(rows, pageSize);
    if (last) {
        res.close();
        if (qr.isAllClosed()) {
            nodeRess.remove(qr.queryRequestId(), segmentId, qr);
            // Release reservations if the last page fetched, all requests are closed and this is a lazy worker.
            if (MapQueryLazyWorker.currentWorker() != null)
                releaseReservations();
        }
    }
    try {
        boolean loc = node.isLocal();
        GridQueryNextPageResponse msg = new GridQueryNextPageResponse(qr.queryRequestId(), segmentId, qry, page, page == 0 ? res.rowCount() : -1, res.columnCount(), loc ? null : toMessages(rows, new ArrayList<Message>(res.columnCount())), loc ? rows : null, last);
        if (loc)
            h2.reduceQueryExecutor().onMessage(ctx.localNodeId(), msg);
        else
            ctx.io().sendToGridTopic(node, GridTopic.TOPIC_QUERY, msg, QUERY_POOL);
    } catch (IgniteCheckedException e) {
        U.error(log, "Failed to send message.", e);
        throw new IgniteException(e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Message(org.apache.ignite.plugin.extensions.communication.Message) IgniteException(org.apache.ignite.IgniteException) GridQueryNextPageResponse(org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryNextPageResponse) ArrayList(java.util.ArrayList)

Example 3 with GridQueryNextPageResponse

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

the class GridMapQueryExecutor method sendRetry.

/**
 * @param node Node.
 * @param reqId Request ID.
 * @param segmentId Index segment ID.
 */
private void sendRetry(ClusterNode node, long reqId, int segmentId) {
    try {
        boolean loc = node.isLocal();
        GridQueryNextPageResponse msg = new GridQueryNextPageResponse(reqId, segmentId, /*qry*/
        0, /*page*/
        0, /*allRows*/
        0, /*cols*/
        1, loc ? null : Collections.<Message>emptyList(), loc ? Collections.<Value[]>emptyList() : null, false);
        msg.retry(h2.readyTopologyVersion());
        if (loc)
            h2.reduceQueryExecutor().onMessage(ctx.localNodeId(), msg);
        else
            ctx.io().sendToGridTopic(node, GridTopic.TOPIC_QUERY, msg, QUERY_POOL);
    } catch (Exception e) {
        U.warn(log, "Failed to send retry message: " + e.getMessage());
    }
}
Also used : Message(org.apache.ignite.plugin.extensions.communication.Message) GridQueryNextPageResponse(org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryNextPageResponse) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) GridH2RetryException(org.apache.ignite.internal.processors.query.h2.opt.GridH2RetryException) CacheException(javax.cache.CacheException)

Example 4 with GridQueryNextPageResponse

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

the class GridMergeIndex method markLastPage.

/**
 * @param page Page.
 */
private void markLastPage(GridResultPage page) {
    GridQueryNextPageResponse res = page.response();
    if (!res.last()) {
        UUID nodeId = page.source();
        initLastPages(nodeId, res);
        ConcurrentMap<SourceKey, Integer> lp = lastPages;
        if (lp == null)
            // It was not initialized --> wait for last page flag.
            return;
        Integer lastPage = lp.get(new SourceKey(nodeId, res.segmentId()));
        if (lastPage == null)
            // This node may use the new protocol --> wait for last page flag.
            return;
        if (lastPage != res.page()) {
            assert lastPage > res.page();
            // This is not the last page.
            return;
        }
    }
    page.setLast(true);
}
Also used : IgniteSystemProperties.getInteger(org.apache.ignite.IgniteSystemProperties.getInteger) GridQueryNextPageResponse(org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryNextPageResponse) UUID(java.util.UUID)

Example 5 with GridQueryNextPageResponse

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

the class GridReduceQueryExecutor method onMessage.

/**
 * @param nodeId Node ID.
 * @param msg Message.
 */
public void onMessage(UUID nodeId, Object msg) {
    try {
        assert msg != null;
        ClusterNode node = ctx.discovery().node(nodeId);
        if (node == null)
            // Node left, ignore.
            return;
        boolean processed = true;
        if (msg instanceof GridQueryNextPageResponse)
            onNextPage(node, (GridQueryNextPageResponse) msg);
        else if (msg instanceof GridQueryFailResponse)
            onFail(node, (GridQueryFailResponse) msg);
        else if (msg instanceof GridH2DmlResponse)
            onDmlResponse(node, (GridH2DmlResponse) msg);
        else
            processed = false;
        if (processed && log.isDebugEnabled())
            log.debug("Processed response: " + nodeId + "->" + ctx.localNodeId() + " " + msg);
    } catch (Throwable th) {
        U.error(log, "Failed to process message: " + msg, th);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridQueryFailResponse(org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryFailResponse) GridQueryNextPageResponse(org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryNextPageResponse) GridH2DmlResponse(org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2DmlResponse)

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