Search in sources :

Example 1 with PrestoThriftPageResult

use of io.prestosql.plugin.thrift.api.PrestoThriftPageResult in project hetu-core by openlookeng.

the class TestThriftIndexPageSource method testGetNextPageTwoConcurrentRequests.

@Test
public void testGetNextPageTwoConcurrentRequests() throws Exception {
    final int splits = 3;
    final int lookupRequestsConcurrency = 2;
    final int rowsPerSplit = 1;
    List<SettableFuture<PrestoThriftPageResult>> futures = IntStream.range(0, splits).mapToObj(i -> SettableFuture.<PrestoThriftPageResult>create()).collect(toImmutableList());
    List<CountDownLatch> signals = IntStream.range(0, splits).mapToObj(i -> new CountDownLatch(1)).collect(toImmutableList());
    TestingThriftService client = new TestingThriftService(rowsPerSplit, false, false) {

        @Override
        public ListenableFuture<PrestoThriftPageResult> getRows(PrestoThriftId splitId, List<String> columns, long maxBytes, PrestoThriftNullableToken nextToken) {
            int key = Ints.fromByteArray(splitId.getId());
            signals.get(key).countDown();
            return futures.get(key);
        }
    };
    ThriftConnectorStats stats = new ThriftConnectorStats();
    long pageSizeReceived = 0;
    ThriftIndexPageSource pageSource = new ThriftIndexPageSource((context, headers) -> client, ImmutableMap.of(), stats, new ThriftIndexHandle(new SchemaTableName("default", "table1"), TupleDomain.all()), ImmutableList.of(column("a", INTEGER)), ImmutableList.of(column("b", INTEGER)), new InMemoryRecordSet(ImmutableList.of(INTEGER), generateKeys(0, splits)), MAX_BYTES_PER_RESPONSE, lookupRequestsConcurrency);
    assertNull(pageSource.getNextPage());
    assertEquals((long) stats.getIndexPageSize().getAllTime().getTotal(), 0);
    signals.get(0).await(1, SECONDS);
    signals.get(1).await(1, SECONDS);
    signals.get(2).await(1, SECONDS);
    assertEquals(signals.get(0).getCount(), 0, "first request wasn't sent");
    assertEquals(signals.get(1).getCount(), 0, "second request wasn't sent");
    assertEquals(signals.get(2).getCount(), 1, "third request shouldn't be sent");
    // at this point first two requests were sent
    assertFalse(pageSource.isFinished());
    assertNull(pageSource.getNextPage());
    assertEquals((long) stats.getIndexPageSize().getAllTime().getTotal(), 0);
    // completing the second request
    futures.get(1).set(pageResult(20, null));
    Page page = pageSource.getNextPage();
    pageSizeReceived += page.getSizeInBytes();
    assertEquals((long) stats.getIndexPageSize().getAllTime().getTotal(), pageSizeReceived);
    assertNotNull(page);
    assertEquals(page.getPositionCount(), 1);
    assertEquals(page.getBlock(0).getInt(0, 0), 20);
    // not complete yet
    assertFalse(pageSource.isFinished());
    // once one of the requests completes the next one should be sent
    signals.get(2).await(1, SECONDS);
    assertEquals(signals.get(2).getCount(), 0, "third request wasn't sent");
    // completing the first request
    futures.get(0).set(pageResult(10, null));
    page = pageSource.getNextPage();
    assertNotNull(page);
    pageSizeReceived += page.getSizeInBytes();
    assertEquals((long) stats.getIndexPageSize().getAllTime().getTotal(), pageSizeReceived);
    assertEquals(page.getPositionCount(), 1);
    assertEquals(page.getBlock(0).getInt(0, 0), 10);
    // still not complete
    assertFalse(pageSource.isFinished());
    // completing the third request
    futures.get(2).set(pageResult(30, null));
    page = pageSource.getNextPage();
    assertNotNull(page);
    pageSizeReceived += page.getSizeInBytes();
    assertEquals((long) stats.getIndexPageSize().getAllTime().getTotal(), pageSizeReceived);
    assertEquals(page.getPositionCount(), 1);
    assertEquals(page.getBlock(0).getInt(0, 0), 30);
    // finished now
    assertTrue(pageSource.isFinished());
    // after completion
    assertNull(pageSource.getNextPage());
    pageSource.close();
}
Also used : SettableFuture(com.google.common.util.concurrent.SettableFuture) IntStream(java.util.stream.IntStream) Collections.shuffle(java.util.Collections.shuffle) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Assert.assertNull(org.testng.Assert.assertNull) PrestoThriftNullableTableMetadata(io.prestosql.plugin.thrift.api.PrestoThriftNullableTableMetadata) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) CompletableFuture(java.util.concurrent.CompletableFuture) INTEGER(io.prestosql.spi.type.IntegerType.INTEGER) SettableFuture(com.google.common.util.concurrent.SettableFuture) PrestoThriftNullableSchemaName(io.prestosql.plugin.thrift.api.PrestoThriftNullableSchemaName) PrestoThriftSchemaTableName(io.prestosql.plugin.thrift.api.PrestoThriftSchemaTableName) ArrayList(java.util.ArrayList) PrestoThriftPageResult(io.prestosql.plugin.thrift.api.PrestoThriftPageResult) InMemoryRecordSet(io.prestosql.spi.connector.InMemoryRecordSet) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ImmutableList(com.google.common.collect.ImmutableList) Type(io.prestosql.spi.type.Type) PrestoThriftService(io.prestosql.plugin.thrift.api.PrestoThriftService) Assert.assertFalse(org.testng.Assert.assertFalse) Block(io.prestosql.spi.block.Block) PrestoThriftBlock.integerData(io.prestosql.plugin.thrift.api.PrestoThriftBlock.integerData) PrestoThriftTupleDomain(io.prestosql.plugin.thrift.api.PrestoThriftTupleDomain) PrestoThriftServiceException(io.prestosql.plugin.thrift.api.PrestoThriftServiceException) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) PrestoThriftInteger(io.prestosql.plugin.thrift.api.datatypes.PrestoThriftInteger) ImmutableMap(com.google.common.collect.ImmutableMap) PrestoThriftId(io.prestosql.plugin.thrift.api.PrestoThriftId) TupleDomain(io.prestosql.spi.predicate.TupleDomain) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Page(io.prestosql.spi.Page) PrestoThriftSplitBatch(io.prestosql.plugin.thrift.api.PrestoThriftSplitBatch) Assert.assertNotNull(org.testng.Assert.assertNotNull) Ints(com.google.common.primitives.Ints) PrestoThriftSplit(io.prestosql.plugin.thrift.api.PrestoThriftSplit) PrestoThriftNullableToken(io.prestosql.plugin.thrift.api.PrestoThriftNullableToken) PrestoThriftNullableColumnSet(io.prestosql.plugin.thrift.api.PrestoThriftNullableColumnSet) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Assert.assertTrue(org.testng.Assert.assertTrue) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) PrestoThriftId(io.prestosql.plugin.thrift.api.PrestoThriftId) PrestoThriftNullableToken(io.prestosql.plugin.thrift.api.PrestoThriftNullableToken) PrestoThriftPageResult(io.prestosql.plugin.thrift.api.PrestoThriftPageResult) Page(io.prestosql.spi.Page) CountDownLatch(java.util.concurrent.CountDownLatch) PrestoThriftSchemaTableName(io.prestosql.plugin.thrift.api.PrestoThriftSchemaTableName) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) InMemoryRecordSet(io.prestosql.spi.connector.InMemoryRecordSet) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) Test(org.testng.annotations.Test)

