Search in sources :

Example 1 with SimpleLocalMemoryContext

use of io.prestosql.memory.context.SimpleLocalMemoryContext in project hetu-core by openlookeng.

the class ExecutingStatementResource method getQuery.

protected Query getQuery(QueryId queryId, String slug) {
    Query query = queries.get(queryId);
    if (query != null) {
        if (!query.isSlugValid(slug)) {
            throw badRequest(NOT_FOUND, "Query not found");
        }
        return query;
    }
    // this is the first time the query has been accessed on this coordinator
    Session session;
    try {
        if (!queryManager.isQuerySlugValid(queryId, slug)) {
            throw badRequest(NOT_FOUND, "Query not found");
        }
        session = queryManager.getQuerySession(queryId);
    } catch (NoSuchElementException e) {
        throw badRequest(NOT_FOUND, "Query not found");
    }
    query = queries.computeIfAbsent(queryId, id -> {
        ExchangeClient exchangeClient = exchangeClientSupplier.get(new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), ExecutingStatementResource.class.getSimpleName()));
        if (SystemSessionProperties.isSnapshotEnabled(session)) {
            exchangeClient.setSnapshotEnabled(snapshotUtils.getOrCreateQuerySnapshotManager(queryId, session));
        }
        return Query.create(session, slug, queryManager, exchangeClient, responseExecutor, timeoutExecutor, blockEncodingSerde);
    });
    return query;
}
Also used : Produces(javax.ws.rs.Produces) SystemSessionProperties(io.prestosql.SystemSessionProperties) Path(javax.ws.rs.Path) Duration(io.airlift.units.Duration) QueryManager(io.prestosql.execution.QueryManager) PreDestroy(javax.annotation.PreDestroy) MediaType(javax.ws.rs.core.MediaType) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) QueryParam(javax.ws.rs.QueryParam) BoundedExecutor(io.airlift.concurrent.BoundedExecutor) SimpleLocalMemoryContext(io.prestosql.memory.context.SimpleLocalMemoryContext) SnapshotUtils(io.prestosql.snapshot.SnapshotUtils) HeaderParam(javax.ws.rs.HeaderParam) X_FORWARDED_PROTO(com.google.common.net.HttpHeaders.X_FORWARDED_PROTO) PRESTO_SET_ROLE(io.prestosql.client.PrestoHeaders.PRESTO_SET_ROLE) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) AsyncResponse(javax.ws.rs.container.AsyncResponse) NOT_FOUND(javax.ws.rs.core.Response.Status.NOT_FOUND) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Threads.threadsNamed(io.airlift.concurrent.Threads.threadsNamed) QueryStatusInfo(io.prestosql.client.QueryStatusInfo) Suspended(javax.ws.rs.container.Suspended) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) DataSize(io.airlift.units.DataSize) Response(javax.ws.rs.core.Response) Entry(java.util.Map.Entry) WebApplicationException(javax.ws.rs.WebApplicationException) UriInfo(javax.ws.rs.core.UriInfo) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AsyncResponseHandler.bindAsyncResponse(io.airlift.jaxrs.AsyncResponseHandler.bindAsyncResponse) AggregatedMemoryContext.newSimpleAggregatedMemoryContext(io.prestosql.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext) PRESTO_CLEAR_TRANSACTION_ID(io.prestosql.client.PrestoHeaders.PRESTO_CLEAR_TRANSACTION_ID) PathParam(javax.ws.rs.PathParam) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Logger(io.airlift.log.Logger) GET(javax.ws.rs.GET) PRESTO_SET_CATALOG(io.prestosql.client.PrestoHeaders.PRESTO_SET_CATALOG) MEGABYTE(io.airlift.units.DataSize.Unit.MEGABYTE) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) BlockEncodingSerde(io.prestosql.spi.block.BlockEncodingSerde) PRESTO_CLEAR_SESSION(io.prestosql.client.PrestoHeaders.PRESTO_CLEAR_SESSION) ExchangeClient(io.prestosql.operator.ExchangeClient) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) QueryId(io.prestosql.spi.QueryId) NoSuchElementException(java.util.NoSuchElementException) Status(javax.ws.rs.core.Response.Status) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) QueryResults(io.prestosql.client.QueryResults) ForStatementResource(io.prestosql.server.ForStatementResource) PRESTO_SET_PATH(io.prestosql.client.PrestoHeaders.PRESTO_SET_PATH) PRESTO_STARTED_TRANSACTION_ID(io.prestosql.client.PrestoHeaders.PRESTO_STARTED_TRANSACTION_ID) TEXT_PLAIN_TYPE(javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE) Futures(com.google.common.util.concurrent.Futures) URLEncoder(java.net.URLEncoder) PRESTO_SET_SCHEMA(io.prestosql.client.PrestoHeaders.PRESTO_SET_SCHEMA) PRESTO_ADDED_PREPARE(io.prestosql.client.PrestoHeaders.PRESTO_ADDED_PREPARE) Ordering(com.google.common.collect.Ordering) ExchangeClientSupplier(io.prestosql.operator.ExchangeClientSupplier) PRESTO_DEALLOCATED_PREPARE(io.prestosql.client.PrestoHeaders.PRESTO_DEALLOCATED_PREPARE) PRESTO_SET_SESSION(io.prestosql.client.PrestoHeaders.PRESTO_SET_SESSION) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ExchangeClient(io.prestosql.operator.ExchangeClient) SimpleLocalMemoryContext(io.prestosql.memory.context.SimpleLocalMemoryContext) NoSuchElementException(java.util.NoSuchElementException) Session(io.prestosql.Session)

