Repository: hbase Updated Branches: refs/heads/branch-1 109e0d548 -> d5838c78f
HBASE-18113 Handle old client without include_stop_row flag when startRow equals endRow Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/d5838c78 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/d5838c78 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/d5838c78 Branch: refs/heads/branch-1 Commit: d5838c78fc6c875152d755990b5a4192c75dea18 Parents: 109e0d5 Author: Phil Yang <[email protected]> Authored: Fri May 26 13:50:24 2017 +0800 Committer: Phil Yang <[email protected]> Committed: Fri May 26 13:51:17 2017 +0800 ---------------------------------------------------------------------- .../apache/hadoop/hbase/client/ClientUtil.java | 30 ++++++++++++++++++++ .../org/apache/hadoop/hbase/client/Scan.java | 11 +++---- .../hadoop/hbase/protobuf/ProtobufUtil.java | 6 ++++ 3 files changed, 40 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/d5838c78/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientUtil.java ---------------------------------------------------------------------- diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientUtil.java new file mode 100644 index 0000000..e4a84d5 --- /dev/null +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientUtil.java @@ -0,0 +1,30 @@ +/** + * 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.client; + +import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.hbase.util.Bytes; + [email protected] +public class ClientUtil { + + + public static boolean areScanStartRowAndStopRowEqual(byte[] startRow, byte[] stopRow) { + return startRow != null && startRow.length > 0 && Bytes.equals(startRow, stopRow); + } +} http://git-wip-us.apache.org/repos/asf/hbase/blob/d5838c78/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 26076f5..64a5787 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 @@ -307,11 +307,8 @@ public class Scan extends Query { } public boolean isGetScan() { - return includeStartRow && includeStopRow && areStartRowAndStopRowEqual(startRow, stopRow); - } - - private static boolean areStartRowAndStopRowEqual(byte[] startRow, byte[] stopRow) { - return startRow != null && startRow.length > 0 && Bytes.equals(startRow, stopRow); + return includeStartRow && includeStopRow + && ClientUtil.areScanStartRowAndStopRowEqual(this.startRow, this.stopRow); } /** @@ -406,7 +403,7 @@ public class Scan extends Query { @Deprecated public Scan setStartRow(byte[] startRow) { withStartRow(startRow); - if (areStartRowAndStopRowEqual(startRow, stopRow)) { + if (ClientUtil.areScanStartRowAndStopRowEqual(this.startRow, this.stopRow)) { // for keeping the old behavior that a scan with the same start and stop row is a get scan. this.includeStopRow = true; } @@ -466,7 +463,7 @@ public class Scan extends Query { @Deprecated public Scan setStopRow(byte[] stopRow) { withStopRow(stopRow); - if (areStartRowAndStopRowEqual(startRow, stopRow)) { + if (ClientUtil.areScanStartRowAndStopRowEqual(this.startRow, this.stopRow)) { // for keeping the old behavior that a scan with the same start and stop row is a get scan. this.includeStopRow = true; } http://git-wip-us.apache.org/repos/asf/hbase/blob/d5838c78/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java ---------------------------------------------------------------------- diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java index 99a0913..b561cfd 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java @@ -73,6 +73,7 @@ import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.Tag; import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.client.Append; +import org.apache.hadoop.hbase.client.ClientUtil; import org.apache.hadoop.hbase.client.Consistency; import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.Durability; @@ -1084,6 +1085,11 @@ public final class ProtobufUtil { } if (proto.hasIncludeStopRow()) { includeStopRow = proto.getIncludeStopRow(); + } else { + // old client without this flag, we should consider start=end as a get. + if (ClientUtil.areScanStartRowAndStopRowEqual(startRow, stopRow)) { + includeStopRow = true; + } } Scan scan = new Scan().withStartRow(startRow, includeStartRow).withStopRow(stopRow, includeStopRow);
