Search in sources :

Example 81 with IAE

use of org.apache.druid.java.util.common.IAE in project druid by druid-io.

the class StreamingMergeSortedGrouper method aggregate.

@Override
public AggregateResult aggregate(KeyType key) {
    try {
        final ByteBuffer keyBuffer = keySerde.toByteBuffer(key);
        if (keyBuffer.remaining() != keySize) {
            throw new IAE("keySerde.toByteBuffer(key).remaining[%s] != keySerde.keySize[%s], buffer was the wrong size?!", keyBuffer.remaining(), keySize);
        }
        final int prevRecordOffset = curWriteIndex * recordSize;
        if (curWriteIndex == -1 || !keyEquals(keyBuffer, buffer, prevRecordOffset)) {
            // Initialize a new slot for the new key. This may be potentially blocked if the array is full until at least
            // one slot becomes available.
            initNewSlot(keyBuffer);
        }
        final int curRecordOffset = curWriteIndex * recordSize;
        for (int i = 0; i < aggregatorOffsets.length; i++) {
            aggregators[i].aggregate(buffer, curRecordOffset + aggregatorOffsets[i]);
        }
        return AggregateResult.ok();
    } catch (RuntimeException e) {
        finished = true;
        throw e;
    }
}
Also used : IAE(org.apache.druid.java.util.common.IAE) ByteBuffer(java.nio.ByteBuffer)

Example 82 with IAE

use of org.apache.druid.java.util.common.IAE in project druid by druid-io.

the class AbstractBufferHashGrouper method aggregate.

@Override
public AggregateResult aggregate(KeyType key, int keyHash) {
    final ByteBuffer keyBuffer = keySerde.toByteBuffer(key);
    if (keyBuffer == null) {
        // be correct.
        return Groupers.dictionaryFull(0);
    }
    if (keyBuffer.remaining() != keySize) {
        throw new IAE("keySerde.toByteBuffer(key).remaining[%s] != keySerde.keySize[%s], buffer was the wrong size?!", keyBuffer.remaining(), keySize);
    }
    // find and try to expand if table is full and find again
    int bucket = hashTable.findBucketWithAutoGrowth(keyBuffer, keyHash, () -> {
    });
    if (bucket < 0) {
        // be correct.
        return Groupers.hashTableFull(0);
    }
    final int bucketStartOffset = hashTable.getOffsetForBucket(bucket);
    final boolean bucketWasUsed = hashTable.isBucketUsed(bucket);
    final ByteBuffer tableBuffer = hashTable.getTableBuffer();
    // Set up key and initialize the aggs if this is a new bucket.
    if (!bucketWasUsed) {
        hashTable.initializeNewBucketKey(bucket, keyBuffer, keyHash);
        aggregators.init(tableBuffer, bucketStartOffset + baseAggregatorOffset);
        newBucketHook(bucketStartOffset);
    }
    if (canSkipAggregate(bucketStartOffset)) {
        return AggregateResult.ok();
    }
    // Aggregate the current row.
    aggregators.aggregateBuffered(tableBuffer, bucketStartOffset + baseAggregatorOffset);
    afterAggregateHook(bucketStartOffset);
    return AggregateResult.ok();
}
Also used : IAE(org.apache.druid.java.util.common.IAE) ByteBuffer(java.nio.ByteBuffer)

Example 83 with IAE

use of org.apache.druid.java.util.common.IAE in project druid by druid-io.

the class ByteBufferHashTable method reset.

public void reset() {
    size = 0;
    maxBuckets = Math.min(tableArenaSize / bucketSizeWithHash, initialBuckets);
    regrowthThreshold = maxSizeForBuckets(maxBuckets);
    if (maxBuckets < 1) {
        throw new IAE("Not enough capacity for even one row! Need[%,d] but have[%,d].", bucketSizeWithHash + Integer.BYTES, buffer.capacity());
    }
    // Start table part-way through the buffer so the last growth can start from zero and thereby use more space.
    tableStart = tableArenaSize - maxBuckets * bucketSizeWithHash;
    int nextBuckets = maxBuckets * 2;
    while (true) {
        long nextBucketsSize = (long) nextBuckets * bucketSizeWithHash;
        if (nextBucketsSize > Integer.MAX_VALUE) {
            break;
        }
        final int nextTableStart = tableStart - nextBuckets * bucketSizeWithHash;
        if (nextTableStart > tableArenaSize / 2) {
            tableStart = nextTableStart;
            nextBuckets = nextBuckets * 2;
        } else {
            break;
        }
    }
    if (tableStart < tableArenaSize / 2) {
        tableStart = 0;
    }
    final ByteBuffer bufferDup = buffer.duplicate();
    bufferDup.position(tableStart);
    bufferDup.limit(tableStart + maxBuckets * bucketSizeWithHash);
    tableBuffer = bufferDup.slice();
    // Clear used bits of new table
    for (int i = 0; i < maxBuckets; i++) {
        tableBuffer.put(i * bucketSizeWithHash, (byte) 0);
    }
}
Also used : IAE(org.apache.druid.java.util.common.IAE) ByteBuffer(java.nio.ByteBuffer)

Example 84 with IAE

use of org.apache.druid.java.util.common.IAE in project druid by druid-io.

the class DruidNode method init.