Example 2 with SimpleLocalMemoryContext

use of io.prestosql.memory.context.SimpleLocalMemoryContext in project hetu-core by openlookeng.

the class TestExchangeClient method testMarkers.

@Test
public void testMarkers() {
    DataSize maxResponseSize = new DataSize(10, Unit.MEGABYTE);
    MockExchangeRequestProcessor processor = new MockExchangeRequestProcessor(maxResponseSize);
    URI location = URI.create("http://localhost:8080");
    String instanceId = "testing instance id";
    processor.addPage(location, createPage(1));
    MarkerPage marker = MarkerPage.snapshotPage(1);
    processor.addPage(location, marker);
    processor.addPage(location, createPage(2));
    processor.setComplete(location);
    @SuppressWarnings("resource") ExchangeClient exchangeClient = new ExchangeClient(new DataSize(32, Unit.MEGABYTE), maxResponseSize, 1, new Duration(1, TimeUnit.MINUTES), true, new TestingHttpClient(processor, scheduler), scheduler, new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), "test"), pageBufferClientCallbackExecutor, new NoOpFailureDetector());
    exchangeClient.setSnapshotEnabled(NOOP_SNAPSHOT_UTILS.getQuerySnapshotManager(new QueryId("query")));
    final String target1 = "target1";
    final String target2 = "target2";
    exchangeClient.addLocation(new TaskLocation(location, instanceId));
    exchangeClient.noMoreLocations();
    exchangeClient.addTarget(target1);
    exchangeClient.addTarget(target2);
    assertEquals(exchangeClient.isClosed(), false);
    assertPageEquals(getNextPage(exchangeClient, target1), createPage(1));
    assertEquals(exchangeClient.isClosed(), false);
    assertPageEquals(getNextPage(exchangeClient, target2), marker);
    assertEquals(exchangeClient.isClosed(), false);
    assertPageEquals(getNextPage(exchangeClient, target2), createPage(2));
    assertEquals(exchangeClient.isClosed(), false);
    // Target2 won't get any page, but because there are pending markers, it won't cause the client to close either
    assertTrue(exchangeClient.isBlocked().isDone());
    assertNull(getNextPage(exchangeClient, target2));
    assertEquals(exchangeClient.isClosed(), false);
    assertPageEquals(getNextPage(exchangeClient, target1), marker);
    // New target receives pending marker
    assertEquals(exchangeClient.isClosed(), false);
    final String target3 = "target3";
    exchangeClient.addTarget(target3);
    assertPageEquals(getNextPage(exchangeClient, target3), marker);
    assertFalse(exchangeClient.isBlocked().isDone());
    assertEquals(exchangeClient.isClosed(), false);
    exchangeClient.noMoreTargets();
    assertNull(getNextPage(exchangeClient));
    assertEquals(exchangeClient.isClosed(), true);
    ExchangeClientStatus status = exchangeClient.getStatus();
    assertEquals(status.getBufferedPages(), 0);
    assertEquals(status.getBufferedBytes(), 0);
    // client should have sent only 2 requests: one to get all pages and once to get the done signal
    assertStatus(status.getPageBufferClientStatuses().get(0), location, "closed", 3, 3, 3, "not scheduled");
}
Also used : NoOpFailureDetector(io.prestosql.failuredetector.NoOpFailureDetector) MarkerPage(io.prestosql.spi.snapshot.MarkerPage) SimpleLocalMemoryContext(io.prestosql.memory.context.SimpleLocalMemoryContext) QueryId(io.prestosql.spi.QueryId) Duration(io.airlift.units.Duration) URI(java.net.URI) DataSize(io.airlift.units.DataSize) TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) Test(org.testng.annotations.Test)

Example 3 with SimpleLocalMemoryContext

use of io.prestosql.memory.context.SimpleLocalMemoryContext in project hetu-core by openlookeng.

the class TestExchangeClient method testClose.

