HBASE-25235 Cleanup the deprecated methods in TimeRange (#2616)
Signed-off-by: Jan Hentschel <janh@apache.org> Signed-off-by: stack <stack@apache.org>
This commit is contained in:
parent
c98e993b23
commit
f37cd05c32
|
@ -68,7 +68,7 @@ public class Append extends Mutation {
|
|||
* @return this
|
||||
*/
|
||||
public Append setTimeRange(long minStamp, long maxStamp) {
|
||||
tr = new TimeRange(minStamp, maxStamp);
|
||||
tr = TimeRange.between(minStamp, maxStamp);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -162,10 +162,9 @@ public class Append extends Mutation {
|
|||
|
||||
/**
|
||||
* Add column and value to this Append operation.
|
||||
* @param cell
|
||||
* @return This instance
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Append add(final Cell cell) {
|
||||
try {
|
||||
super.add(cell);
|
||||
|
|
|
@ -74,7 +74,6 @@ public class Get extends Query implements Row {
|
|||
private int storeOffset = 0;
|
||||
private TimeRange tr = TimeRange.allTime();
|
||||
private boolean checkExistenceOnly = false;
|
||||
private boolean closestRowBefore = false;
|
||||
private Map<byte [], NavigableSet<byte []>> familyMap = new TreeMap<>(Bytes.BYTES_COMPARATOR);
|
||||
|
||||
/**
|
||||
|
@ -199,11 +198,10 @@ public class Get extends Query implements Row {
|
|||
* [minStamp, maxStamp).
|
||||
* @param minStamp minimum timestamp value, inclusive
|
||||
* @param maxStamp maximum timestamp value, exclusive
|
||||
* @throws IOException
|
||||
* @return this for invocation chaining
|
||||
*/
|
||||
public Get setTimeRange(long minStamp, long maxStamp) throws IOException {
|
||||
tr = new TimeRange(minStamp, maxStamp);
|
||||
tr = TimeRange.between(minStamp, maxStamp);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -214,17 +212,17 @@ public class Get extends Query implements Row {
|
|||
*/
|
||||
public Get setTimestamp(long timestamp) {
|
||||
try {
|
||||
tr = new TimeRange(timestamp, timestamp + 1);
|
||||
tr = TimeRange.at(timestamp);
|
||||
} catch(Exception e) {
|
||||
// This should never happen, unless integer overflow or something extremely wrong...
|
||||
LOG.error("TimeRange failed, likely caused by integer overflow. ", e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override public Get setColumnFamilyTimeRange(byte[] cf, long minStamp, long maxStamp) {
|
||||
@Override
|
||||
public Get setColumnFamilyTimeRange(byte[] cf, long minStamp, long maxStamp) {
|
||||
return (Get) super.setColumnFamilyTimeRange(cf, minStamp, maxStamp);
|
||||
}
|
||||
|
||||
|
|
|
@ -148,9 +148,8 @@ public class Increment extends Mutation {
|
|||
* @throws IOException if invalid time range
|
||||
* @return this
|
||||
*/
|
||||
public Increment setTimeRange(long minStamp, long maxStamp)
|
||||
throws IOException {
|
||||
tr = new TimeRange(minStamp, maxStamp);
|
||||
public Increment setTimeRange(long minStamp, long maxStamp) throws IOException {
|
||||
tr = TimeRange.between(minStamp, maxStamp);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -230,7 +230,7 @@ public abstract class Query extends OperationWithAttributes {
|
|||
*/
|
||||
|
||||
public Query setColumnFamilyTimeRange(byte[] cf, long minStamp, long maxStamp) {
|
||||
colFamTimeRangeMap.put(cf, new TimeRange(minStamp, maxStamp));
|
||||
colFamTimeRangeMap.put(cf, TimeRange.between(minStamp, maxStamp));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -316,7 +316,7 @@ public class Scan extends Query {
|
|||
* @return this
|
||||
*/
|
||||
public Scan setTimeRange(long minStamp, long maxStamp) throws IOException {
|
||||
tr = new TimeRange(minStamp, maxStamp);
|
||||
tr = TimeRange.between(minStamp, maxStamp);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -350,7 +350,7 @@ public class Scan extends Query {
|
|||
*/
|
||||
public Scan setTimestamp(long timestamp) {
|
||||
try {
|
||||
tr = new TimeRange(timestamp, timestamp + 1);
|
||||
tr = TimeRange.at(timestamp);
|
||||
} catch(Exception e) {
|
||||
// This should never happen, unless integer overflow or something extremely wrong...
|
||||
LOG.error("TimeRange failed, likely caused by integer overflow. ", e);
|
||||
|
|
|
@ -2861,10 +2861,18 @@ public final class ProtobufUtil {
|
|||
}
|
||||
|
||||
public static TimeRange toTimeRange(HBaseProtos.TimeRange timeRange) {
|
||||
return timeRange == null ?
|
||||
TimeRange.allTime() :
|
||||
new TimeRange(timeRange.hasFrom() ? timeRange.getFrom() : 0,
|
||||
timeRange.hasTo() ? timeRange.getTo() : Long.MAX_VALUE);
|
||||
if (timeRange == null) {
|
||||
return TimeRange.allTime();
|
||||
}
|
||||
if (timeRange.hasFrom()) {
|
||||
if (timeRange.hasTo()) {
|
||||
return TimeRange.between(timeRange.getFrom(), timeRange.getTo());
|
||||
} else {
|
||||
return TimeRange.from(timeRange.getFrom());
|
||||
}
|
||||
} else {
|
||||
return TimeRange.until(timeRange.getTo());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,24 +18,23 @@
|
|||
|
||||
package org.apache.hadoop.hbase.io;
|
||||
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.apache.yetus.audience.InterfaceAudience;
|
||||
|
||||
/**
|
||||
* Represents an interval of version timestamps. Presumes timestamps between
|
||||
* {@link #INITIAL_MIN_TIMESTAMP} and {@link #INITIAL_MAX_TIMESTAMP} only. Gets freaked out if
|
||||
* passed a timestamp that is < {@link #INITIAL_MIN_TIMESTAMP},
|
||||
* <p>
|
||||
* <p/>
|
||||
* Evaluated according to minStamp <= timestamp < maxStamp or [minStamp,maxStamp) in interval
|
||||
* notation.
|
||||
* <p>
|
||||
* <p/>
|
||||
* Can be returned and read by clients. Should not be directly created by clients. Thus, all
|
||||
* constructors are purposely @InterfaceAudience.Private.
|
||||
* <p>
|
||||
* <p/>
|
||||
* Immutable. Thread-safe.
|
||||
*/
|
||||
@InterfaceAudience.Public
|
||||
public class TimeRange {
|
||||
public final class TimeRange {
|
||||
public static final long INITIAL_MIN_TIMESTAMP = 0L;
|
||||
public static final long INITIAL_MAX_TIMESTAMP = Long.MAX_VALUE;
|
||||
private static final TimeRange ALL_TIME = new TimeRange(INITIAL_MIN_TIMESTAMP,
|
||||
|
@ -84,67 +83,13 @@ public class TimeRange {
|
|||
private final long maxStamp;
|
||||
private final boolean allTime;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
* Represents interval [0, Long.MAX_VALUE) (allTime)
|
||||
* @deprecated This is made @InterfaceAudience.Private in the 2.0 line and above and may be
|
||||
* changed to private or removed in 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@InterfaceAudience.Private
|
||||
public TimeRange() {
|
||||
this(INITIAL_MIN_TIMESTAMP, INITIAL_MAX_TIMESTAMP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents interval [minStamp, Long.MAX_VALUE)
|
||||
* @param minStamp the minimum timestamp value, inclusive
|
||||
* @deprecated This is made @InterfaceAudience.Private in the 2.0 line and above and may be
|
||||
* changed to private or removed in 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@InterfaceAudience.Private
|
||||
public TimeRange(long minStamp) {
|
||||
this(minStamp, INITIAL_MAX_TIMESTAMP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents interval [minStamp, Long.MAX_VALUE)
|
||||
* @param minStamp the minimum timestamp value, inclusive
|
||||
* @deprecated This is made @InterfaceAudience.Private in the 2.0 line and above and may be
|
||||
* changed to private or removed in 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@InterfaceAudience.Private
|
||||
public TimeRange(byte [] minStamp) {
|
||||
this(Bytes.toLong(minStamp));
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents interval [minStamp, maxStamp)
|
||||
* @param minStamp the minimum timestamp, inclusive
|
||||
* @param maxStamp the maximum timestamp, exclusive
|
||||
* @deprecated This is made @InterfaceAudience.Private in the 2.0 line and above and may be
|
||||
* changed to private or removed in 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@InterfaceAudience.Private
|
||||
public TimeRange(byte [] minStamp, byte [] maxStamp) {
|
||||
this(Bytes.toLong(minStamp), Bytes.toLong(maxStamp));
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents interval [minStamp, maxStamp)
|
||||
* @param minStamp the minimum timestamp, inclusive
|
||||
* @param maxStamp the maximum timestamp, exclusive
|
||||
* @throws IllegalArgumentException if either <0,
|
||||
* @deprecated This is made @InterfaceAudience.Private in the 2.0 line and above and may be
|
||||
* changed to private or removed in 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@InterfaceAudience.Private
|
||||
public TimeRange(long minStamp, long maxStamp) {
|
||||
check(minStamp, maxStamp);
|
||||
private TimeRange(long minStamp, long maxStamp) {
|
||||
this.minStamp = minStamp;
|
||||
this.maxStamp = maxStamp;
|
||||
this.allTime = isAllTime(minStamp, maxStamp);
|
||||
|
@ -188,27 +133,8 @@ public class TimeRange {
|
|||
|
||||
/**
|
||||
* Check if the specified timestamp is within this TimeRange.
|
||||
* <p>
|
||||
* <p/>
|
||||
* Returns true if within interval [minStamp, maxStamp), false if not.
|
||||
* @param bytes timestamp to check
|
||||
* @param offset offset into the bytes
|
||||
* @return true if within TimeRange, false if not
|
||||
* @deprecated This is made @InterfaceAudience.Private in the 2.0 line and above and may be
|
||||
* changed to private or removed in 3.0. Use {@link #withinTimeRange(long)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean withinTimeRange(byte [] bytes, int offset) {
|
||||
if (allTime) {
|
||||
return true;
|
||||
}
|
||||
return withinTimeRange(Bytes.toLong(bytes, offset));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the specified timestamp is within this TimeRange.
|
||||
* <p>
|
||||
* Returns true if within interval [minStamp, maxStamp), false
|
||||
* if not.
|
||||
* @param timestamp timestamp to check
|
||||
* @return true if within TimeRange, false if not
|
||||
*/
|
||||
|
|
|
@ -240,7 +240,7 @@ public abstract class TimeRangeTracker {
|
|||
if (max == INITIAL_MAX_TIMESTAMP) {
|
||||
max = TimeRange.INITIAL_MAX_TIMESTAMP;
|
||||
}
|
||||
return new TimeRange(min, max);
|
||||
return TimeRange.between(min, max);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
|
|
@ -128,15 +128,15 @@ public class TestAppendTimeRange {
|
|||
|
||||
time = EnvironmentEdgeManager.currentTime();
|
||||
mee.setValue(time);
|
||||
TimeRange range10 = new TimeRange(1, time + 10);
|
||||
Result r = table.append(new Append(ROW).addColumn(TEST_FAMILY, QUAL, Bytes.toBytes("b"))
|
||||
.setTimeRange(range10.getMin(), range10.getMax()));
|
||||
TimeRange range10 = TimeRange.between(1, time + 10);
|
||||
table.append(new Append(ROW).addColumn(TEST_FAMILY, QUAL, Bytes.toBytes("b"))
|
||||
.setTimeRange(range10.getMin(), range10.getMax()));
|
||||
checkRowValue(table, ROW, Bytes.toBytes("ab"));
|
||||
assertEquals(MyObserver.tr10.getMin(), range10.getMin());
|
||||
assertEquals(MyObserver.tr10.getMax(), range10.getMax());
|
||||
time = EnvironmentEdgeManager.currentTime();
|
||||
mee.setValue(time);
|
||||
TimeRange range2 = new TimeRange(1, time+20);
|
||||
TimeRange range2 = TimeRange.between(1, time + 20);
|
||||
List<Row> actions =
|
||||
Arrays.asList(new Row[] {
|
||||
new Append(ROW).addColumn(TEST_FAMILY, QUAL, Bytes.toBytes("c"))
|
||||
|
|
|
@ -165,7 +165,7 @@ public class TestIncrementTimeRange {
|
|||
|
||||
time = EnvironmentEdgeManager.currentTime();
|
||||
mee.setValue(time);
|
||||
TimeRange range10 = new TimeRange(1, time+10);
|
||||
TimeRange range10 = TimeRange.between(1, time+10);
|
||||
hTableInterface.increment(new Increment(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, 10L)
|
||||
.setTimeRange(range10.getMin(), range10.getMax()));
|
||||
checkRowValue(ROW_A, Bytes.toBytes(11L));
|
||||
|
@ -174,7 +174,7 @@ public class TestIncrementTimeRange {
|
|||
|
||||
time = EnvironmentEdgeManager.currentTime();
|
||||
mee.setValue(time);
|
||||
TimeRange range2 = new TimeRange(1, time+20);
|
||||
TimeRange range2 = TimeRange.between(1, time + 20);
|
||||
List<Row> actions =
|
||||
Arrays.asList(new Row[] { new Increment(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, 2L)
|
||||
.setTimeRange(range2.getMin(), range2.getMax()),
|
||||
|
|
|
@ -61,7 +61,7 @@ public class TestSimpleTimeRangeTracker {
|
|||
@Test
|
||||
public void testTimeRangeInitialized() {
|
||||
TimeRangeTracker src = getTimeRangeTracker();
|
||||
TimeRange tr = new TimeRange(System.currentTimeMillis());
|
||||
TimeRange tr = TimeRange.from(System.currentTimeMillis());
|
||||
assertFalse(src.includesTimeRange(tr));
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ public class TestSimpleTimeRangeTracker {
|
|||
TimeRangeTracker trr = getTimeRangeTracker();
|
||||
trr.includeTimestamp(0);
|
||||
trr.includeTimestamp(2);
|
||||
assertTrue(trr.includesTimeRange(new TimeRange(1)));
|
||||
assertTrue(trr.includesTimeRange(TimeRange.from(1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -118,27 +118,27 @@ public class TestSimpleTimeRangeTracker {
|
|||
assertEquals(Long.MAX_VALUE, defaultRange.getMax());
|
||||
assertTrue(defaultRange.isAllTime());
|
||||
|
||||
TimeRange oneArgRange = new TimeRange(0L);
|
||||
TimeRange oneArgRange = TimeRange.from(0L);
|
||||
assertEquals(0L, oneArgRange.getMin());
|
||||
assertEquals(Long.MAX_VALUE, oneArgRange.getMax());
|
||||
assertTrue(oneArgRange.isAllTime());
|
||||
|
||||
TimeRange oneArgRange2 = new TimeRange(1);
|
||||
TimeRange oneArgRange2 = TimeRange.from(1);
|
||||
assertEquals(1, oneArgRange2.getMin());
|
||||
assertEquals(Long.MAX_VALUE, oneArgRange2.getMax());
|
||||
assertFalse(oneArgRange2.isAllTime());
|
||||
|
||||
TimeRange twoArgRange = new TimeRange(0L, Long.MAX_VALUE);
|
||||
TimeRange twoArgRange = TimeRange.between(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);
|
||||
TimeRange twoArgRange2 = TimeRange.between(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);
|
||||
TimeRange twoArgRange3 = TimeRange.between(1, Long.MAX_VALUE);
|
||||
assertEquals(1, twoArgRange3.getMin());
|
||||
assertEquals(Long.MAX_VALUE, twoArgRange3.getMax());
|
||||
assertFalse(twoArgRange3.isAllTime());
|
||||
|
|
Loading…
Reference in New Issue