Search in sources :

Example 86 with IAE

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

the class CompactionTaskTest method testCreateCompactionTaskWithNullSegmentGranularityInGranularitySpecAndSegmentGranularityShouldSucceed.

@Test(expected = IAE.class)
public void testCreateCompactionTaskWithNullSegmentGranularityInGranularitySpecAndSegmentGranularityShouldSucceed() {
    final Builder builder = new Builder(DATA_SOURCE, segmentCacheManagerFactory, RETRY_POLICY_FACTORY);
    builder.inputSpec(new CompactionIntervalSpec(COMPACTION_INTERVAL, SegmentUtils.hashIds(SEGMENTS)));
    builder.tuningConfig(createTuningConfig());
    builder.segmentGranularity(Granularities.HOUR);
    builder.granularitySpec(new ClientCompactionTaskGranularitySpec(null, Granularities.DAY, null));
    try {
        builder.build();
    } catch (IAE iae) {
        Assert.assertEquals(StringUtils.format(CONFLICTING_SEGMENT_GRANULARITY_FORMAT, Granularities.HOUR, null), iae.getMessage());
        throw iae;
    }
    Assert.fail("Should not have reached here!");
}
Also used : Builder(org.apache.druid.indexing.common.task.CompactionTask.Builder) ClientCompactionTaskGranularitySpec(org.apache.druid.client.indexing.ClientCompactionTaskGranularitySpec) IAE(org.apache.druid.java.util.common.IAE) Test(org.junit.Test)

Example 87 with IAE

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

the class HttpRemoteTaskRunnerTest method createWorkerHolder.

private static WorkerHolder createWorkerHolder(ObjectMapper smileMapper, HttpClient httpClient, HttpRemoteTaskRunnerConfig config, ScheduledExecutorService workersSyncExec, WorkerHolder.Listener listener, Worker worker, List<TaskAnnouncement> knownAnnouncements, // running/completed on the worker.
List<TaskAnnouncement> preExistingTaskAnnouncements, // defines behavior for what to do when a particular task is assigned
Map<Task, List<TaskAnnouncement>> toBeAssignedTasks, // work completed
AtomicInteger ticks, // happened.
Set<String> actualShutdowns) {
    return new WorkerHolder(smileMapper, httpClient, config, workersSyncExec, listener, worker, knownAnnouncements) {

        private final String workerHost;

        private final int workerPort;

        private final LifecycleLock startStopLock = new LifecycleLock();

        {
            String hostAndPort = worker.getHost();
            int colonIndex = hostAndPort.indexOf(':');
            if (colonIndex == -1) {
                throw new IAE("Invalid host and port: [%s]", colonIndex);
            }
            workerHost = hostAndPort.substring(0, colonIndex);
            workerPort = Integer.parseInt(hostAndPort.substring(colonIndex + 1));
        }

        @Override
        public void start() {
            synchronized (startStopLock) {
                if (!startStopLock.canStart()) {
                    throw new ISE("Can't start worker[%s:%s].", workerHost, workerPort);
                }
                try {
                    disabled.set(false);
                    if (!preExistingTaskAnnouncements.isEmpty()) {
                        workersSyncExec.execute(() -> {
                            for (TaskAnnouncement announcement : preExistingTaskAnnouncements) {
                                tasksSnapshotRef.get().put(announcement.getTaskId(), announcement);
                                listener.taskAddedOrUpdated(announcement, this);
                            }
                            ticks.incrementAndGet();
                        });
                    }
                    startStopLock.started();
                } finally {
                    startStopLock.exitStart();
                }
            }
        }

        @Override
        public void stop() {
            synchronized (startStopLock) {
                if (!startStopLock.canStop()) {
                    throw new ISE("Can't stop worker[%s:%s].", workerHost, workerPort);
                }
                try {
                } finally {
                    startStopLock.exitStop();
                }
            }
        }

        @Override
        public boolean isInitialized() {
            return true;
        }

        @Override
        public void waitForInitialization() {
        }

        @Override
        public boolean assignTask(Task task) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException ex) {
                throw new RuntimeException(ex);
            }
            if (toImmutable().getCurrCapacityUsed() > worker.getCapacity()) {
                throw new ISE("Got assigned tasks more than capacity.");
            }
            final List<TaskAnnouncement> announcements;
            if (toBeAssignedTasks.containsKey(task)) {
                announcements = toBeAssignedTasks.get(task);
            } else {
                // no behavior specified for the task, so do default behavior of completing the task
                announcements = new ArrayList<>();
                announcements.add(TaskAnnouncement.create(task, TaskStatus.running(task.getId()), TaskLocation.unknown()));
                announcements.add(TaskAnnouncement.create(task, TaskStatus.running(task.getId()), TaskLocation.create(workerHost, workerPort, -1)));
                announcements.add(TaskAnnouncement.create(task, TaskStatus.success(task.getId()), TaskLocation.create(workerHost, workerPort, -1)));
            }
            workersSyncExec.execute(() -> {
                for (TaskAnnouncement announcement : announcements) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException ex) {
                        throw new RuntimeException(ex);
                    }
                    tasksSnapshotRef.get().put(announcement.getTaskId(), announcement);
                    listener.taskAddedOrUpdated(announcement, this);
                }
                ticks.incrementAndGet();
            });
            return true;
        }

        @Override
        public void shutdownTask(String taskId) {
            actualShutdowns.add(taskId);
        }
    };
}
Also used : Task(org.apache.druid.indexing.common.task.Task) NoopTask(org.apache.druid.indexing.common.task.NoopTask) TaskAnnouncement(org.apache.druid.indexing.worker.TaskAnnouncement) ISE(org.apache.druid.java.util.common.ISE) IAE(org.apache.druid.java.util.common.IAE) LifecycleLock(org.apache.druid.concurrent.LifecycleLock)

