use of org.apache.ignite.internal.processors.query.h2.opt.join.SegmentKey in project ignite by apache.
the class DistributedLookupBatch method addSearchRows.
/**
* {@inheritDoc}
*/
@SuppressWarnings({ "ForLoopReplaceableByForEach", "IfMayBeConditional" })
@Override
public boolean addSearchRows(SearchRow firstRow, SearchRow lastRow) {
if (joinCtx == null || findCalled) {
if (joinCtx == null) {
// It is the first call after query begin (may be after reuse),
// reinitialize query context and result.
QueryContext qctx = QueryContext.threadLocal();
res = new ArrayList<>();
assert qctx != null;
assert !findCalled;
joinCtx = qctx.distributedJoinContext();
} else {
// Cleanup after the previous lookup phase.
assert batchLookupId != 0;
findCalled = false;
joinCtx.putStreams(batchLookupId, null);
res.clear();
}
// Reinitialize for the next lookup phase.
batchLookupId = joinCtx.nextBatchLookupId();
rangeStreams = new HashMap<>();
}
Object affKey = getAffinityKey(firstRow, lastRow);
List<SegmentKey> segmentKeys;
if (affKey != null) {
// Affinity key is provided.
if (// Affinity key is explicit null, we will not find anything.
affKey == EXPLICIT_NULL)
return false;
segmentKeys = F.asList(rangeSegment(affKey));
} else {
// Affinity key is not provided or is not the same in upper and lower bounds, we have to broadcast.
if (broadcastSegments == null)
broadcastSegments = broadcastSegments();
segmentKeys = broadcastSegments;
}
assert !F.isEmpty(segmentKeys) : segmentKeys;
final int rangeId = res.size();
// Create messages.
GridH2RowMessage first = idx.toSearchRowMessage(firstRow);
GridH2RowMessage last = idx.toSearchRowMessage(lastRow);
// Range containing upper and lower bounds.
GridH2RowRangeBounds rangeBounds = rangeBounds(rangeId, first, last);
// Add range to every message of every participating node.
for (int i = 0; i < segmentKeys.size(); i++) {
SegmentKey segmentKey = segmentKeys.get(i);
assert segmentKey != null;
RangeStream stream = rangeStreams.get(segmentKey);
List<GridH2RowRangeBounds> bounds;
if (stream == null) {
stream = new RangeStream(cctx.kernalContext(), idx, joinCtx, segmentKey.node());
stream.request(createRequest(joinCtx, batchLookupId, segmentKey.segmentId()));
stream.request().bounds(bounds = new ArrayList<>());
rangeStreams.put(segmentKey, stream);
} else
bounds = stream.request().bounds();
bounds.add(rangeBounds);
// If at least one node will have a full batch then we are ok.
if (bounds.size() >= joinCtx.pageSize())
batchFull = true;
}
Cursor cur;
if (segmentKeys.size() == 1)
cur = new UnicastCursor(rangeId, rangeStreams.get(F.first(segmentKeys)));
else
cur = new BroadcastCursor(idx, rangeId, segmentKeys, rangeStreams);
res.add(new DoneFuture<>(cur));
return true;
}
use of org.apache.ignite.internal.processors.query.h2.opt.join.SegmentKey in project ignite by apache.
the class H2TreeIndex method onIndexRangeResponse.
/**
* @param node Responded node.
* @param msg Response message.
*/
private void onIndexRangeResponse(ClusterNode node, GridH2IndexRangeResponse msg) {
try (TraceSurroundings ignored = MTC.support(ctx.tracing().create(SQL_IDX_RANGE_RESP, MTC.span()))) {
QueryContext qctx = qryCtxRegistry.getShared(msg.originNodeId(), msg.queryId(), msg.originSegmentId());
if (qctx == null)
return;
DistributedJoinContext joinCtx = qctx.distributedJoinContext();
assert joinCtx != null;
Map<SegmentKey, RangeStream> streams = joinCtx.getStreams(msg.batchLookupId());
if (streams == null)
return;
RangeStream stream = streams.get(new SegmentKey(node, msg.segment()));
assert stream != null;
stream.onResponse(msg);
}
}
Aggregations