Search in sources :

Example 1 with StageId

use of io.trino.execution.StageId in project trino by trinodb.

the class TestBroadcastOutputBuffer method createBroadcastBuffer.

private BroadcastOutputBuffer createBroadcastBuffer(OutputBuffers outputBuffers, DataSize dataSize, AggregatedMemoryContext memoryContext, Executor notificationExecutor) {
    BroadcastOutputBuffer buffer = new BroadcastOutputBuffer(TASK_INSTANCE_ID, new OutputBufferStateMachine(new TaskId(new StageId(new QueryId("query"), 0), 0, 0), stateNotificationExecutor), dataSize, () -> memoryContext.newLocalMemoryContext("test"), notificationExecutor, () -> {
    });
    buffer.setOutputBuffers(outputBuffers);
    return buffer;
}
Also used : TaskId(io.trino.execution.TaskId) StageId(io.trino.execution.StageId) QueryId(io.trino.spi.QueryId)

Example 2 with StageId

use of io.trino.execution.StageId in project trino by trinodb.

the class TestDirectExchangeClient method setUpDataCorruption.

private DirectExchangeClient setUpDataCorruption(DataIntegrityVerification dataIntegrityVerification, URI location) {
    DataSize maxResponseSize = DataSize.of(10, Unit.MEGABYTE);
    MockExchangeRequestProcessor delegate = new MockExchangeRequestProcessor(maxResponseSize);
    delegate.addPage(location, createPage(1));
    delegate.addPage(location, createPage(2));
    delegate.setComplete(location);
    TestingHttpClient.Processor processor = new TestingHttpClient.Processor() {

        private int completedRequests;

        private TestingResponse savedResponse;

        @Override
        public synchronized Response handle(Request request) throws Exception {
            if (completedRequests == 0) {
                verify(savedResponse == null);
                TestingResponse response = (TestingResponse) delegate.handle(request);
                checkState(response.getStatusCode() == HttpStatus.OK.code(), "Unexpected status code: %s", response.getStatusCode());
                ListMultimap<String, String> headers = response.getHeaders().entries().stream().collect(toImmutableListMultimap(entry -> entry.getKey().toString(), Map.Entry::getValue));
                byte[] bytes = toByteArray(response.getInputStream());
                checkState(bytes.length > 42, "too short");
                savedResponse = new TestingResponse(HttpStatus.OK, headers, bytes.clone());
                // corrupt
                bytes[42]++;
                completedRequests++;
                return new TestingResponse(HttpStatus.OK, headers, bytes);
            }
            if (completedRequests == 1) {
                verify(savedResponse != null);
                Response response = savedResponse;
                savedResponse = null;
                completedRequests++;
                return response;
            }
            completedRequests++;
            return delegate.handle(request);
        }
    };
    DirectExchangeClient exchangeClient = new DirectExchangeClient("localhost", dataIntegrityVerification, new StreamingDirectExchangeBuffer(scheduler, DataSize.of(32, Unit.MEGABYTE)), maxResponseSize, 1, new Duration(1, TimeUnit.MINUTES), true, new TestingHttpClient(processor, scheduler), scheduler, new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), "test"), pageBufferClientCallbackExecutor, (taskId, failure) -> {
    });
    exchangeClient.addLocation(new TaskId(new StageId("query", 1), 0, 0), location);
    exchangeClient.noMoreLocations();
    return exchangeClient;
}
Also used : QueryId(io.trino.spi.QueryId) ListMultimap(com.google.common.collect.ListMultimap) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TimeoutException(java.util.concurrent.TimeoutException) BlockAssertions(io.trino.block.BlockAssertions) Test(org.testng.annotations.Test) Maps.uniqueIndex(com.google.common.collect.Maps.uniqueIndex) Unit(io.airlift.units.DataSize.Unit) Duration(io.airlift.units.Duration) ImmutableListMultimap.toImmutableListMultimap(com.google.common.collect.ImmutableListMultimap.toImmutableListMultimap) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) Map(java.util.Map) URI(java.net.URI) Assert.assertFalse(org.testng.Assert.assertFalse) ImmutableSet(com.google.common.collect.ImmutableSet) SimpleLocalMemoryContext(io.trino.memory.context.SimpleLocalMemoryContext) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.testng.annotations.BeforeClass) TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) Set(java.util.Set) PagesSerde.getSerializedPagePositionCount(io.trino.execution.buffer.PagesSerde.getSerializedPagePositionCount) TrinoException(io.trino.spi.TrinoException) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Assert.assertNotNull(org.testng.Assert.assertNotNull) PagesSerde(io.trino.execution.buffer.PagesSerde) Uninterruptibles.sleepUninterruptibly(com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly) TaskId(io.trino.execution.TaskId) Executors(java.util.concurrent.Executors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) TrinoTransportException(io.trino.spi.TrinoTransportException) CountDownLatch(java.util.concurrent.CountDownLatch) DataSize(io.airlift.units.DataSize) List(java.util.List) TestingPagesSerdeFactory.testingPagesSerde(io.trino.execution.buffer.TestingPagesSerdeFactory.testingPagesSerde) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Slice(io.airlift.slice.Slice) StageId(io.trino.execution.StageId) Assert.assertNull(org.testng.Assert.assertNull) AggregatedMemoryContext.newSimpleAggregatedMemoryContext(io.trino.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext) Page(io.trino.spi.Page) Assert.assertEquals(org.testng.Assert.assertEquals) ExchangeHandleResolver(io.trino.metadata.ExchangeHandleResolver) ExchangeId.createRandomExchangeId(io.trino.spi.exchange.ExchangeId.createRandomExchangeId) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Verify.verify(com.google.common.base.Verify.verify) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) Request(io.airlift.http.client.Request) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TestingResponse(io.airlift.http.client.testing.TestingResponse) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Assertions.assertLessThan(io.airlift.testing.Assertions.assertLessThan) ExecutorService(java.util.concurrent.ExecutorService) AfterClass(org.testng.annotations.AfterClass) Sets.newConcurrentHashSet(com.google.common.collect.Sets.newConcurrentHashSet) MoreFutures.tryGetFutureValue(io.airlift.concurrent.MoreFutures.tryGetFutureValue) GENERIC_INTERNAL_ERROR(io.trino.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR) ByteStreams.toByteArray(com.google.common.io.ByteStreams.toByteArray) DataIntegrityVerification(io.trino.FeaturesConfig.DataIntegrityVerification) TimeUnit(java.util.concurrent.TimeUnit) Futures(com.google.common.util.concurrent.Futures) HttpStatus(io.airlift.http.client.HttpStatus) Assert.assertEventually(io.trino.testing.assertions.Assert.assertEventually) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) Response(io.airlift.http.client.Response) Assert.assertTrue(org.testng.Assert.assertTrue) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ExchangeManagerRegistry(io.trino.exchange.ExchangeManagerRegistry) TestingResponse(io.airlift.http.client.testing.TestingResponse) SimpleLocalMemoryContext(io.trino.memory.context.SimpleLocalMemoryContext) TaskId(io.trino.execution.TaskId) StageId(io.trino.execution.StageId) Request(io.airlift.http.client.Request) Duration(io.airlift.units.Duration) TestingResponse(io.airlift.http.client.testing.TestingResponse) Response(io.airlift.http.client.Response) DataSize(io.airlift.units.DataSize) TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 3 with StageId

