You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by op...@apache.org on 2019/08/17 02:11:59 UTC
[hbase] branch branch-2.0 updated: HBASE-22841 Add more factory
functions to TimeRange
This is an automated email from the ASF dual-hosted git repository.
openinx pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new 288fdb9 HBASE-22841 Add more factory functions to TimeRange
288fdb9 is described below
commit 288fdb9a2794e5030568152b260cccaa2c332beb
Author: Huon Wilson <Hu...@data61.csiro.au>
AuthorDate: Tue Aug 13 15:03:56 2019 +1000
HBASE-22841 Add more factory functions to TimeRange
These functions make it easier to possible to use
`org.apache.hadoop.hbase.client.Table.CheckAndMutateBuilder#timeRange`
with more interesting ranges, without being forced to use the
deprecated constructors.
Signed-off-by: huzheng <op...@gmail.com>
---
.../java/org/apache/hadoop/hbase/io/TimeRange.java | 39 +++++-
.../hadoop/hbase/client/TestFromClientSide.java | 137 +++++++++++++--------
2 files changed, 121 insertions(+), 55 deletions(-)
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 c44ab69..fe229b6 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
@@ -26,12 +26,13 @@ import org.apache.yetus.audience.InterfaceAudience;
* {@link #INITIAL_MIN_TIMESTAMP} and {@link #INITIAL_MAX_TIMESTAMP} only. Gets freaked out if
* passed a timestamp that is < {@link #INITIAL_MIN_TIMESTAMP},
* <p>
- * Evaluated according to minStamp <= timestamp < maxStamp
- * or [minStamp,maxStamp) in interval notation.
+ * Evaluated according to minStamp <= timestamp < maxStamp or [minStamp,maxStamp) in interval
+ * notation.
* <p>
- * Can be returned and read by clients. Should not be directly created by clients.
- * Thus, all constructors are purposely @InterfaceAudience.Private.
- *<p>Immutable. Thread-safe.
+ * Can be returned and read by clients. Should not be directly created by clients. Thus, all
+ * constructors are purposely @InterfaceAudience.Private.
+ * <p>
+ * Immutable. Thread-safe.
*/
@InterfaceAudience.Public
public class TimeRange {
@@ -51,6 +52,34 @@ public class TimeRange {
return new TimeRange(ts, ts + 1);
}
+ /**
+ * Represents the time interval [minStamp, Long.MAX_VALUE)
+ * @param minStamp the minimum timestamp value, inclusive
+ */
+ public static TimeRange from(long minStamp) {
+ check(minStamp, INITIAL_MAX_TIMESTAMP);
+ return new TimeRange(minStamp, INITIAL_MAX_TIMESTAMP);
+ }
+
+ /**
+ * Represents the time interval [0, maxStamp)
+ * @param maxStamp the minimum timestamp value, exclusive
+ */
+ public static TimeRange until(long maxStamp) {
+ check(INITIAL_MIN_TIMESTAMP, maxStamp);
+ return new TimeRange(INITIAL_MIN_TIMESTAMP, maxStamp);
+ }
+
+ /**
+ * Represents the time interval [minStamp, maxStamp)
+ * @param minStamp the minimum timestamp, inclusive
+ * @param maxStamp the maximum timestamp, exclusive
+ */
+ public static TimeRange between(long minStamp, long maxStamp) {
+ check(minStamp, maxStamp);
+ return new TimeRange(minStamp, maxStamp);
+ }
+
private final long minStamp;
private final long maxStamp;
private final boolean allTime;
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
index 87ef8da..4ed6d71 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
@@ -4835,56 +4835,93 @@ public class TestFromClientSide {
@Test
public void testCheckAndMutateWithTimeRange() throws IOException {
- Table table = TEST_UTIL.createTable(TableName.valueOf(name.getMethodName()), FAMILY);
- final long ts = System.currentTimeMillis() / 2;
- Put put = new Put(ROW);
- put.addColumn(FAMILY, QUALIFIER, ts, VALUE);
-
- boolean ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
- .ifNotExists()
- .thenPut(put);
- assertTrue(ok);
-
- ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
- .timeRange(TimeRange.at(ts + 10000))
- .ifEquals(VALUE)
- .thenPut(put);
- assertFalse(ok);
-
- ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
- .timeRange(TimeRange.at(ts))
- .ifEquals(VALUE)
- .thenPut(put);
- assertTrue(ok);
-
- RowMutations rm = new RowMutations(ROW)
- .add((Mutation) put);
- ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
- .timeRange(TimeRange.at(ts + 10000))
- .ifEquals(VALUE)
- .thenMutate(rm);
- assertFalse(ok);
-
- ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
- .timeRange(TimeRange.at(ts))
- .ifEquals(VALUE)
- .thenMutate(rm);
- assertTrue(ok);
-
- Delete delete = new Delete(ROW)
- .addColumn(FAMILY, QUALIFIER);
-
- ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
- .timeRange(TimeRange.at(ts + 10000))
- .ifEquals(VALUE)
- .thenDelete(delete);
- assertFalse(ok);
+ try (Table table = TEST_UTIL.createTable(TableName.valueOf(name.getMethodName()), FAMILY)) {
+ final long ts = System.currentTimeMillis() / 2;
+ Put put = new Put(ROW);
+ put.addColumn(FAMILY, QUALIFIER, ts, VALUE);
- ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
- .timeRange(TimeRange.at(ts))
- .ifEquals(VALUE)
- .thenDelete(delete);
- assertTrue(ok);
+ boolean ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
+ .ifNotExists()
+ .thenPut(put);
+ assertTrue(ok);
+
+ ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
+ .timeRange(TimeRange.at(ts + 10000))
+ .ifEquals(VALUE)
+ .thenPut(put);
+ assertFalse(ok);
+
+ ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
+ .timeRange(TimeRange.from(ts + 10000))
+ .ifEquals(VALUE)
+ .thenPut(put);
+ assertFalse(ok);
+
+ ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
+ .timeRange(TimeRange.between(ts + 10000, ts + 20000))
+ .ifEquals(VALUE)
+ .thenPut(put);
+ assertFalse(ok);
+
+ ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
+ .timeRange(TimeRange.until(ts))
+ .ifEquals(VALUE)
+ .thenPut(put);
+ assertFalse(ok);
+
+ ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
+ .timeRange(TimeRange.at(ts))
+ .ifEquals(VALUE)
+ .thenPut(put);
+ assertTrue(ok);
+
+ ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
+ .timeRange(TimeRange.from(ts))
+ .ifEquals(VALUE)
+ .thenPut(put);
+ assertTrue(ok);
+
+ ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
+ .timeRange(TimeRange.between(ts, ts + 20000))
+ .ifEquals(VALUE)
+ .thenPut(put);
+ assertTrue(ok);
+
+ ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
+ .timeRange(TimeRange.until(ts + 10000))
+ .ifEquals(VALUE)
+ .thenPut(put);
+ assertTrue(ok);
+
+ RowMutations rm = new RowMutations(ROW)
+ .add((Mutation) put);
+ ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
+ .timeRange(TimeRange.at(ts + 10000))
+ .ifEquals(VALUE)
+ .thenMutate(rm);
+ assertFalse(ok);
+
+ ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
+ .timeRange(TimeRange.at(ts))
+ .ifEquals(VALUE)
+ .thenMutate(rm);
+ assertTrue(ok);
+
+ Delete delete = new Delete(ROW)
+ .addColumn(FAMILY, QUALIFIER);
+
+ ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
+ .timeRange(TimeRange.at(ts + 10000))
+ .ifEquals(VALUE)
+ .thenDelete(delete);
+ assertFalse(ok);
+
+ ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
+ .timeRange(TimeRange.at(ts))
+ .ifEquals(VALUE)
+ .thenDelete(delete);
+ assertTrue(ok);
+ }
}
@Test
@@ -6735,4 +6772,4 @@ public class TestFromClientSide {
TEST_UTIL.getAdmin().modifyTable(newDesc);
}
-}
\ No newline at end of file
+}