use of org.apache.ignite.internal.table.distributed.command.response.MultiRowsResponse in project ignite-3 by apache.
the class PartitionListener method handleScanRetrieveBatchCommand.
/**
* Handler for the {@link ScanRetrieveBatchCommand}.
*
* @param clo Command closure.
* @param cmd Command.
*/
private void handleScanRetrieveBatchCommand(CommandClosure<ScanRetrieveBatchCommand> clo, ScanRetrieveBatchCommand cmd) {
CursorMeta cursorDesc = cursors.get(cmd.scanId());
if (cursorDesc == null) {
clo.result(new NoSuchElementException(format("Cursor with id={} is not found on server side.", cmd.scanId())));
return;
}
AtomicInteger internalBatchCounter = cursorDesc.batchCounter();
if (internalBatchCounter.getAndSet(clo.command().batchCounter()) != clo.command().batchCounter() - 1) {
throw new IllegalStateException("Counters from received scan command and handled scan command in partition listener are inconsistent");
}
List<BinaryRow> res = new ArrayList<>();
try {
for (int i = 0; i < cmd.itemsToRetrieveCount() && cursorDesc.cursor().hasNext(); i++) {
res.add(cursorDesc.cursor().next());
}
} catch (NoSuchElementException e) {
clo.result(e);
}
clo.result(new MultiRowsResponse(res));
}
use of org.apache.ignite.internal.table.distributed.command.response.MultiRowsResponse in project ignite-3 by apache.
the class InternalTableImpl method collectMultiRowsResponses.
/**
* TODO asch keep the same order as for keys Collects multirow responses from multiple futures into a single collection IGNITE-16004.
*
* @param futs Futures.
* @return Row collection.
*/
private CompletableFuture<Collection<BinaryRow>> collectMultiRowsResponses(CompletableFuture<?>[] futs) {
return CompletableFuture.allOf(futs).thenApply(response -> {
List<BinaryRow> list = new ArrayList<>(futs.length);
for (CompletableFuture<?> future : futs) {
MultiRowsResponse ret = (MultiRowsResponse) future.join();
List<BinaryRow> values = ret.getValues();
if (values != null) {
list.addAll(values);
}
}
return list;
});
}
Aggregations