@Test
public void testClose() throws Exception {
    DataSize maxResponseSize = new DataSize(1, Unit.BYTE);
    MockExchangeRequestProcessor processor = new MockExchangeRequestProcessor(maxResponseSize);
    URI location = URI.create("http://localhost:8080");
    String instanceId = "testing instance id";
    processor.addPage(location, createPage(1));
    processor.addPage(location, createPage(2));
    processor.addPage(location, createPage(3));
    @SuppressWarnings("resource") ExchangeClient exchangeClient = new ExchangeClient(new DataSize(1, Unit.BYTE), maxResponseSize, 1, new Duration(1, TimeUnit.MINUTES), true, new TestingHttpClient(processor, newCachedThreadPool(daemonThreadsNamed("test-%s"))), scheduler, new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), "test"), pageBufferClientCallbackExecutor, new NoOpFailureDetector());
    exchangeClient.addLocation(new TaskLocation(location, instanceId));
    exchangeClient.noMoreLocations();
    // fetch a page
    assertEquals(exchangeClient.isClosed(), false);
    assertPageEquals(getNextPage(exchangeClient), createPage(1));
    // close client while pages are still available
    exchangeClient.close();
    while (!exchangeClient.isFinished()) {
        MILLISECONDS.sleep(10);
    }
    assertEquals(exchangeClient.isClosed(), true);
    Pair<SerializedPage, String> pair = exchangeClient.pollPage(null);
    assertNotNull(pair);
    assertNull(pair.getLeft());
    assertEquals(exchangeClient.getStatus().getBufferedPages(), 0);
    assertEquals(exchangeClient.getStatus().getBufferedBytes(), 0);
    // client should have sent only 2 requests: one to get all pages and once to get the done signal
    PageBufferClientStatus clientStatus = exchangeClient.getStatus().getPageBufferClientStatuses().get(0);
    assertEquals(clientStatus.getUri(), location);
    assertEquals(clientStatus.getState(), "closed", "status");
    assertEquals(clientStatus.getHttpRequestState(), "not scheduled", "httpRequestState");
}
Also used : NoOpFailureDetector(io.prestosql.failuredetector.NoOpFailureDetector) SimpleLocalMemoryContext(io.prestosql.memory.context.SimpleLocalMemoryContext) Duration(io.airlift.units.Duration) URI(java.net.URI) DataSize(io.airlift.units.DataSize) TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) SerializedPage(io.hetu.core.transport.execution.buffer.SerializedPage) Test(org.testng.annotations.Test)

Example 4 with SimpleLocalMemoryContext

use of io.prestosql.memory.context.SimpleLocalMemoryContext in project hetu-core by openlookeng.

the class TestExchangeClient method testAddLocation.

@Test(timeOut = 10000)
public void testAddLocation() throws Exception {
    DataSize maxResponseSize = new DataSize(10, Unit.MEGABYTE);
    MockExchangeRequestProcessor processor = new MockExchangeRequestProcessor(maxResponseSize);
    @SuppressWarnings("resource") ExchangeClient exchangeClient = new ExchangeClient(new DataSize(32, Unit.MEGABYTE), maxResponseSize, 1, new Duration(1, TimeUnit.MINUTES), true, new TestingHttpClient(processor, newCachedThreadPool(daemonThreadsNamed("test-%s"))), scheduler, new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), "test"), pageBufferClientCallbackExecutor, new NoOpFailureDetector());
    URI location1 = URI.create("http://localhost:8081/foo");
    String instanceId1 = "testing instance id";
    processor.addPage(location1, createPage(1));
    processor.addPage(location1, createPage(2));
    processor.addPage(location1, createPage(3));
    processor.setComplete(location1);
    exchangeClient.addLocation(new TaskLocation(location1, instanceId1));
    assertEquals(exchangeClient.isClosed(), false);
    assertPageEquals(getNextPage(exchangeClient), createPage(1));
    assertEquals(exchangeClient.isClosed(), false);
    assertPageEquals(getNextPage(exchangeClient), createPage(2));
    assertEquals(exchangeClient.isClosed(), false);
    assertPageEquals(getNextPage(exchangeClient), createPage(3));
    assertFalse(tryGetFutureValue(exchangeClient.isBlocked(), 10, MILLISECONDS).isPresent());
    assertEquals(exchangeClient.isClosed(), false);
    URI location2 = URI.create("http://localhost:8082/bar");
    String instanceId2 = "testing instance id2";
    processor.addPage(location2, createPage(4));
    processor.addPage(location2, createPage(5));
    processor.addPage(location2, createPage(6));
    processor.setComplete(location2);
    exchangeClient.addLocation(new TaskLocation(location2, instanceId2));
    assertEquals(exchangeClient.isClosed(), false);
    assertPageEquals(getNextPage(exchangeClient), createPage(4));
    assertEquals(exchangeClient.isClosed(), false);
    assertPageEquals(getNextPage(exchangeClient), createPage(5));
    assertEquals(exchangeClient.isClosed(), false);
    assertPageEquals(getNextPage(exchangeClient), createPage(6));
    assertFalse(tryGetFutureValue(exchangeClient.isBlocked(), 10, MILLISECONDS).isPresent());
    assertEquals(exchangeClient.isClosed(), false);
    exchangeClient.noMoreLocations();
    // receive a final GONE response, so just spin until it's closed or the test times out.
    while (!exchangeClient.isClosed()) {
        Thread.sleep(1);
    }
    ImmutableMap<URI, PageBufferClientStatus> statuses = uniqueIndex(exchangeClient.getStatus().getPageBufferClientStatuses(), PageBufferClientStatus::getUri);
    assertStatus(statuses.get(location1), location1, "closed", 3, 3, 3, "not scheduled");
    assertStatus(statuses.get(location2), location2, "closed", 3, 3, 3, "not scheduled");
}
Also used : NoOpFailureDetector(io.prestosql.failuredetector.NoOpFailureDetector) SimpleLocalMemoryContext(io.prestosql.memory.context.SimpleLocalMemoryContext) Duration(io.airlift.units.Duration) URI(java.net.URI) DataSize(io.airlift.units.DataSize) TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) Test(org.testng.annotations.Test)

