Search in sources :

Example 11 with DataSize

use of io.airlift.units.DataSize in project presto by prestodb.

the class OrcTestingUtil method createReader.

public static OrcRecordReader createReader(OrcDataSource dataSource, List<Long> columnIds, List<Type> types) throws IOException {
    OrcReader orcReader = new OrcReader(dataSource, new OrcMetadataReader(), new DataSize(1, Unit.MEGABYTE), new DataSize(1, Unit.MEGABYTE));
    List<String> columnNames = orcReader.getColumnNames();
    assertEquals(columnNames.size(), columnIds.size());
    Map<Integer, Type> includedColumns = new HashMap<>();
    int ordinal = 0;
    for (long columnId : columnIds) {
        assertEquals(columnNames.get(ordinal), String.valueOf(columnId));
        includedColumns.put(ordinal, types.get(ordinal));
        ordinal++;
    }
    return createRecordReader(orcReader, includedColumns);
}
Also used : Type(com.facebook.presto.spi.type.Type) OrcReader(com.facebook.presto.orc.OrcReader) HashMap(java.util.HashMap) OrcMetadataReader(com.facebook.presto.orc.metadata.OrcMetadataReader) DataSize(io.airlift.units.DataSize)

Example 12 with DataSize

use of io.airlift.units.DataSize in project presto by prestodb.

the class RcFileTester method createRcFileReader.

private static RcFileReader createRcFileReader(TempFile tempFile, Type type, RcFileEncoding encoding) throws IOException {
    RcFileDataSource rcFileDataSource = new FileRcFileDataSource(tempFile.getFile());
    RcFileReader rcFileReader = new RcFileReader(rcFileDataSource, encoding, ImmutableMap.of(0, type), new AircompressorCodecFactory(new HadoopCodecFactory(RcFileTester.class.getClassLoader())), 0, tempFile.getFile().length(), new DataSize(8, MEGABYTE));
    assertEquals(rcFileReader.getColumnCount(), 1);
    return rcFileReader;
}
Also used : DataSize(io.airlift.units.DataSize)

Example 13 with DataSize

use of io.airlift.units.DataSize in project presto by prestodb.

the class AbstractResourceConfigurationManager method configureGroup.

protected void configureGroup(ResourceGroup group, ResourceGroupSpec match) {
    if (match.getSoftMemoryLimit().isPresent()) {
        group.setSoftMemoryLimit(match.getSoftMemoryLimit().get());
    } else {
        synchronized (generalPoolMemoryFraction) {
            double fraction = match.getSoftMemoryLimitFraction().get();
            generalPoolMemoryFraction.put(group, fraction);
            group.setSoftMemoryLimit(new DataSize(generalPoolBytes * fraction, BYTE));
        }
    }
    group.setMaxQueuedQueries(match.getMaxQueued());
    group.setMaxRunningQueries(match.getMaxRunning());
    if (match.getSchedulingPolicy().isPresent()) {
        group.setSchedulingPolicy(match.getSchedulingPolicy().get());
    }
    if (match.getSchedulingWeight().isPresent()) {
        group.setSchedulingWeight(match.getSchedulingWeight().get());
    }
    if (match.getJmxExport().isPresent()) {
        group.setJmxExport(match.getJmxExport().get());
    }
    if (match.getSoftCpuLimit().isPresent() || match.getHardCpuLimit().isPresent()) {
        // This will never throw an exception if the validateManagerSpec method succeeds
        checkState(getCpuQuotaPeriodMillis().isPresent(), "Must specify hard CPU limit in addition to soft limit");
        Duration limit;
        if (match.getHardCpuLimit().isPresent()) {
            limit = match.getHardCpuLimit().get();
        } else {
            limit = match.getSoftCpuLimit().get();
        }
        long rate = (long) Math.min(1000.0 * limit.toMillis() / (double) getCpuQuotaPeriodMillis().get().toMillis(), Long.MAX_VALUE);
        rate = Math.max(1, rate);
        group.setCpuQuotaGenerationMillisPerSecond(rate);
    }
    if (match.getSoftCpuLimit().isPresent()) {
        group.setSoftCpuLimit(match.getSoftCpuLimit().get());
    }
    if (match.getHardCpuLimit().isPresent()) {
        group.setHardCpuLimit(match.getHardCpuLimit().get());
    }
}
Also used : DataSize(io.airlift.units.DataSize) Duration(io.airlift.units.Duration)

