Repository: hbase Updated Branches: refs/heads/0.98 7a804030f -> a0d138826
HBASE-14985 TimeRange constructors should set allTime when appropriate (Geoffrey Jacoby) Conflicts: hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestTimeRangeTracker.java Amending-Author: Andrew Purtell <apurt...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/a0d13882 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/a0d13882 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/a0d13882 Branch: refs/heads/0.98 Commit: a0d13882676d638191a4c7c77fadeb050c4a7e45 Parents: 7a80403 Author: tedyu <yuzhih...@gmail.com> Authored: Mon Apr 11 17:58:38 2016 -0700 Committer: Andrew Purtell <apurt...@apache.org> Committed: Tue Apr 12 12:29:59 2016 -0700 ---------------------------------------------------------------------- .../org/apache/hadoop/hbase/io/TimeRange.java | 12 ++- .../hbase/regionserver/TimeRangeTracker.java | 2 +- .../regionserver/TestTimeRangeTracker.java | 94 ++++++++++++++++++++ 3 files changed, 105 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/a0d13882/hbase-common/src/main/java/org/apache/hadoop/hbase/io/TimeRange.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/TimeRange.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/TimeRange.java index 86f3540..b2c3ebe 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/TimeRange.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/TimeRange.java @@ -36,8 +36,10 @@ import org.apache.hadoop.hbase.util.Bytes; @InterfaceAudience.Public @InterfaceStability.Stable public class TimeRange { - private long minStamp = 0L; - private long maxStamp = Long.MAX_VALUE; + private static final long MIN_TIME = 0L; + private static final long MAX_TIME = Long.MAX_VALUE; + private long minStamp = MIN_TIME; + private long maxStamp = MAX_TIME; private boolean allTime = false; /** @@ -54,6 +56,9 @@ public class TimeRange { */ public TimeRange(long minStamp) { this.minStamp = minStamp; + if (this.minStamp == MIN_TIME){ + this.allTime = true; + } } /** @@ -81,6 +86,9 @@ public class TimeRange { } this.minStamp = minStamp; this.maxStamp = maxStamp; + if (this.minStamp == MIN_TIME && this.maxStamp == MAX_TIME){ + this.allTime = true; + } } /** http://git-wip-us.apache.org/repos/asf/hbase/blob/a0d13882/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/TimeRangeTracker.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/TimeRangeTracker.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/TimeRangeTracker.java index dfa0ded..a93f828 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/TimeRangeTracker.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/TimeRangeTracker.java @@ -96,7 +96,7 @@ public class TimeRangeTracker implements Writable { * If required, update the current TimestampRange to include timestamp * @param timestamp the timestamp value to include */ - private synchronized void includeTimestamp(final long timestamp) { + synchronized void includeTimestamp(final long timestamp) { if (maximumTimestamp == -1) { minimumTimestamp = timestamp; maximumTimestamp = timestamp; http://git-wip-us.apache.org/repos/asf/hbase/blob/a0d13882/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestTimeRangeTracker.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestTimeRangeTracker.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestTimeRangeTracker.java new file mode 100644 index 0000000..8fca399 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestTimeRangeTracker.java @@ -0,0 +1,94 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.regionserver; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import org.apache.hadoop.hbase.io.TimeRange; +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +@Category({SmallTests.class}) +public class TestTimeRangeTracker { + + @Test + public void testRangeConstruction() throws IOException { + TimeRange defaultRange = new TimeRange(); + assertEquals(0L, defaultRange.getMin()); + assertEquals(Long.MAX_VALUE, defaultRange.getMax()); + assertTrue(defaultRange.isAllTime()); + + TimeRange oneArgRange = new TimeRange(0L); + assertEquals(0L, oneArgRange.getMin()); + assertEquals(Long.MAX_VALUE, oneArgRange.getMax()); + assertTrue(oneArgRange.isAllTime()); + + TimeRange oneArgRange2 = new TimeRange(1); + assertEquals(1, oneArgRange2.getMin()); + assertEquals(Long.MAX_VALUE, oneArgRange2.getMax()); + assertFalse(oneArgRange2.isAllTime()); + + TimeRange twoArgRange = new TimeRange(0L, Long.MAX_VALUE); + assertEquals(0L, twoArgRange.getMin()); + assertEquals(Long.MAX_VALUE, twoArgRange.getMax()); + assertTrue(twoArgRange.isAllTime()); + + TimeRange twoArgRange2 = new TimeRange(0L, Long.MAX_VALUE - 1); + assertEquals(0L, twoArgRange2.getMin()); + assertEquals(Long.MAX_VALUE - 1, twoArgRange2.getMax()); + assertFalse(twoArgRange2.isAllTime()); + + TimeRange twoArgRange3 = new TimeRange(1, Long.MAX_VALUE); + assertEquals(1, twoArgRange3.getMin()); + assertEquals(Long.MAX_VALUE, twoArgRange3.getMax()); + assertFalse(twoArgRange3.isAllTime()); + } + + /** + * Bit of code to test concurrent access on this class. + * @param args + * @throws InterruptedException + */ + public static void main(String[] args) throws InterruptedException { + long start = System.currentTimeMillis(); + final TimeRangeTracker trr = new TimeRangeTracker(); + final int threadCount = 5; + final int calls = 1024 * 1024 * 128; + Thread [] threads = new Thread[threadCount]; + for (int i = 0; i < threads.length; i++) { + Thread t = new Thread("" + i) { + @Override + public void run() { + for (int i = 0; i < calls; i++) trr.includeTimestamp(i); + } + }; + t.start(); + threads[i] = t; + } + for (int i = 0; i < threads.length; i++) { + threads[i].join(); + } + System.out.println(trr.getMinimumTimestamp() + " " + trr.getMaximumTimestamp() + " " + + (System.currentTimeMillis() - start)); + } +}