use of io.trino.execution.StageId in project trino by trinodb.

the class TestDirectExchangeClient method testStreamingTaskFailure.

@Test
public void testStreamingTaskFailure() {
    DataSize maxResponseSize = DataSize.of(10, Unit.MEGABYTE);
    MockExchangeRequestProcessor processor = new MockExchangeRequestProcessor(maxResponseSize);
    TaskId task1 = new TaskId(new StageId("query", 1), 0, 0);
    TaskId task2 = new TaskId(new StageId("query", 1), 1, 0);
    URI location1 = URI.create("http://localhost:8080/1");
    URI location2 = URI.create("http://localhost:8080/2");
    processor.addPage(location1, createPage(1));
    StreamingDirectExchangeBuffer buffer = new StreamingDirectExchangeBuffer(scheduler, DataSize.of(1, Unit.MEGABYTE));
    DirectExchangeClient exchangeClient = new DirectExchangeClient("localhost", DataIntegrityVerification.ABORT, buffer, maxResponseSize, 1, new Duration(1, SECONDS), true, new TestingHttpClient(processor, scheduler), scheduler, new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), "test"), pageBufferClientCallbackExecutor, (taskId, failure) -> {
    });
    exchangeClient.addLocation(task1, location1);
    exchangeClient.addLocation(task2, location2);
    assertPageEquals(getNextPage(exchangeClient), createPage(1));
    processor.setComplete(location1);
    assertFalse(tryGetFutureValue(exchangeClient.isBlocked(), 10, MILLISECONDS).isPresent());
    RuntimeException randomException = new RuntimeException("randomfailure");
    processor.setFailed(location2, randomException);
    assertThatThrownBy(() -> getNextPage(exchangeClient)).hasMessageContaining("Encountered too many errors talking to a worker node");
    assertFalse(exchangeClient.isFinished());
}
Also used : TaskId(io.trino.execution.TaskId) SimpleLocalMemoryContext(io.trino.memory.context.SimpleLocalMemoryContext) DataSize(io.airlift.units.DataSize) StageId(io.trino.execution.StageId) TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) Duration(io.airlift.units.Duration) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 4 with StageId