Example 14 with DataSize

use of io.airlift.units.DataSize in project presto by prestodb.

the class TestRcFileReaderManual method readValues.

private static List<Integer> readValues(Slice data, int offset, int length) throws IOException {
    if (offset < 0) {
        // adjust length to new offset
        length += offset;
        offset = 0;
    }
    if (offset + length > data.length()) {
        length = data.length() - offset;
    }
    RcFileReader reader = new RcFileReader(new SliceRcFileDataSource(data), new BinaryRcFileEncoding(), ImmutableMap.of(0, SMALLINT), new BogusRcFileCodecFactory(), offset, length, new DataSize(1, MEGABYTE));
    ImmutableList.Builder<Integer> values = ImmutableList.builder();
    while (reader.advance() >= 0) {
        Block block = reader.readBlock(0);
        for (int position = 0; position < block.getPositionCount(); position++) {
            values.add((int) SMALLINT.getLong(block, position));
        }
    }
    return values.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) DataSize(io.airlift.units.DataSize) Block(com.facebook.presto.spi.block.Block) BinaryRcFileEncoding(com.facebook.presto.rcfile.binary.BinaryRcFileEncoding)

Example 15 with DataSize

use of io.airlift.units.DataSize in project presto by prestodb.

the class ClusterMemoryManager method updatePools.