private void init(String serviceName, String host, boolean bindOnHost, Integer plainTextPort, Integer tlsPort, boolean enablePlaintextPort, boolean enableTlsPort) {
    Preconditions.checkNotNull(serviceName);
    if (!enableTlsPort && !enablePlaintextPort) {
        throw new IAE("At least one of the druid.enablePlaintextPort or druid.enableTlsPort needs to be true.");
    }
    this.enablePlaintextPort = enablePlaintextPort;
    this.enableTlsPort = enableTlsPort;
    final boolean nullHost = host == null;
    HostAndPort hostAndPort;
    Integer portFromHostConfig;
    if (host != null) {
        hostAndPort = HostAndPort.fromString(host);
        host = hostAndPort.getHostText();
        portFromHostConfig = hostAndPort.hasPort() ? hostAndPort.getPort() : null;
        if (plainTextPort != null && portFromHostConfig != null && !plainTextPort.equals(portFromHostConfig)) {
            throw new IAE("Conflicting host:port [%s] and port [%d] settings", host, plainTextPort);
        }
        if (portFromHostConfig != null) {
            plainTextPort = portFromHostConfig;
        }
    } else {
        host = getDefaultHost();
    }
    if (enablePlaintextPort && enableTlsPort && ((plainTextPort == null || tlsPort == null) || plainTextPort.equals(tlsPort))) {
        // If both plainTExt and tls are enabled then do not allow plaintextPort to be null or
        throw new IAE("plaintextPort and tlsPort cannot be null or same if both http and https connectors are enabled");
    }
    if (enableTlsPort && (tlsPort == null || tlsPort < 0)) {
        throw new IAE("A valid tlsPort needs to specified when druid.enableTlsPort is set");
    }
    if (enablePlaintextPort) {
        // to preserve backwards compatible behaviour
        if (nullHost && plainTextPort == null) {
            plainTextPort = -1;
        } else {
            if (plainTextPort == null) {
                plainTextPort = SocketUtil.findOpenPort(8080);
            }
        }
        this.plaintextPort = plainTextPort;
    } else {
        this.plaintextPort = -1;
    }
    if (enableTlsPort) {
        this.tlsPort = tlsPort;
    } else {
        this.tlsPort = -1;
    }
    this.serviceName = serviceName;
    this.host = host;
    this.bindOnHost = bindOnHost;
}
Also used : HostAndPort(com.google.common.net.HostAndPort) IAE(org.apache.druid.java.util.common.IAE)

Example 85 with IAE

use of org.apache.druid.java.util.common.IAE in project druid by druid-io.

the class LocalQuerySegmentWalker method getQueryRunnerForIntervals.

@Override
public <T> QueryRunner<T> getQueryRunnerForIntervals(final Query<T> query, final Iterable<Interval> intervals) {
    final DataSourceAnalysis analysis = DataSourceAnalysis.forDataSource(query.getDataSource());
    if (!analysis.isConcreteBased() || !analysis.isGlobal()) {
        throw new IAE("Cannot query dataSource locally: %s", analysis.getDataSource());
    }
    // wrap in ReferenceCountingSegment, these aren't currently managed by SegmentManager so reference tracking doesn't
    // matter, but at least some or all will be in a future PR
    final Iterable<ReferenceCountingSegment> segments = FunctionalIterable.create(segmentWrangler.getSegmentsForIntervals(analysis.getBaseDataSource(), intervals)).transform(ReferenceCountingSegment::wrapRootGenerationSegment);
    final AtomicLong cpuAccumulator = new AtomicLong(0L);
    final Function<SegmentReference, SegmentReference> segmentMapFn = joinableFactoryWrapper.createSegmentMapFn(analysis.getJoinBaseTableFilter().map(Filters::toFilter).orElse(null), analysis.getPreJoinableClauses(), cpuAccumulator, analysis.getBaseQuery().orElse(query));
    final QueryRunnerFactory<T, Query<T>> queryRunnerFactory = conglomerate.findFactory(query);
    final QueryRunner<T> baseRunner = queryRunnerFactory.mergeRunners(DirectQueryProcessingPool.INSTANCE, () -> StreamSupport.stream(segments.spliterator(), false).map(segmentMapFn).map(queryRunnerFactory::createRunner).iterator());
    // it is already supported.
    return new FluentQueryRunnerBuilder<>(queryRunnerFactory.getToolchest()).create(scheduler.wrapQueryRunner(baseRunner)).applyPreMergeDecoration().mergeResults().applyPostMergeDecoration().emitCPUTimeMetric(emitter, cpuAccumulator);
}
Also used : ReferenceCountingSegment(org.apache.druid.segment.ReferenceCountingSegment) Query(org.apache.druid.query.Query) SegmentReference(org.apache.druid.segment.SegmentReference) DataSourceAnalysis(org.apache.druid.query.planning.DataSourceAnalysis) IAE(org.apache.druid.java.util.common.IAE) AtomicLong(java.util.concurrent.atomic.AtomicLong) Filters(org.apache.druid.segment.filter.Filters)

Aggregations

IAE (org.apache.druid.java.util.common.IAE)115 ISE (org.apache.druid.java.util.common.ISE)23 IOException (java.io.IOException)20 ByteBuffer (java.nio.ByteBuffer)19 ArrayList (java.util.ArrayList)16 List (java.util.List)14 Expr (org.apache.druid.math.expr.Expr)14 Nullable (javax.annotation.Nullable)12 ColumnType (org.apache.druid.segment.column.ColumnType)10 HashSet (java.util.HashSet)8 Map (java.util.Map)8 Interval (org.joda.time.Interval)8 VisibleForTesting (com.google.common.annotations.VisibleForTesting)7 HashMap (java.util.HashMap)7 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)7 File (java.io.File)6 Iterables (com.google.common.collect.Iterables)5 Arrays (java.util.Arrays)5 Test (org.junit.Test)5 ImmutableMap (com.google.common.collect.ImmutableMap)4