Example 88 with IAE

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

the class DruidProcessingConfig method intermediateComputeSizeBytes.

public int intermediateComputeSizeBytes() {
    HumanReadableBytes sizeBytesConfigured = intermediateComputeSizeBytesConfigured();
    if (!DEFAULT_PROCESSING_BUFFER_SIZE_BYTES.equals(sizeBytesConfigured)) {
        if (sizeBytesConfigured.getBytes() > Integer.MAX_VALUE) {
            throw new IAE("druid.processing.buffer.sizeBytes must be less than 2GiB");
        }
        return sizeBytesConfigured.getBytesInInt();
    } else if (computedBufferSizeBytes.get() != null) {
        return computedBufferSizeBytes.get();
    }
    long directSizeBytes;
    try {
        directSizeBytes = JvmUtils.getRuntimeInfo().getDirectMemorySizeBytes();
        log.info("Detected max direct memory size of [%,d] bytes", directSizeBytes);
    } catch (UnsupportedOperationException e) {
        // max direct memory defaults to max heap size on recent JDK version, unless set explicitly
        directSizeBytes = computeMaxMemoryFromMaxHeapSize();
        log.info("Defaulting to at most [%,d] bytes (25%% of max heap size) of direct memory for computation buffers", directSizeBytes);
    }
    int numProcessingThreads = getNumThreads();
    int numMergeBuffers = getNumMergeBuffers();
    int totalNumBuffers = numMergeBuffers + numProcessingThreads;
    int sizePerBuffer = (int) ((double) directSizeBytes / (double) (totalNumBuffers + 1));
    final int computedSizePerBuffer = Math.min(sizePerBuffer, MAX_DEFAULT_PROCESSING_BUFFER_SIZE_BYTES);
    if (computedBufferSizeBytes.compareAndSet(null, computedSizePerBuffer)) {
        log.info("Auto sizing buffers to [%,d] bytes each for [%,d] processing and [%,d] merge buffers", computedSizePerBuffer, numProcessingThreads, numMergeBuffers);
    }
    return computedSizePerBuffer;
}
Also used : HumanReadableBytes(org.apache.druid.java.util.common.HumanReadableBytes) IAE(org.apache.druid.java.util.common.IAE)

Example 89 with IAE

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

the class HyperUniquesAggregatorFactory method factorize.

@Override
public Aggregator factorize(ColumnSelectorFactory metricFactory) {
    BaseObjectColumnValueSelector selector = metricFactory.makeColumnValueSelector(fieldName);
    if (selector instanceof NilColumnValueSelector) {
        return NoopAggregator.instance();
    }
    final Class classOfObject = selector.classOfObject();
    if (classOfObject.equals(Object.class) || HyperLogLogCollector.class.isAssignableFrom(classOfObject)) {
        return new HyperUniquesAggregator(selector);
    }
    throw new IAE("Incompatible type for metric[%s], expected a HyperUnique, got a %s", fieldName, classOfObject);
}
Also used : HyperLogLogCollector(org.apache.druid.hll.HyperLogLogCollector) BaseObjectColumnValueSelector(org.apache.druid.segment.BaseObjectColumnValueSelector) IAE(org.apache.druid.java.util.common.IAE) NilColumnValueSelector(org.apache.druid.segment.NilColumnValueSelector)

Example 90 with IAE

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

the class DimensionSelectorUtils method makePredicateMatchingSet.

public static BitSet makePredicateMatchingSet(DimensionSelector selector, Predicate<String> predicate) {
    if (!selector.nameLookupPossibleInAdvance()) {
        throw new IAE("selector.nameLookupPossibleInAdvance() should return true");
    }
    int cardinality = selector.getValueCardinality();
    BitSet valueIds = new BitSet(cardinality);
    for (int i = 0; i < cardinality; i++) {
        if (predicate.apply(selector.lookupName(i))) {
            valueIds.set(i);
        }
    }
    return valueIds;
}
Also used : BitSet(java.util.BitSet) IAE(org.apache.druid.java.util.common.IAE)

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