private synchronized void updatePools(Map<MemoryPoolId, Integer> queryCounts) {
    // Update view of cluster memory and pools
    List<MemoryInfo> nodeMemoryInfos = nodes.values().stream().map(RemoteNodeMemory::getInfo).filter(Optional::isPresent).map(Optional::get).collect(toImmutableList());
    long totalClusterMemory = nodeMemoryInfos.stream().map(MemoryInfo::getTotalNodeMemory).mapToLong(DataSize::toBytes).sum();
    clusterMemoryBytes.set(totalClusterMemory);
    Set<MemoryPoolId> activePoolIds = nodeMemoryInfos.stream().flatMap(info -> info.getPools().keySet().stream()).collect(toImmutableSet());
    // Make a copy to materialize the set difference
    Set<MemoryPoolId> removedPools = ImmutableSet.copyOf(difference(pools.keySet(), activePoolIds));
    for (MemoryPoolId removed : removedPools) {
        unexport(pools.get(removed));
        pools.remove(removed);
        if (changeListeners.containsKey(removed)) {
            for (Consumer<MemoryPoolInfo> listener : changeListeners.get(removed)) {
                listenerExecutor.execute(() -> listener.accept(new MemoryPoolInfo(0, 0, ImmutableMap.of())));
            }
        }
    }
    for (MemoryPoolId id : activePoolIds) {
        ClusterMemoryPool pool = pools.computeIfAbsent(id, poolId -> {
            ClusterMemoryPool newPool = new ClusterMemoryPool(poolId);
            String objectName = ObjectNames.builder(ClusterMemoryPool.class, newPool.getId().toString()).build();
            try {
                exporter.export(objectName, newPool);
            } catch (JmxException e) {
                log.error(e, "Error exporting memory pool %s", poolId);
            }
            return newPool;
        });
        pool.update(nodeMemoryInfos, queryCounts.getOrDefault(pool.getId(), 0));
        if (changeListeners.containsKey(id)) {
            MemoryPoolInfo info = pool.getInfo();
            for (Consumer<MemoryPoolInfo> listener : changeListeners.get(id)) {
                listenerExecutor.execute(() -> listener.accept(info));
            }
        }
    }
}
Also used : SystemSessionProperties.getQueryMaxCpuTime(com.facebook.presto.SystemSessionProperties.getQueryMaxCpuTime) Duration(io.airlift.units.Duration) ACTIVE(com.facebook.presto.spi.NodeState.ACTIVE) RESERVED_POOL(com.facebook.presto.memory.LocalMemoryManager.RESERVED_POOL) PreDestroy(javax.annotation.PreDestroy) Sets.difference(com.google.common.collect.Sets.difference) InternalNodeManager(com.facebook.presto.metadata.InternalNodeManager) Node(com.facebook.presto.spi.Node) Duration.nanosSince(io.airlift.units.Duration.nanosSince) Map(java.util.Map) GENERAL_POOL(com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL) ImmutableCollectors.toImmutableSet(com.facebook.presto.util.ImmutableCollectors.toImmutableSet) QueryManagerConfig(com.facebook.presto.execution.QueryManagerConfig) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) ServerConfig(com.facebook.presto.server.ServerConfig) ObjectNames(org.weakref.jmx.ObjectNames) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) GuardedBy(javax.annotation.concurrent.GuardedBy) Executors(java.util.concurrent.Executors) String.format(java.lang.String.format) ExceededCpuLimitException(com.facebook.presto.ExceededCpuLimitException) QueryIdGenerator(com.facebook.presto.execution.QueryIdGenerator) QueryExecution(com.facebook.presto.execution.QueryExecution) DataSize(io.airlift.units.DataSize) List(java.util.List) Optional(java.util.Optional) JmxException(org.weakref.jmx.JmxException) SystemSessionProperties.resourceOvercommit(com.facebook.presto.SystemSessionProperties.resourceOvercommit) JsonCodec(io.airlift.json.JsonCodec) HttpClient(io.airlift.http.client.HttpClient) ExceededMemoryLimitException.exceededGlobalLimit(com.facebook.presto.ExceededMemoryLimitException.exceededGlobalLimit) RESOURCE_OVERCOMMIT(com.facebook.presto.SystemSessionProperties.RESOURCE_OVERCOMMIT) Logger(io.airlift.log.Logger) DataSize.succinctBytes(io.airlift.units.DataSize.succinctBytes) HashMap(java.util.HashMap) PrestoException(com.facebook.presto.spi.PrestoException) CLUSTER_OUT_OF_MEMORY(com.facebook.presto.spi.StandardErrorCode.CLUSTER_OUT_OF_MEMORY) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) Managed(org.weakref.jmx.Managed) Objects.requireNonNull(java.util.Objects.requireNonNull) MemoryPoolInfo(com.facebook.presto.spi.memory.MemoryPoolInfo) SystemSessionProperties.getQueryMaxMemory(com.facebook.presto.SystemSessionProperties.getQueryMaxMemory) ExecutorService(java.util.concurrent.ExecutorService) ClusterMemoryPoolManager(com.facebook.presto.spi.memory.ClusterMemoryPoolManager) SHUTTING_DOWN(com.facebook.presto.spi.NodeState.SHUTTING_DOWN) LocationFactory(com.facebook.presto.execution.LocationFactory) Consumer(java.util.function.Consumer) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) AtomicLong(java.util.concurrent.atomic.AtomicLong) QueryId(com.facebook.presto.spi.QueryId) VisibleForTesting(com.google.common.annotations.VisibleForTesting) MBeanExporter(org.weakref.jmx.MBeanExporter) JmxException(org.weakref.jmx.JmxException) Optional(java.util.Optional) MemoryPoolInfo(com.facebook.presto.spi.memory.MemoryPoolInfo) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId)

Aggregations

DataSize (io.airlift.units.DataSize)114 Test (org.testng.annotations.Test)71 Duration (io.airlift.units.Duration)36 Page (com.facebook.presto.spi.Page)23 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)19 RowPagesBuilder (com.facebook.presto.RowPagesBuilder)11 HashAggregationOperatorFactory (com.facebook.presto.operator.HashAggregationOperator.HashAggregationOperatorFactory)11 URI (java.net.URI)11 MockQueryExecution (com.facebook.presto.execution.MockQueryExecution)10 RootInternalResourceGroup (com.facebook.presto.execution.resourceGroups.InternalResourceGroup.RootInternalResourceGroup)10 TestingHttpClient (io.airlift.http.client.testing.TestingHttpClient)10 Type (com.facebook.presto.spi.type.Type)9 MaterializedResult (com.facebook.presto.testing.MaterializedResult)9 MemoryPoolId (com.facebook.presto.spi.memory.MemoryPoolId)7 QueryId (com.facebook.presto.spi.QueryId)6 BufferResult (com.facebook.presto.execution.buffer.BufferResult)5 MetadataManager (com.facebook.presto.metadata.MetadataManager)5 TopNOperatorFactory (com.facebook.presto.operator.TopNOperator.TopNOperatorFactory)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 ArrayList (java.util.ArrayList)5