Search in sources :

Example 1 with GridH2IndexRangeResponse

use of org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2IndexRangeResponse in project ignite by apache.

the class GridH2IndexBase method onIndexRangeRequest.

/**
     * @param node Requesting node.
     * @param msg Request message.
     */
private void onIndexRangeRequest(final ClusterNode node, final GridH2IndexRangeRequest msg) {
    GridH2IndexRangeResponse res = new GridH2IndexRangeResponse();
    res.originNodeId(msg.originNodeId());
    res.queryId(msg.queryId());
    res.originSegmentId(msg.originSegmentId());
    res.segment(msg.segment());
    res.batchLookupId(msg.batchLookupId());
    GridH2QueryContext qctx = GridH2QueryContext.get(kernalContext().localNodeId(), msg.originNodeId(), msg.queryId(), msg.originSegmentId(), MAP);
    if (qctx == null)
        res.status(STATUS_NOT_FOUND);
    else {
        try {
            RangeSource src;
            if (msg.bounds() != null) {
                // This is the first request containing all the search rows.
                IgniteTree snapshotTree = qctx.getSnapshot(idxId);
                assert !msg.bounds().isEmpty() : "empty bounds";
                src = new RangeSource(msg.bounds(), msg.segment(), snapshotTree, qctx.filter());
            } else {
                // This is request to fetch next portion of data.
                src = qctx.getSource(node.id(), msg.segment(), msg.batchLookupId());
                assert src != null;
            }
            List<GridH2RowRange> ranges = new ArrayList<>();
            int maxRows = qctx.pageSize();
            assert maxRows > 0 : maxRows;
            while (maxRows > 0) {
                GridH2RowRange range = src.next(maxRows);
                if (range == null)
                    break;
                ranges.add(range);
                if (range.rows() != null)
                    maxRows -= range.rows().size();
            }
            assert !ranges.isEmpty();
            if (src.hasMoreRows()) {
                // Save source for future fetches.
                if (msg.bounds() != null)
                    qctx.putSource(node.id(), msg.segment(), msg.batchLookupId(), src);
            } else if (msg.bounds() == null) {
                // Drop saved source.
                qctx.putSource(node.id(), msg.segment(), msg.batchLookupId(), null);
            }
            res.ranges(ranges);
            res.status(STATUS_OK);
        } catch (Throwable th) {
            U.error(log, "Failed to process request: " + msg, th);
            res.error(th.getClass() + ": " + th.getMessage());
            res.status(STATUS_ERROR);
        }
    }
    send(singletonList(node), res);
}
Also used : GridH2IndexRangeResponse(org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2IndexRangeResponse) GridH2RowRange(org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2RowRange)

Aggregations

GridH2IndexRangeResponse (org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2IndexRangeResponse)1 GridH2RowRange (org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2RowRange)1