Example 2 with PrestoThriftPageResult

use of io.prestosql.plugin.thrift.api.PrestoThriftPageResult in project hetu-core by openlookeng.

the class ThriftPageSource method sendDataRequestInternal.

private CompletableFuture<PrestoThriftPageResult> sendDataRequestInternal() {
    long start = System.nanoTime();
    ListenableFuture<PrestoThriftPageResult> rowsBatchFuture = client.getRows(splitId, columnNames, maxBytesPerResponse, new PrestoThriftNullableToken(nextToken));
    rowsBatchFuture = catchingThriftException(rowsBatchFuture);
    rowsBatchFuture.addListener(() -> readTimeNanos.addAndGet(System.nanoTime() - start), directExecutor());
    return toCompletableFuture(nonCancellationPropagating(rowsBatchFuture));
}
Also used : PrestoThriftNullableToken(io.prestosql.plugin.thrift.api.PrestoThriftNullableToken) PrestoThriftPageResult(io.prestosql.plugin.thrift.api.PrestoThriftPageResult)

Example 3 with PrestoThriftPageResult

use of io.prestosql.plugin.thrift.api.PrestoThriftPageResult in project hetu-core by openlookeng.

the class ThriftIndexPageSource method getNextPage.

@Override
public Page getNextPage() {
    if (finished) {
        return null;
    }
    if (!loadAllSplits()) {
        return null;
    }
    // check if any data requests were started
    if (dataSignalFuture == null) {
        // no data requests were started, start a number of initial requests
        checkState(contexts.isEmpty() && dataRequests.isEmpty(), "some splits are already started");
        if (splits.isEmpty()) {
            // all done: no splits
            finished = true;
            return null;
        }
        for (int i = 0; i < min(lookupRequestsConcurrency, splits.size()); i++) {
            startDataFetchForNextSplit();
        }
        updateSignalAndStatusFutures();
    }
    // check if any data request is finished
    if (!dataSignalFuture.isDone()) {
        // not finished yet
        return null;
    }
    // at least one of data requests completed
    ListenableFuture<PrestoThriftPageResult> resultFuture = getAndRemoveNextCompletedRequest();
    RunningSplitContext resultContext = contexts.remove(resultFuture);
    checkState(resultContext != null, "no associated context for the request");
    PrestoThriftPageResult pageResult = getFutureValue(resultFuture);
    Page page = pageResult.toPage(outputColumnTypes);
    if (page != null) {
        long pageSize = page.getSizeInBytes();
        completedBytes += pageSize;
        stats.addIndexPageSize(pageSize);
    } else {
        stats.addIndexPageSize(0);
    }
    if (pageResult.getNextToken() != null) {
        // can get more data
        sendDataRequest(resultContext, pageResult.getNextToken());
        updateSignalAndStatusFutures();
        return page;
    }
    // are there more splits available
    if (splitIndex < splits.size()) {
        // can send data request for a new split
        startDataFetchForNextSplit();
        updateSignalAndStatusFutures();
    } else if (!dataRequests.isEmpty()) {
        // no more new splits, but some requests are still in progress, wait for them
        updateSignalAndStatusFutures();
    } else {
        // all done: no more new splits, no requests in progress
        dataSignalFuture = null;
        statusFuture = null;
        finished = true;
    }
    return page;
}
Also used : PrestoThriftPageResult(io.prestosql.plugin.thrift.api.PrestoThriftPageResult) Page(io.prestosql.spi.Page)

