Search in sources :

Example 31 with BatchIterator

use of io.crate.data.BatchIterator in project crate by crate.

the class NodeStatsIteratorTest method testNoRequestIfNotRequired.

@Test
public void testNoRequestIfNotRequired() throws InterruptedException, ExecutionException, TimeoutException {
    List<Symbol> toCollect = new ArrayList<>();
    toCollect.add(idRef);
    when(collectPhase.toCollect()).thenReturn(toCollect);
    BatchIterator iterator = NodeStatsIterator.newInstance(transportNodeStatsAction, collectPhase, nodes, new InputFactory(getFunctions()));
    iterator.loadNextBatch();
    // Because only id and name are selected, transportNodesStatsAction should be never used
    verifyNoMoreInteractions(transportNodeStatsAction);
}
Also used : InputFactory(io.crate.operation.InputFactory) Symbol(io.crate.analyze.symbol.Symbol) BatchIterator(io.crate.data.BatchIterator) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 32 with BatchIterator

use of io.crate.data.BatchIterator in project crate by crate.

the class NodeStatsIteratorTest method testRequestsIfRequired.

@Test
public void testRequestsIfRequired() throws InterruptedException, ExecutionException, TimeoutException {
    List<Symbol> toCollect = new ArrayList<>();
    toCollect.add(idRef);
    toCollect.add(hostnameRef);
    when(collectPhase.toCollect()).thenReturn(toCollect);
    BatchIterator iterator = NodeStatsIterator.newInstance(transportNodeStatsAction, collectPhase, nodes, new InputFactory(getFunctions()));
    iterator.loadNextBatch();
    // Hostnames needs to be collected so requests need to be performed
    verify(transportNodeStatsAction).execute(eq("nodeOne"), any(NodeStatsRequest.class), any(ActionListener.class), eq(TimeValue.timeValueMillis(3000L)));
    verify(transportNodeStatsAction).execute(eq("nodeTwo"), any(NodeStatsRequest.class), any(ActionListener.class), eq(TimeValue.timeValueMillis(3000L)));
    verifyNoMoreInteractions(transportNodeStatsAction);
}
Also used : InputFactory(io.crate.operation.InputFactory) ActionListener(org.elasticsearch.action.ActionListener) NodeStatsRequest(io.crate.executor.transport.NodeStatsRequest) Symbol(io.crate.analyze.symbol.Symbol) BatchIterator(io.crate.data.BatchIterator) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 33 with BatchIterator

use of io.crate.data.BatchIterator in project crate by crate.

the class ShardingUpsertExecutor method apply.

@Override
public CompletableFuture<? extends Iterable<Row>> apply(BatchIterator<Row> batchIterator) {
    final ConcurrencyLimit nodeLimit = nodeLimits.get(localNode);
    long startTime = nodeLimit.startSample();
    var isUsedBytesOverThreshold = new IsUsedBytesOverThreshold(queryCircuitBreaker, nodeLimit);
    var reqBatchIterator = BatchIterators.partition(batchIterator, bulkSize, () -> new ShardedRequests<>(requestFactory, ramAccounting), grouper, bulkShardCreationLimiter.or(isUsedBytesOverThreshold));
    // If IO is involved the source iterator should pause when the target node reaches a concurrent job counter limit.
    // Without IO, we assume that the source iterates over in-memory structures which should be processed as
    // fast as possible to free resources.
    Predicate<ShardedRequests<ShardUpsertRequest, ShardUpsertRequest.Item>> shouldPause = this::shouldPauseOnPartitionCreation;
    if (batchIterator.hasLazyResultSet()) {
        shouldPause = shouldPause.or(this::shouldPauseOnTargetNodeJobsCounter).or(isUsedBytesOverThreshold);
    }
    BatchIteratorBackpressureExecutor<ShardedRequests<ShardUpsertRequest, ShardUpsertRequest.Item>, UpsertResults> executor = new BatchIteratorBackpressureExecutor<>(jobId, scheduler, this.executor, reqBatchIterator, this::execute, resultCollector.combiner(), resultCollector.supplier().get(), shouldPause, earlyTerminationCondition, earlyTerminationExceptionGenerator, this::getMaxLastRttInMs);
    return executor.consumeIteratorAndExecute().thenApply(upsertResults -> resultCollector.finisher().apply(upsertResults)).whenComplete((res, err) -> {
        nodeLimit.onSample(startTime, err != null);
    });
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ByteSizeUnit(org.elasticsearch.common.unit.ByteSizeUnit) Item(io.crate.execution.dml.upsert.ShardUpsertRequest.Item) ClusterService(org.elasticsearch.cluster.service.ClusterService) CollectExpression(io.crate.execution.engine.collect.CollectExpression) CompletableFuture(java.util.concurrent.CompletableFuture) BatchIterator(io.crate.data.BatchIterator) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) NodeLimits(io.crate.execution.jobs.NodeLimits) BackoffPolicy(org.elasticsearch.action.bulk.BackoffPolicy) TransportCreatePartitionsAction(org.elasticsearch.action.admin.indices.create.TransportCreatePartitionsAction) RetryListener(io.crate.execution.support.RetryListener) BlockBasedRamAccounting(io.crate.breaker.BlockBasedRamAccounting) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) TypeGuessEstimateRowSize(io.crate.breaker.TypeGuessEstimateRowSize) ConcurrencyLimit(io.crate.concurrent.limits.ConcurrencyLimit) BulkRequestExecutor(org.elasticsearch.action.bulk.BulkRequestExecutor) ToLongFunction(java.util.function.ToLongFunction) Nullable(javax.annotation.Nullable) FutureActionListener(io.crate.action.FutureActionListener) Iterator(java.util.Iterator) Setting(org.elasticsearch.common.settings.Setting) Executor(java.util.concurrent.Executor) Predicate(java.util.function.Predicate) UUID(java.util.UUID) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) RamAccounting(io.crate.breaker.RamAccounting) TimeUnit(java.util.concurrent.TimeUnit) ShardResponse(io.crate.execution.dml.ShardResponse) ShardUpsertRequest(io.crate.execution.dml.upsert.ShardUpsertRequest) List(java.util.List) Logger(org.apache.logging.log4j.Logger) BatchIterators(io.crate.data.BatchIterators) Row(io.crate.data.Row) TimeValue(io.crate.common.unit.TimeValue) RowShardResolver(io.crate.execution.engine.collect.RowShardResolver) LogManager(org.apache.logging.log4j.LogManager) CreatePartitionsRequest(org.elasticsearch.action.admin.indices.create.CreatePartitionsRequest) ActionListener(org.elasticsearch.action.ActionListener) ConcurrencyLimit(io.crate.concurrent.limits.ConcurrencyLimit) ShardUpsertRequest(io.crate.execution.dml.upsert.ShardUpsertRequest)

