Search in sources :

Example 71 with Duration

use of org.joda.time.Duration in project druid by druid-io.

the class KillDatasourceMetadataTest method testConstructorFailIfInvalidPeriod.

@Test
public void testConstructorFailIfInvalidPeriod() {
    TestDruidCoordinatorConfig druidCoordinatorConfig = new TestDruidCoordinatorConfig(null, null, null, new Duration("PT5S"), null, null, null, null, null, null, null, null, null, null, new Duration("PT3S"), new Duration("PT1S"), 10, null);
    exception.expect(IllegalArgumentException.class);
    exception.expectMessage("Coordinator datasource metadata kill period must be >= druid.coordinator.period.metadataStoreManagementPeriod");
    killDatasourceMetadata = new KillDatasourceMetadata(druidCoordinatorConfig, mockIndexerMetadataStorageCoordinator, mockMetadataSupervisorManager);
}
Also used : TestDruidCoordinatorConfig(org.apache.druid.server.coordinator.TestDruidCoordinatorConfig) Duration(org.joda.time.Duration) Test(org.junit.Test)

Example 72 with Duration

use of org.joda.time.Duration in project druid by druid-io.

the class RetryPolicyTest method testGetAndIncrementRetryDelay.

@Test
public void testGetAndIncrementRetryDelay() {
    RetryPolicy retryPolicy = new RetryPolicy(new RetryPolicyConfig().setMinWait(new Period("PT1S")).setMaxWait(new Period("PT10S")).setMaxRetryCount(6));
    Assert.assertEquals(new Duration("PT1S"), retryPolicy.getAndIncrementRetryDelay());
    Assert.assertEquals(new Duration("PT2S"), retryPolicy.getAndIncrementRetryDelay());
    Assert.assertEquals(new Duration("PT4S"), retryPolicy.getAndIncrementRetryDelay());
    Assert.assertEquals(new Duration("PT8S"), retryPolicy.getAndIncrementRetryDelay());
    Assert.assertEquals(new Duration("PT10S"), retryPolicy.getAndIncrementRetryDelay());
    Assert.assertEquals(new Duration("PT10S"), retryPolicy.getAndIncrementRetryDelay());
    Assert.assertEquals(null, retryPolicy.getAndIncrementRetryDelay());
    Assert.assertTrue(retryPolicy.hasExceededRetryThreshold());
}
Also used : Period(org.joda.time.Period) Duration(org.joda.time.Duration) Test(org.junit.Test)

Example 73 with Duration

use of org.joda.time.Duration in project druid by druid-io.

the class RetryPolicyFactoryTest method testMakeRetryPolicy.

@Test
public void testMakeRetryPolicy() {
    RetryPolicyConfig config = new RetryPolicyConfig().setMinWait(new Period("PT1S")).setMaxWait(new Period("PT10S")).setMaxRetryCount(1);
    RetryPolicyFactory retryPolicyFactory = new RetryPolicyFactory(config);
    RetryPolicy retryPolicy = retryPolicyFactory.makeRetryPolicy();
    Assert.assertEquals(new Duration("PT1S"), retryPolicy.getAndIncrementRetryDelay());
    Assert.assertTrue(retryPolicy.hasExceededRetryThreshold());
}
Also used : Period(org.joda.time.Period) Duration(org.joda.time.Duration) Test(org.junit.Test)

Example 74 with Duration

use of org.joda.time.Duration in project druid by druid-io.

the class RealtimePlumber method startPersistThread.

protected void startPersistThread() {
    final Granularity segmentGranularity = schema.getGranularitySpec().getSegmentGranularity();
    final Period windowPeriod = config.getWindowPeriod();
    final DateTime truncatedNow = segmentGranularity.bucketStart(DateTimes.nowUtc());
    final long windowMillis = windowPeriod.toStandardDuration().getMillis();
    log.info("Expect to run at [%s]", DateTimes.nowUtc().plus(new Duration(System.currentTimeMillis(), segmentGranularity.increment(truncatedNow).getMillis() + windowMillis)));
    String threadName = StringUtils.format("%s-overseer-%d", schema.getDataSource(), config.getShardSpec().getPartitionNum());
    ThreadRenamingCallable<ScheduledExecutors.Signal> threadRenamingCallable = new ThreadRenamingCallable<ScheduledExecutors.Signal>(threadName) {

        @Override
        public ScheduledExecutors.Signal doCall() {
            if (stopped) {
                log.info("Stopping merge-n-push overseer thread");
                return ScheduledExecutors.Signal.STOP;
            }
            mergeAndPush();
            if (stopped) {
                log.info("Stopping merge-n-push overseer thread");
                return ScheduledExecutors.Signal.STOP;
            } else {
                return ScheduledExecutors.Signal.REPEAT;
            }
        }
    };
    Duration initialDelay = new Duration(System.currentTimeMillis(), segmentGranularity.increment(truncatedNow).getMillis() + windowMillis);
    Duration rate = new Duration(truncatedNow, segmentGranularity.increment(truncatedNow));
    ScheduledExecutors.scheduleAtFixedRate(scheduledExecutor, initialDelay, rate, threadRenamingCallable);
}
Also used : ThreadRenamingCallable(org.apache.druid.common.guava.ThreadRenamingCallable) Period(org.joda.time.Period) Duration(org.joda.time.Duration) Granularity(org.apache.druid.java.util.common.granularity.Granularity) DateTime(org.joda.time.DateTime) ScheduledExecutors(org.apache.druid.java.util.common.concurrent.ScheduledExecutors)