Example 4 with PrestoThriftPageResult

use of io.prestosql.plugin.thrift.api.PrestoThriftPageResult in project hetu-core by openlookeng.

the class ThriftIndexPageSource method sendDataRequest.

private void sendDataRequest(RunningSplitContext context, @Nullable PrestoThriftId nextToken) {
    long start = System.nanoTime();
    ListenableFuture<PrestoThriftPageResult> future = context.getClient().getRows(context.getSplit().getSplitId(), outputColumnNames, maxBytesPerResponse, new PrestoThriftNullableToken(nextToken));
    future = catchingThriftException(future);
    future.addListener(() -> readTimeNanos.addAndGet(System.nanoTime() - start), directExecutor());
    dataRequests.add(future);
    contexts.put(future, context);
}
Also used : PrestoThriftNullableToken(io.prestosql.plugin.thrift.api.PrestoThriftNullableToken) PrestoThriftPageResult(io.prestosql.plugin.thrift.api.PrestoThriftPageResult)

Aggregations

PrestoThriftPageResult (io.prestosql.plugin.thrift.api.PrestoThriftPageResult)4 PrestoThriftNullableToken (io.prestosql.plugin.thrift.api.PrestoThriftNullableToken)3 Page (io.prestosql.spi.Page)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Ints (com.google.common.primitives.Ints)1 Futures.immediateFuture (com.google.common.util.concurrent.Futures.immediateFuture)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 PrestoThriftBlock.integerData (io.prestosql.plugin.thrift.api.PrestoThriftBlock.integerData)1 PrestoThriftId (io.prestosql.plugin.thrift.api.PrestoThriftId)1 PrestoThriftNullableColumnSet (io.prestosql.plugin.thrift.api.PrestoThriftNullableColumnSet)1 PrestoThriftNullableSchemaName (io.prestosql.plugin.thrift.api.PrestoThriftNullableSchemaName)1 PrestoThriftNullableTableMetadata (io.prestosql.plugin.thrift.api.PrestoThriftNullableTableMetadata)1 PrestoThriftSchemaTableName (io.prestosql.plugin.thrift.api.PrestoThriftSchemaTableName)1 PrestoThriftService (io.prestosql.plugin.thrift.api.PrestoThriftService)1 PrestoThriftServiceException (io.prestosql.plugin.thrift.api.PrestoThriftServiceException)1 PrestoThriftSplit (io.prestosql.plugin.thrift.api.PrestoThriftSplit)1 PrestoThriftSplitBatch (io.prestosql.plugin.thrift.api.PrestoThriftSplitBatch)1