Example 34 with BatchIterator

use of io.crate.data.BatchIterator in project crate by crate.

the class NodeStatsTest method testRequestsIfRequired.

@Test
public void testRequestsIfRequired() throws Exception {
    List<Symbol> toCollect = new ArrayList<>();
    toCollect.add(idRef);
    toCollect.add(hostnameRef);
    when(collectPhase.toCollect()).thenReturn(toCollect);
    BatchIterator iterator = NodeStats.newInstance(transportNodeStatsAction, collectPhase, nodes, txnCtx, new InputFactory(nodeCtx));
    iterator.loadNextBatch();
    // Hostnames needs to be collected so requests need to be performed
    verify(transportNodeStatsAction).execute(eq("nodeOne"), any(NodeStatsRequest.class), any(ActionListener.class), eq(TimeValue.timeValueMillis(3000L)));
    verify(transportNodeStatsAction).execute(eq("nodeTwo"), any(NodeStatsRequest.class), any(ActionListener.class), eq(TimeValue.timeValueMillis(3000L)));
    verifyNoMoreInteractions(transportNodeStatsAction);
}
Also used : InputFactory(io.crate.expression.InputFactory) ActionListener(org.elasticsearch.action.ActionListener) NodeStatsRequest(io.crate.execution.engine.collect.stats.NodeStatsRequest) Symbol(io.crate.expression.symbol.Symbol) ArrayList(java.util.ArrayList) BatchIterator(io.crate.data.BatchIterator) Test(org.junit.Test)

Example 35 with BatchIterator

use of io.crate.data.BatchIterator in project crate by crate.

the class FileReadingIteratorTest method testIteratorContract_givenDefaultJsonInputFormat_AndCSVExtension_thenWritesAsMap.

@Test
public void testIteratorContract_givenDefaultJsonInputFormat_AndCSVExtension_thenWritesAsMap() throws Exception {
    tempFilePath = createTempFile("tempfile", ".csv");
    tmpFile = tempFilePath.toFile();
    try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tmpFile), StandardCharsets.UTF_8)) {
        writer.write("name,id,age\n");
        writer.write("Arthur,4,38\n");
        writer.write("Trillian,5,33\n");
    }
    fileUri = tempFilePath.toUri().toString();
    Supplier<BatchIterator<Row>> batchIteratorSupplier = () -> createBatchIterator(Collections.singletonList(fileUri), JSON);
    List<Object[]> expectedResult = Arrays.asList(new Object[] { CSV_AS_MAP_FIRST_LINE }, new Object[] { CSV_AS_MAP_SECOND_LINE });
    BatchIteratorTester tester = new BatchIteratorTester(batchIteratorSupplier);
    tester.verifyResultAndEdgeCaseBehaviour(expectedResult);
}
Also used : FileOutputStream(java.io.FileOutputStream) BatchIteratorTester(io.crate.testing.BatchIteratorTester) OutputStreamWriter(java.io.OutputStreamWriter) BatchIterator(io.crate.data.BatchIterator) Test(org.junit.Test)

Aggregations

BatchIterator (io.crate.data.BatchIterator)50 Test (org.junit.Test)37 BatchIteratorTester (io.crate.testing.BatchIteratorTester)22 InMemoryBatchIterator (io.crate.data.InMemoryBatchIterator)17 Row (io.crate.data.Row)16 ArrayList (java.util.ArrayList)10 CrateUnitTest (io.crate.test.integration.CrateUnitTest)8 List (java.util.List)8 Map (java.util.Map)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 Bucket (io.crate.data.Bucket)6 InputFactory (io.crate.expression.InputFactory)6 Symbol (io.crate.analyze.symbol.Symbol)4 RowAccounting (io.crate.breaker.RowAccounting)4 RowN (io.crate.data.RowN)4 CombinedRow (io.crate.data.join.CombinedRow)4 InputFactory (io.crate.operation.InputFactory)4 TestingHelpers.isRow (io.crate.testing.TestingHelpers.isRow)4 UUID (java.util.UUID)4 ClusterService (org.elasticsearch.cluster.service.ClusterService)4