You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ga...@apache.org on 2016/09/13 00:39:37 UTC
hbase git commit: HBASE-16540 Adding checks in Scanner's setStartRow
and setStopRow for invalid row key sizes.
Repository: hbase
Updated Branches:
refs/heads/branch-1 8ad14bac6 -> 7028a0d88
HBASE-16540 Adding checks in Scanner's setStartRow and setStopRow for invalid row key sizes.
Signed-off-by: Gary Helmling <ga...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/7028a0d8
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/7028a0d8
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/7028a0d8
Branch: refs/heads/branch-1
Commit: 7028a0d889b3649e5a0c4bd9532b852fb70d3ae3
Parents: 8ad14ba
Author: Dustin Pho <ph...@fb.com>
Authored: Mon Sep 12 13:25:02 2016 -0700
Committer: Gary Helmling <ga...@apache.org>
Committed: Mon Sep 12 17:38:15 2016 -0700
----------------------------------------------------------------------
.../org/apache/hadoop/hbase/client/Scan.java | 16 +++++++++++
.../apache/hadoop/hbase/client/TestScan.java | 29 +++++++++++++++++++-
2 files changed, 44 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/7028a0d8/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Scan.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Scan.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Scan.java
index 1d9b130..a518ffb 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Scan.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Scan.java
@@ -362,8 +362,16 @@ public class Scan extends Query {
* @param startRow row to start scan on (inclusive)
* Note: In order to make startRow exclusive add a trailing 0 byte
* @return this
+ * @throws IllegalArgumentException if startRow does not meet criteria
+ * for a row key (when length exceeds {@link HConstants#MAX_ROW_LENGTH})
*/
public Scan setStartRow(byte [] startRow) {
+ if (Bytes.len(startRow) > HConstants.MAX_ROW_LENGTH) {
+ throw new IllegalArgumentException(
+ "startRow's length must be less than or equal to " +
+ HConstants.MAX_ROW_LENGTH + " to meet the criteria" +
+ " for a row key.");
+ }
this.startRow = startRow;
return this;
}
@@ -376,8 +384,16 @@ public class Scan extends Query {
* use {@link #setRowPrefixFilter(byte[])}.
* The 'trailing 0' will not yield the desired result.</p>
* @return this
+ * @throws IllegalArgumentException if stopRow does not meet criteria
+ * for a row key (when length exceeds {@link HConstants#MAX_ROW_LENGTH})
*/
public Scan setStopRow(byte [] stopRow) {
+ if (Bytes.len(stopRow) > HConstants.MAX_ROW_LENGTH) {
+ throw new IllegalArgumentException(
+ "stopRow's length must be less than or equal to " +
+ HConstants.MAX_ROW_LENGTH + " to meet the criteria" +
+ " for a row key.");
+ }
this.stopRow = stopRow;
return this;
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/7028a0d8/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestScan.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestScan.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestScan.java
index d843723..5f771cd 100644
--- a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestScan.java
+++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestScan.java
@@ -25,10 +25,11 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.Set;
-import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.protobuf.generated.ClientProtos;
import org.apache.hadoop.hbase.security.visibility.Authorizations;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Assert;
import org.junit.Test;
@@ -131,5 +132,31 @@ public class TestScan {
fail("should not throw exception");
}
}
+
+ @Test
+ public void testSetStartRowAndSetStopRow() {
+ Scan scan = new Scan();
+ scan.setStartRow(null);
+ scan.setStartRow(new byte[1]);
+ scan.setStartRow(new byte[HConstants.MAX_ROW_LENGTH]);
+ try {
+ scan.setStartRow(new byte[HConstants.MAX_ROW_LENGTH+1]);
+ fail("should've thrown exception");
+ } catch (IllegalArgumentException iae) {
+ } catch (Exception e) {
+ fail("expected IllegalArgumentException to be thrown");
+ }
+
+ scan.setStopRow(null);
+ scan.setStopRow(new byte[1]);
+ scan.setStopRow(new byte[HConstants.MAX_ROW_LENGTH]);
+ try {
+ scan.setStopRow(new byte[HConstants.MAX_ROW_LENGTH+1]);
+ fail("should've thrown exception");
+ } catch (IllegalArgumentException iae) {
+ } catch (Exception e) {
+ fail("expected IllegalArgumentException to be thrown");
+ }
+ }
}