Search in sources :

Example 1 with BlockEncodingSerde

use of com.facebook.presto.common.block.BlockEncodingSerde in project presto by prestodb.

the class TestFileSingleStreamSpillerFactory method testDistributesSpillOverPaths.

@Test
public void testDistributesSpillOverPaths() throws Exception {
    List<Type> types = ImmutableList.of(BIGINT);
    BlockEncodingSerde blockEncodingSerde = new BlockEncodingManager();
    List<Path> spillPaths = ImmutableList.of(spillPath1.toPath(), spillPath2.toPath());
    FileSingleStreamSpillerFactory spillerFactory = new FileSingleStreamSpillerFactory(// executor won't be closed, because we don't call destroy() on the spiller factory
    executor, blockEncodingSerde, new SpillerStats(), spillPaths, 1.0, false, false);
    assertEquals(listFiles(spillPath1.toPath()).size(), 0);
    assertEquals(listFiles(spillPath2.toPath()).size(), 0);
    Page page = buildPage();
    List<SingleStreamSpiller> spillers = new ArrayList<>();
    for (int i = 0; i < 10; ++i) {
        SingleStreamSpiller singleStreamSpiller = spillerFactory.create(types, new TestingSpillContext(), newSimpleAggregatedMemoryContext().newLocalMemoryContext("test"));
        getUnchecked(singleStreamSpiller.spill(page));
        spillers.add(singleStreamSpiller);
    }
    assertEquals(listFiles(spillPath1.toPath()).size(), 5);
    assertEquals(listFiles(spillPath2.toPath()).size(), 5);
    spillers.forEach(SingleStreamSpiller::close);
    assertEquals(listFiles(spillPath1.toPath()).size(), 0);
    assertEquals(listFiles(spillPath2.toPath()).size(), 0);
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) Page(com.facebook.presto.common.Page) BlockEncodingSerde(com.facebook.presto.common.block.BlockEncodingSerde) Type(com.facebook.presto.common.type.Type) BlockEncodingManager(com.facebook.presto.common.block.BlockEncodingManager) Test(org.testng.annotations.Test)

Example 2 with BlockEncodingSerde

use of com.facebook.presto.common.block.BlockEncodingSerde in project presto by prestodb.

the class TestFileSingleStreamSpillerFactory method throwsIfNoDiskSpace.

@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "No free space available for spill")
public void throwsIfNoDiskSpace() {
    List<Type> types = ImmutableList.of(BIGINT);
    BlockEncodingSerde blockEncodingSerde = new BlockEncodingManager();
    List<Path> spillPaths = ImmutableList.of(spillPath1.toPath(), spillPath2.toPath());
    FileSingleStreamSpillerFactory spillerFactory = new FileSingleStreamSpillerFactory(// executor won't be closed, because we don't call destroy() on the spiller factory
    executor, blockEncodingSerde, new SpillerStats(), spillPaths, 0.0, false, false);
    spillerFactory.create(types, new TestingSpillContext(), newSimpleAggregatedMemoryContext().newLocalMemoryContext("test"));
}
Also used : Path(java.nio.file.Path) Type(com.facebook.presto.common.type.Type) BlockEncodingManager(com.facebook.presto.common.block.BlockEncodingManager) BlockEncodingSerde(com.facebook.presto.common.block.BlockEncodingSerde) Test(org.testng.annotations.Test)

Example 3 with BlockEncodingSerde

use of com.facebook.presto.common.block.BlockEncodingSerde in project presto by prestodb.

the class LocalQueryProvider method getQuery.

public Query getQuery(QueryId queryId, String slug) {
    Query query = queries.get(queryId);
    if (query != null) {
        if (!query.isSlugValid(slug)) {
            throw notFound("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 notFound("Query not found");
        }
        session = queryManager.getQuerySession(queryId);
    } catch (NoSuchElementException e) {
        throw notFound("Query not found");
    }
    query = queries.computeIfAbsent(queryId, id -> {
        ExchangeClient exchangeClient = exchangeClientSupplier.get(new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), LocalQueryProvider.class.getSimpleName()));
        return Query.create(session, slug, queryManager, transactionManager, exchangeClient, responseExecutor, timeoutExecutor, blockEncodingSerde, retryCircuitBreaker);
    });
    return query;
}
Also used : Logger(com.facebook.airlift.log.Logger) QueryManager(com.facebook.presto.execution.QueryManager) BlockEncodingSerde(com.facebook.presto.common.block.BlockEncodingSerde) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) PreDestroy(javax.annotation.PreDestroy) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) BoundedExecutor(com.facebook.airlift.concurrent.BoundedExecutor) SimpleLocalMemoryContext(com.facebook.presto.memory.context.SimpleLocalMemoryContext) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NoSuchElementException(java.util.NoSuchElementException) AggregatedMemoryContext.newSimpleAggregatedMemoryContext(com.facebook.presto.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext) TransactionManager(com.facebook.presto.transaction.TransactionManager) Status(javax.ws.rs.core.Response.Status) Threads.threadsNamed(com.facebook.airlift.concurrent.Threads.threadsNamed) Session(com.facebook.presto.Session) ExchangeClient(com.facebook.presto.operator.ExchangeClient) ExchangeClientSupplier(com.facebook.presto.operator.ExchangeClientSupplier) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) TEXT_PLAIN_TYPE(javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE) Response(javax.ws.rs.core.Response) QueryId(com.facebook.presto.spi.QueryId) PostConstruct(javax.annotation.PostConstruct) Entry(java.util.Map.Entry) ForStatementResource(com.facebook.presto.server.ForStatementResource) WebApplicationException(javax.ws.rs.WebApplicationException) ExchangeClient(com.facebook.presto.operator.ExchangeClient) SimpleLocalMemoryContext(com.facebook.presto.memory.context.SimpleLocalMemoryContext) NoSuchElementException(java.util.NoSuchElementException) Session(com.facebook.presto.Session)