use of io.trino.execution.StageId in project trino by trinodb.

the class TestDirectExchangeClient method testStreamingBufferLimit.

@Test
public void testStreamingBufferLimit() {
    DataSize maxResponseSize = DataSize.ofBytes(1);
    MockExchangeRequestProcessor processor = new MockExchangeRequestProcessor(maxResponseSize);
    URI location = URI.create("http://localhost:8080");
    // add a pages
    processor.addPage(location, createPage(1));
    processor.addPage(location, createPage(2));
    processor.addPage(location, createPage(3));
    processor.setComplete(location);
    @SuppressWarnings("resource") DirectExchangeClient exchangeClient = new DirectExchangeClient("localhost", DataIntegrityVerification.ABORT, new StreamingDirectExchangeBuffer(scheduler, DataSize.ofBytes(1)), maxResponseSize, 1, new Duration(1, TimeUnit.MINUTES), true, new TestingHttpClient(processor, newCachedThreadPool(daemonThreadsNamed(getClass().getSimpleName() + "-testBufferLimit-%s"))), scheduler, new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), "test"), pageBufferClientCallbackExecutor, (taskId, failure) -> {
    });
    exchangeClient.addLocation(new TaskId(new StageId("query", 1), 0, 0), location);
    exchangeClient.noMoreLocations();
    assertFalse(exchangeClient.isFinished());
    long start = System.nanoTime();
    // wait for a page to be fetched
    do {
        // there is no thread coordination here, so sleep is the best we can do
        assertLessThan(Duration.nanosSince(start), new Duration(5, TimeUnit.SECONDS));
        sleepUninterruptibly(100, MILLISECONDS);
    } while (exchangeClient.getStatus().getBufferedPages() == 0);
    // client should have sent a single request for a single page
    assertEquals(exchangeClient.getStatus().getBufferedPages(), 1);
    assertTrue(exchangeClient.getStatus().getBufferedBytes() > 0);
    assertStatus(exchangeClient.getStatus().getPageBufferClientStatuses().get(0), location, "queued", 1, 1, 1, "not scheduled");
    // remove the page and wait for the client to fetch another page
    assertPageEquals(exchangeClient.pollPage(), createPage(1));
    do {
        assertLessThan(Duration.nanosSince(start), new Duration(5, TimeUnit.SECONDS));
        sleepUninterruptibly(100, MILLISECONDS);
    } while (exchangeClient.getStatus().getBufferedPages() == 0);
    // client should have sent a single request for a single page
    assertStatus(exchangeClient.getStatus().getPageBufferClientStatuses().get(0), location, "queued", 2, 2, 2, "not scheduled");
    assertEquals(exchangeClient.getStatus().getBufferedPages(), 1);
    assertTrue(exchangeClient.getStatus().getBufferedBytes() > 0);
    // remove the page and wait for the client to fetch another page
    assertPageEquals(exchangeClient.pollPage(), createPage(2));
    do {
        assertLessThan(Duration.nanosSince(start), new Duration(5, TimeUnit.SECONDS));
        sleepUninterruptibly(100, MILLISECONDS);
    } while (exchangeClient.getStatus().getBufferedPages() == 0);
    // client should have sent a single request for a single page
    assertStatus(exchangeClient.getStatus().getPageBufferClientStatuses().get(0), location, "queued", 3, 3, 3, "not scheduled");
    assertEquals(exchangeClient.getStatus().getBufferedPages(), 1);
    assertTrue(exchangeClient.getStatus().getBufferedBytes() > 0);
    // remove last page
    assertPageEquals(getNextPage(exchangeClient), createPage(3));
    // wait for client to decide there are no more pages
    assertNull(getNextPage(exchangeClient));
    assertEquals(exchangeClient.getStatus().getBufferedPages(), 0);
    assertTrue(exchangeClient.isFinished());
    exchangeClient.close();
    assertStatus(exchangeClient.getStatus().getPageBufferClientStatuses().get(0), location, "closed", 3, 5, 5, "not scheduled");
}
Also used : SimpleLocalMemoryContext(io.trino.memory.context.SimpleLocalMemoryContext) TaskId(io.trino.execution.TaskId) DataSize(io.airlift.units.DataSize) TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) StageId(io.trino.execution.StageId) Duration(io.airlift.units.Duration) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 5 with StageId

