From 0c521e0a776ec8b40fd7070be07a794da93767dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20L=C3=A9aut=C3=A9?= Date: Tue, 2 Dec 2014 16:55:32 -0800 Subject: [PATCH] update joda-time and fix min/max instant --- common/src/main/java/io/druid/common/utils/JodaUtils.java | 4 ++++ .../io/druid/timeline/VersionedIntervalTimelineTest.java | 3 ++- .../main/java/io/druid/indexing/overlord/TaskLockbox.java | 5 +++-- pom.xml | 2 +- .../src/main/java/io/druid/granularity/AllGranularity.java | 5 +++-- .../java/io/druid/query/timeboundary/TimeBoundaryQuery.java | 5 +++-- processing/src/main/java/io/druid/segment/IndexMaker.java | 4 ++-- processing/src/main/java/io/druid/segment/IndexMerger.java | 4 ++-- .../indexing/granularity/ArbitraryGranularitySpec.java | 3 ++- .../realtime/plumber/MessageTimeRejectionPolicyFactory.java | 3 ++- .../segment/realtime/plumber/RealtimePlumberSchoolTest.java | 2 +- 11 files changed, 25 insertions(+), 15 deletions(-) diff --git a/common/src/main/java/io/druid/common/utils/JodaUtils.java b/common/src/main/java/io/druid/common/utils/JodaUtils.java index db6da04e875..a3e1b9cee26 100644 --- a/common/src/main/java/io/druid/common/utils/JodaUtils.java +++ b/common/src/main/java/io/druid/common/utils/JodaUtils.java @@ -36,6 +36,10 @@ import java.util.TreeSet; */ public class JodaUtils { + // joda limits years to [-292275054,292278993] that should be reasonable + public static final long MAX_INSTANT = new DateTime("292278993").getMillis(); + public static final long MIN_INSTANT = new DateTime("-292275054").getMillis(); + public static ArrayList condenseIntervals(Iterable intervals) { ArrayList retVal = Lists.newArrayList(); diff --git a/common/src/test/java/io/druid/timeline/VersionedIntervalTimelineTest.java b/common/src/test/java/io/druid/timeline/VersionedIntervalTimelineTest.java index 54a358223a6..e5611f6c332 100644 --- a/common/src/test/java/io/druid/timeline/VersionedIntervalTimelineTest.java +++ b/common/src/test/java/io/druid/timeline/VersionedIntervalTimelineTest.java @@ -26,6 +26,7 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Ordering; import com.google.common.collect.Sets; import com.metamx.common.Pair; +import io.druid.common.utils.JodaUtils; import io.druid.timeline.partition.ImmutablePartitionHolder; import io.druid.timeline.partition.IntegerPartitionChunk; import io.druid.timeline.partition.PartitionChunk; @@ -1294,7 +1295,7 @@ public class VersionedIntervalTimelineTest createExpected("2011-01-05/2011-01-10", "2", 2), createExpected("2011-01-10/2011-01-15", "3", 3) ), - timeline.lookup(new Interval(new DateTime(0), new DateTime(Long.MAX_VALUE))) + timeline.lookup(new Interval(new DateTime(0), new DateTime(JodaUtils.MAX_INSTANT))) ); } diff --git a/indexing-service/src/main/java/io/druid/indexing/overlord/TaskLockbox.java b/indexing-service/src/main/java/io/druid/indexing/overlord/TaskLockbox.java index 28506499f4c..90962e55705 100644 --- a/indexing-service/src/main/java/io/druid/indexing/overlord/TaskLockbox.java +++ b/indexing-service/src/main/java/io/druid/indexing/overlord/TaskLockbox.java @@ -36,6 +36,7 @@ import com.metamx.common.Pair; import com.metamx.common.guava.Comparators; import com.metamx.common.guava.FunctionalIterable; import com.metamx.emitter.EmittingLogger; +import io.druid.common.utils.JodaUtils; import io.druid.indexing.common.TaskLock; import io.druid.indexing.common.task.Task; import org.joda.time.DateTime; @@ -462,11 +463,11 @@ public class TaskLockbox final NavigableSet dsLockbox = dsRunning.navigableKeySet(); final Iterable searchIntervals = Iterables.concat( // Single interval that starts at or before ours - Collections.singletonList(dsLockbox.floor(new Interval(interval.getStart(), new DateTime(Long.MAX_VALUE)))), + Collections.singletonList(dsLockbox.floor(new Interval(interval.getStart(), new DateTime(JodaUtils.MAX_INSTANT)))), // All intervals that start somewhere between our start instant (exclusive) and end instant (exclusive) dsLockbox.subSet( - new Interval(interval.getStart(), new DateTime(Long.MAX_VALUE)), + new Interval(interval.getStart(), new DateTime(JodaUtils.MAX_INSTANT)), false, new Interval(interval.getEnd(), interval.getEnd()), false diff --git a/pom.xml b/pom.xml index 35fa76c921b..7562dee7406 100644 --- a/pom.xml +++ b/pom.xml @@ -348,7 +348,7 @@ joda-time joda-time - 2.1 + 2.6 com.google.code.findbugs diff --git a/processing/src/main/java/io/druid/granularity/AllGranularity.java b/processing/src/main/java/io/druid/granularity/AllGranularity.java index eebe4c43ab1..165c0a34134 100644 --- a/processing/src/main/java/io/druid/granularity/AllGranularity.java +++ b/processing/src/main/java/io/druid/granularity/AllGranularity.java @@ -20,19 +20,20 @@ package io.druid.granularity; import com.google.common.collect.ImmutableList; +import io.druid.common.utils.JodaUtils; public final class AllGranularity extends BaseQueryGranularity { @Override public long next(long offset) { - return Long.MAX_VALUE; + return JodaUtils.MAX_INSTANT; } @Override public long truncate(long offset) { - return Long.MIN_VALUE; + return JodaUtils.MIN_INSTANT; } @Override diff --git a/processing/src/main/java/io/druid/query/timeboundary/TimeBoundaryQuery.java b/processing/src/main/java/io/druid/query/timeboundary/TimeBoundaryQuery.java index ec2f32174fc..03adf942695 100644 --- a/processing/src/main/java/io/druid/query/timeboundary/TimeBoundaryQuery.java +++ b/processing/src/main/java/io/druid/query/timeboundary/TimeBoundaryQuery.java @@ -24,6 +24,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.Charsets; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import io.druid.common.utils.JodaUtils; import io.druid.query.BaseQuery; import io.druid.query.DataSource; import io.druid.query.Query; @@ -155,8 +156,8 @@ public class TimeBoundaryQuery extends BaseQuery return Lists.newArrayList(); } - DateTime min = new DateTime(Long.MAX_VALUE); - DateTime max = new DateTime(Long.MIN_VALUE); + DateTime min = new DateTime(JodaUtils.MAX_INSTANT); + DateTime max = new DateTime(JodaUtils.MIN_INSTANT); for (Result result : results) { TimeBoundaryResultValue val = result.getValue(); diff --git a/processing/src/main/java/io/druid/segment/IndexMaker.java b/processing/src/main/java/io/druid/segment/IndexMaker.java index ac9708723d6..4f6bf51605b 100644 --- a/processing/src/main/java/io/druid/segment/IndexMaker.java +++ b/processing/src/main/java/io/druid/segment/IndexMaker.java @@ -1363,8 +1363,8 @@ public class IndexMaker cols.writeToChannel(writer); dims.writeToChannel(writer); - DateTime minTime = new DateTime(Long.MAX_VALUE); - DateTime maxTime = new DateTime(0l); + DateTime minTime = new DateTime(JodaUtils.MAX_INSTANT); + DateTime maxTime = new DateTime(JodaUtils.MIN_INSTANT); for (IndexableAdapter index : adapters) { minTime = JodaUtils.minDateTime(minTime, index.getDataInterval().getStart()); diff --git a/processing/src/main/java/io/druid/segment/IndexMerger.java b/processing/src/main/java/io/druid/segment/IndexMerger.java index 3021ff83934..fdd2de05d02 100644 --- a/processing/src/main/java/io/druid/segment/IndexMerger.java +++ b/processing/src/main/java/io/druid/segment/IndexMerger.java @@ -457,8 +457,8 @@ public class IndexMerger GenericIndexed.fromIterable(mergedDimensions, GenericIndexed.stringStrategy).writeToChannel(channel); GenericIndexed.fromIterable(mergedMetrics, GenericIndexed.stringStrategy).writeToChannel(channel); - DateTime minTime = new DateTime(Long.MAX_VALUE); - DateTime maxTime = new DateTime(0l); + DateTime minTime = new DateTime(JodaUtils.MAX_INSTANT); + DateTime maxTime = new DateTime(JodaUtils.MIN_INSTANT); for (IndexableAdapter index : indexes) { minTime = JodaUtils.minDateTime(minTime, index.getDataInterval().getStart()); diff --git a/server/src/main/java/io/druid/segment/indexing/granularity/ArbitraryGranularitySpec.java b/server/src/main/java/io/druid/segment/indexing/granularity/ArbitraryGranularitySpec.java index 627667a5941..36a30eea391 100644 --- a/server/src/main/java/io/druid/segment/indexing/granularity/ArbitraryGranularitySpec.java +++ b/server/src/main/java/io/druid/segment/indexing/granularity/ArbitraryGranularitySpec.java @@ -28,6 +28,7 @@ import com.google.common.collect.PeekingIterator; import com.google.common.collect.Sets; import com.metamx.common.Granularity; import com.metamx.common.guava.Comparators; +import io.druid.common.utils.JodaUtils; import io.druid.granularity.QueryGranularity; import org.joda.time.DateTime; import org.joda.time.Interval; @@ -90,7 +91,7 @@ public class ArbitraryGranularitySpec implements GranularitySpec public Optional bucketInterval(DateTime dt) { // First interval with start time ≤ dt - final Interval interval = intervals.floor(new Interval(dt, new DateTime(Long.MAX_VALUE))); + final Interval interval = intervals.floor(new Interval(dt, new DateTime(JodaUtils.MAX_INSTANT))); if (interval != null && interval.contains(dt)) { return Optional.of(interval); diff --git a/server/src/main/java/io/druid/segment/realtime/plumber/MessageTimeRejectionPolicyFactory.java b/server/src/main/java/io/druid/segment/realtime/plumber/MessageTimeRejectionPolicyFactory.java index 7b6c5868017..2064ff11956 100644 --- a/server/src/main/java/io/druid/segment/realtime/plumber/MessageTimeRejectionPolicyFactory.java +++ b/server/src/main/java/io/druid/segment/realtime/plumber/MessageTimeRejectionPolicyFactory.java @@ -19,6 +19,7 @@ package io.druid.segment.realtime.plumber; +import io.druid.common.utils.JodaUtils; import org.joda.time.DateTime; import org.joda.time.Period; @@ -31,7 +32,7 @@ public class MessageTimeRejectionPolicyFactory implements RejectionPolicyFactory return new RejectionPolicy() { - private volatile long maxTimestamp = Long.MIN_VALUE; + private volatile long maxTimestamp = JodaUtils.MIN_INSTANT; @Override public DateTime getCurrMaxTime() diff --git a/server/src/test/java/io/druid/segment/realtime/plumber/RealtimePlumberSchoolTest.java b/server/src/test/java/io/druid/segment/realtime/plumber/RealtimePlumberSchoolTest.java index 420b7d12c2e..6d925ecc507 100644 --- a/server/src/test/java/io/druid/segment/realtime/plumber/RealtimePlumberSchoolTest.java +++ b/server/src/test/java/io/druid/segment/realtime/plumber/RealtimePlumberSchoolTest.java @@ -194,7 +194,7 @@ public class RealtimePlumberSchoolTest public void testPersist() throws Exception { final MutableBoolean committed = new MutableBoolean(false); - plumber.getSinks().put(0L, new Sink(new Interval(0, TimeUnit.HOURS.toMillis(1)),schema, tuningConfig, DateTime.now().toString())); + plumber.getSinks().put(0L, new Sink(new Interval(0, TimeUnit.HOURS.toMillis(1)),schema, tuningConfig, new DateTime("2014-12-01T12:34:56.789").toString())); plumber.startJob(); final InputRow row = EasyMock.createNiceMock(InputRow.class); EasyMock.expect(row.getTimestampFromEpoch()).andReturn(0L);