Example 5 with SimpleLocalMemoryContext

use of io.prestosql.memory.context.SimpleLocalMemoryContext in project hetu-core by openlookeng.

the class TestExchangeClient method testAddTarget.

@Test
public void testAddTarget() {
    @SuppressWarnings("resource") ExchangeClient exchangeClient = new ExchangeClient(new DataSize(32, Unit.MEGABYTE), new DataSize(10, Unit.MEGABYTE), 1, new Duration(1, TimeUnit.MINUTES), true, mock(HttpClient.class), scheduler, new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), "test"), pageBufferClientCallbackExecutor, new NoOpFailureDetector());
    exchangeClient.setSnapshotEnabled(NOOP_SNAPSHOT_UTILS.getQuerySnapshotManager(new QueryId("query")));
    String origin1 = "location1";
    String origin2 = "location2";
    final String target1 = "target1";
    final String target2 = "target2";
    PagesSerde serde = testingPagesSerde();
    exchangeClient.addTarget(target1);
    exchangeClient.addPages(ImmutableList.of(serde.serialize(createPage(1))), origin1);
    MarkerPage marker = MarkerPage.snapshotPage(1);
    exchangeClient.addPages(ImmutableList.of(SerializedPage.forMarker(marker)), origin1);
    exchangeClient.addPages(ImmutableList.of(serde.serialize(createPage(2))), origin2);
    assertPageEquals(getNextPage(exchangeClient, target1), createPage(1));
    assertPageEquals(getNextPage(exchangeClient, target1), marker);
    exchangeClient.addTarget(target2);
    assertPageEquals(getNextPage(exchangeClient, target2, origin1), marker);
    assertPageEquals(getNextPage(exchangeClient, target1, origin2), createPage(2));
}
Also used : NoOpFailureDetector(io.prestosql.failuredetector.NoOpFailureDetector) MarkerPage(io.prestosql.spi.snapshot.MarkerPage) SimpleLocalMemoryContext(io.prestosql.memory.context.SimpleLocalMemoryContext) TestingPagesSerdeFactory.testingPagesSerde(io.prestosql.testing.TestingPagesSerdeFactory.testingPagesSerde) PagesSerde(io.hetu.core.transport.execution.buffer.PagesSerde) DataSize(io.airlift.units.DataSize) HttpClient(io.airlift.http.client.HttpClient) TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) QueryId(io.prestosql.spi.QueryId) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Aggregations

SimpleLocalMemoryContext (io.prestosql.memory.context.SimpleLocalMemoryContext)12 DataSize (io.airlift.units.DataSize)7 Duration (io.airlift.units.Duration)7 TestingHttpClient (io.airlift.http.client.testing.TestingHttpClient)6 NoOpFailureDetector (io.prestosql.failuredetector.NoOpFailureDetector)6 Test (org.testng.annotations.Test)6 URI (java.net.URI)5 Session (io.prestosql.Session)3 ExchangeClient (io.prestosql.operator.ExchangeClient)3 QueryId (io.prestosql.spi.QueryId)3 MarkerPage (io.prestosql.spi.snapshot.MarkerPage)2 NoSuchElementException (java.util.NoSuchElementException)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Ordering (com.google.common.collect.Ordering)1 X_FORWARDED_PROTO (com.google.common.net.HttpHeaders.X_FORWARDED_PROTO)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors.directExecutor (com.google.common.util.concurrent.MoreExecutors.directExecutor)1 BoundedExecutor (io.airlift.concurrent.BoundedExecutor)1 Threads.threadsNamed (io.airlift.concurrent.Threads.threadsNamed)1