use of io.trino.execution.StageId in project trino by trinodb.

the class TestDirectExchangeClient method testAddLocation.

@Test
public void testAddLocation() throws Exception {
    DataSize maxResponseSize = DataSize.of(10, Unit.MEGABYTE);
    MockExchangeRequestProcessor processor = new MockExchangeRequestProcessor(maxResponseSize);
    TaskId task1 = new TaskId(new StageId("query", 1), 0, 0);
    TaskId task2 = new TaskId(new StageId("query", 1), 1, 0);
    TaskId task3 = new TaskId(new StageId("query", 1), 2, 0);
    URI location1 = URI.create("http://localhost:8080/1");
    URI location2 = URI.create("http://localhost:8080/2");
    URI location3 = URI.create("http://localhost:8080/3");
    processor.addPage(location1, createSerializedPage(1));
    processor.addPage(location1, createSerializedPage(2));
    TestingDirectExchangeBuffer buffer = new TestingDirectExchangeBuffer(DataSize.of(1, Unit.MEGABYTE));
    @SuppressWarnings("resource") DirectExchangeClient exchangeClient = new DirectExchangeClient("localhost", DataIntegrityVerification.ABORT, buffer, maxResponseSize, 1, new Duration(1, TimeUnit.MINUTES), true, new TestingHttpClient(processor, scheduler), scheduler, new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), "test"), pageBufferClientCallbackExecutor, (taskId, failure) -> {
    });
    assertThat(buffer.getAllTasks()).isEmpty();
    assertThat(buffer.getPages().asMap()).isEmpty();
    assertThat(buffer.getFinishedTasks()).isEmpty();
    assertThat(buffer.getFailedTasks().asMap()).isEmpty();
    assertFalse(buffer.isNoMoreTasks());
    exchangeClient.addLocation(task1, location1);
    assertThat(buffer.getAllTasks()).containsExactly(task1);
    assertTaskIsNotFinished(buffer, task1);
    processor.setComplete(location1);
    buffer.whenTaskFinished(task1).get(10, SECONDS);
    assertThat(buffer.getPages().get(task1)).hasSize(2);
    assertThat(buffer.getFinishedTasks()).containsExactly(task1);
    exchangeClient.addLocation(task2, location2);
    assertThat(buffer.getAllTasks()).containsExactlyInAnyOrder(task1, task2);
    assertTaskIsNotFinished(buffer, task2);
    processor.setComplete(location2);
    buffer.whenTaskFinished(task2).get(10, SECONDS);
    assertThat(buffer.getFinishedTasks()).containsExactlyInAnyOrder(task1, task2);
    assertThat(buffer.getPages().get(task2)).hasSize(0);
    exchangeClient.addLocation(task3, location3);
    assertThat(buffer.getAllTasks()).containsExactlyInAnyOrder(task1, task2, task3);
    assertTaskIsNotFinished(buffer, task3);
    exchangeClient.noMoreLocations();
    assertTrue(buffer.isNoMoreTasks());
    assertThat(buffer.getAllTasks()).containsExactlyInAnyOrder(task1, task2, task3);
    assertTaskIsNotFinished(buffer, task3);
    exchangeClient.close();
    buffer.whenTaskFinished(task3).get(10, SECONDS);
    assertThat(buffer.getFinishedTasks()).containsExactlyInAnyOrder(task1, task2, task3);
    assertThat(buffer.getFailedTasks().asMap()).isEmpty();
    assertEventually(() -> assertEquals(exchangeClient.getStatus().getPageBufferClientStatuses().get(0).getHttpRequestState(), "not scheduled", "httpRequestState"));
    assertEventually(() -> assertEquals(exchangeClient.getStatus().getPageBufferClientStatuses().get(1).getHttpRequestState(), "not scheduled", "httpRequestState"));
    assertEventually(() -> assertEquals(exchangeClient.getStatus().getPageBufferClientStatuses().get(2).getHttpRequestState(), "not scheduled", "httpRequestState"));
    assertTrue(exchangeClient.isFinished());
}
Also used : TaskId(io.trino.execution.TaskId) SimpleLocalMemoryContext(io.trino.memory.context.SimpleLocalMemoryContext) DataSize(io.airlift.units.DataSize) StageId(io.trino.execution.StageId) TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) Duration(io.airlift.units.Duration) URI(java.net.URI) Test(org.testng.annotations.Test)

