HBASE-18113 Handle old client without include_stop_row flag when startRow equals endRow

This commit is contained in:
Phil Yang 2017-05-25 19:00:12 +08:00
parent f441ca0458
commit b74474dfc9
3 changed files with 40 additions and 7 deletions

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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);