Example 75 with Duration

use of org.joda.time.Duration in project druid by druid-io.

the class FlushingPlumber method startFlushThread.

private void startFlushThread() {
    final Granularity segmentGranularity = schema.getGranularitySpec().getSegmentGranularity();
    final DateTime truncatedNow = segmentGranularity.bucketStart(DateTimes.nowUtc());
    final long windowMillis = config.getWindowPeriod().toStandardDuration().getMillis();
    log.info("Expect to run at [%s]", DateTimes.nowUtc().plus(new Duration(System.currentTimeMillis(), schema.getGranularitySpec().getSegmentGranularity().increment(truncatedNow).getMillis() + windowMillis)));
    String threadName = StringUtils.format("%s-flusher-%d", getSchema().getDataSource(), getConfig().getShardSpec().getPartitionNum());
    ThreadRenamingCallable<ScheduledExecutors.Signal> threadRenamingCallable = new ThreadRenamingCallable<ScheduledExecutors.Signal>(threadName) {

        @Override
        public ScheduledExecutors.Signal doCall() {
            if (stopped) {
                log.info("Stopping flusher thread");
                return ScheduledExecutors.Signal.STOP;
            }
            long minTimestamp = segmentGranularity.bucketStart(getRejectionPolicy().getCurrMaxTime().minus(windowMillis)).getMillis();
            List<Map.Entry<Long, Sink>> sinksToPush = new ArrayList<>();
            for (Map.Entry<Long, Sink> entry : getSinks().entrySet()) {
                final Long intervalStart = entry.getKey();
                if (intervalStart < minTimestamp) {
                    log.info("Adding entry[%s] to flush.", entry);
                    sinksToPush.add(entry);
                }
            }
            for (final Map.Entry<Long, Sink> entry : sinksToPush) {
                flushAfterDuration(entry.getKey(), entry.getValue());
            }
            if (stopped) {
                log.info("Stopping flusher thread");
                return ScheduledExecutors.Signal.STOP;
            } else {
                return ScheduledExecutors.Signal.REPEAT;
            }
        }
    };
    Duration initialDelay = new Duration(System.currentTimeMillis(), schema.getGranularitySpec().getSegmentGranularity().increment(truncatedNow).getMillis() + windowMillis);
    Duration rate = new Duration(truncatedNow, segmentGranularity.increment(truncatedNow));
    ScheduledExecutors.scheduleAtFixedRate(flushScheduledExec, initialDelay, rate, threadRenamingCallable);
}
Also used : ArrayList(java.util.ArrayList) Duration(org.joda.time.Duration) Granularity(org.apache.druid.java.util.common.granularity.Granularity) DateTime(org.joda.time.DateTime) ScheduledExecutors(org.apache.druid.java.util.common.concurrent.ScheduledExecutors) ThreadRenamingCallable(org.apache.druid.common.guava.ThreadRenamingCallable) Map(java.util.Map)

Aggregations

Duration (org.joda.time.Duration)272 Test (org.junit.Test)148 Instant (org.joda.time.Instant)66 DateTime (org.joda.time.DateTime)32 Period (org.joda.time.Period)27 IntervalWindow (org.apache.beam.sdk.transforms.windowing.IntervalWindow)24 TestDruidCoordinatorConfig (org.apache.druid.server.coordinator.TestDruidCoordinatorConfig)22 HashMap (java.util.HashMap)18 IOException (java.io.IOException)17 Category (org.junit.experimental.categories.Category)16 ArrayList (java.util.ArrayList)15 Map (java.util.Map)15 KV (org.apache.beam.sdk.values.KV)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 IndexSpec (org.apache.druid.segment.IndexSpec)12 Set (java.util.Set)10 GlobalWindows (org.apache.beam.sdk.transforms.windowing.GlobalWindows)10 DynamicPartitionsSpec (org.apache.druid.indexer.partitions.DynamicPartitionsSpec)10 Interval (org.joda.time.Interval)10 Request (com.metamx.http.client.Request)9