From 64bedbf281ea56b316d2af5ff94820836a6014fb Mon Sep 17 00:00:00 2001 From: Phil Yang Date: Thu, 25 May 2017 19:00:12 +0800 Subject: [PATCH] HBASE-18113 Handle old client without include_stop_row flag when startRow equals endRow --- .../org/apache/hadoop/hbase/client/ClientUtil.java | 30 ++++++++++++++++++++++ .../java/org/apache/hadoop/hbase/client/Scan.java | 11 +++----- .../hadoop/hbase/shaded/protobuf/ProtobufUtil.java | 6 +++++ 3 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 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 0000000000..e4a84d5c53 --- /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; + +@InterfaceAudience.Private +public class ClientUtil { + + + public static boolean areScanStartRowAndStopRowEqual(byte[] startRow, byte[] stopRow) { + return startRow != null && startRow.length > 0 && Bytes.equals(startRow, stopRow); + } +} 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 7bc78d45dc..2746263b65 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 @@ -305,11 +305,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); } /** @@ -418,7 +415,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; } @@ -478,7 +475,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; } diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java index 108646aeae..a002f74c64 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java @@ -62,6 +62,7 @@ import org.apache.hadoop.hbase.Tag; import org.apache.hadoop.hbase.TagUtil; 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.CompactionState; import org.apache.hadoop.hbase.client.Consistency; import org.apache.hadoop.hbase.client.Delete; @@ -1124,6 +1125,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); -- 2.11.0 (Apple Git-81)