Aggregations

StageId (io.trino.execution.StageId)47 TaskId (io.trino.execution.TaskId)44 Test (org.testng.annotations.Test)38 Duration (io.airlift.units.Duration)25 QueryId (io.trino.spi.QueryId)25 DynamicFilterId (io.trino.sql.planner.plan.DynamicFilterId)15 URI (java.net.URI)14 SimpleLocalMemoryContext (io.trino.memory.context.SimpleLocalMemoryContext)13 DataSize (io.airlift.units.DataSize)12 DynamicFilter (io.trino.spi.connector.DynamicFilter)12 Symbol (io.trino.sql.planner.Symbol)12 TestingHttpClient (io.airlift.http.client.testing.TestingHttpClient)11 SymbolAllocator (io.trino.sql.planner.SymbolAllocator)11 TestingColumnHandle (io.trino.spi.connector.TestingColumnHandle)10 DynamicFilters.createDynamicFilterExpression (io.trino.sql.DynamicFilters.createDynamicFilterExpression)9 TestingTicker (io.airlift.testing.TestingTicker)8 Expression (io.trino.sql.tree.Expression)8 Phaser (java.util.concurrent.Phaser)8 ImmutableList (com.google.common.collect.ImmutableList)7 TupleDomain (io.trino.spi.predicate.TupleDomain)7