Search in sources :

Example 1 with MultiRowsResponse

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));
}
Also used : MultiRowsResponse(org.apache.ignite.internal.table.distributed.command.response.MultiRowsResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) NoSuchElementException(java.util.NoSuchElementException)

Example 2 with MultiRowsResponse

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;
    });
}
Also used : MultiRowsResponse(org.apache.ignite.internal.table.distributed.command.response.MultiRowsResponse) ArrayList(java.util.ArrayList) BinaryRow(org.apache.ignite.internal.schema.BinaryRow)

Aggregations

ArrayList (java.util.ArrayList)2 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)2 MultiRowsResponse (org.apache.ignite.internal.table.distributed.command.response.MultiRowsResponse)2 NoSuchElementException (java.util.NoSuchElementException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1