Example 4 with BlockEncodingSerde

use of com.facebook.presto.common.block.BlockEncodingSerde in project presto by prestodb.

the class TestFileSingleStreamSpillerFactory method testCleanupOldSpillFiles.

@Test
public void testCleanupOldSpillFiles() throws Exception {
    BlockEncodingSerde blockEncodingSerde = new BlockEncodingManager();
    List<Path> spillPaths = ImmutableList.of(spillPath1.toPath(), spillPath2.toPath());
    spillPath1.mkdirs();
    spillPath2.mkdirs();
    java.nio.file.Files.createTempFile(spillPath1.toPath(), SPILL_FILE_PREFIX, SPILL_FILE_SUFFIX);
    java.nio.file.Files.createTempFile(spillPath1.toPath(), SPILL_FILE_PREFIX, SPILL_FILE_SUFFIX);
    java.nio.file.Files.createTempFile(spillPath1.toPath(), SPILL_FILE_PREFIX, "blah");
    java.nio.file.Files.createTempFile(spillPath2.toPath(), SPILL_FILE_PREFIX, SPILL_FILE_SUFFIX);
    java.nio.file.Files.createTempFile(spillPath2.toPath(), "blah", SPILL_FILE_SUFFIX);
    java.nio.file.Files.createTempFile(spillPath2.toPath(), "blah", "blah");
    assertEquals(listFiles(spillPath1.toPath()).size(), 3);
    assertEquals(listFiles(spillPath2.toPath()).size(), 3);
    FileSingleStreamSpillerFactory spillerFactory = new FileSingleStreamSpillerFactory(// executor won't be closed, because we don't call destroy() on the spiller factory
    executor, blockEncodingSerde, new SpillerStats(), spillPaths, 1.0, false, false);
    spillerFactory.cleanupOldSpillFiles();
    assertEquals(listFiles(spillPath1.toPath()).size(), 1);
    assertEquals(listFiles(spillPath2.toPath()).size(), 2);
}
Also used : Path(java.nio.file.Path) BlockEncodingManager(com.facebook.presto.common.block.BlockEncodingManager) BlockEncodingSerde(com.facebook.presto.common.block.BlockEncodingSerde) Test(org.testng.annotations.Test)

Aggregations

BlockEncodingSerde (com.facebook.presto.common.block.BlockEncodingSerde)4 BlockEncodingManager (com.facebook.presto.common.block.BlockEncodingManager)3 Path (java.nio.file.Path)3 Test (org.testng.annotations.Test)3 Type (com.facebook.presto.common.type.Type)2 BoundedExecutor (com.facebook.airlift.concurrent.BoundedExecutor)1 Threads.threadsNamed (com.facebook.airlift.concurrent.Threads.threadsNamed)1 Logger (com.facebook.airlift.log.Logger)1 Session (com.facebook.presto.Session)1 Page (com.facebook.presto.common.Page)1 QueryManager (com.facebook.presto.execution.QueryManager)1 AggregatedMemoryContext.newSimpleAggregatedMemoryContext (com.facebook.presto.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext)1 SimpleLocalMemoryContext (com.facebook.presto.memory.context.SimpleLocalMemoryContext)1 ExchangeClient (com.facebook.presto.operator.ExchangeClient)1 ExchangeClientSupplier (com.facebook.presto.operator.ExchangeClientSupplier)1 ForStatementResource (com.facebook.presto.server.ForStatementResource)1 QueryId (com.facebook.presto.spi.QueryId)1 TransactionManager (com.facebook.presto.transaction.TransactionManager)1 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1