HBASE-6870 HTable#coprocessorExec always scan the whole table
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1470376 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
af33aeefe5
commit
87023082bd
|
@ -488,22 +488,42 @@ public class HTable implements HTableInterface {
|
||||||
*/
|
*/
|
||||||
public List<HRegionLocation> getRegionsInRange(final byte [] startKey,
|
public List<HRegionLocation> getRegionsInRange(final byte [] startKey,
|
||||||
final byte [] endKey) throws IOException {
|
final byte [] endKey) throws IOException {
|
||||||
final boolean endKeyIsEndOfTable = Bytes.equals(endKey,
|
return getKeysAndRegionsInRange(startKey, endKey, false).getSecond();
|
||||||
HConstants.EMPTY_END_ROW);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the corresponding start keys and regions for an arbitrary range of
|
||||||
|
* keys.
|
||||||
|
* <p>
|
||||||
|
* @param startKey Starting row in range, inclusive
|
||||||
|
* @param endKey Ending row in range
|
||||||
|
* @param includeEndKey true if endRow is inclusive, false if exclusive
|
||||||
|
* @return A pair of list of start keys and list of HRegionLocations that
|
||||||
|
* contain the specified range
|
||||||
|
* @throws IOException if a remote or network exception occurs
|
||||||
|
*/
|
||||||
|
private Pair<List<byte[]>, List<HRegionLocation>> getKeysAndRegionsInRange(
|
||||||
|
final byte[] startKey, final byte[] endKey, final boolean includeEndKey)
|
||||||
|
throws IOException {
|
||||||
|
final boolean endKeyIsEndOfTable = Bytes.equals(endKey,HConstants.EMPTY_END_ROW);
|
||||||
if ((Bytes.compareTo(startKey, endKey) > 0) && !endKeyIsEndOfTable) {
|
if ((Bytes.compareTo(startKey, endKey) > 0) && !endKeyIsEndOfTable) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Invalid range: " + Bytes.toStringBinary(startKey) +
|
"Invalid range: " + Bytes.toStringBinary(startKey) +
|
||||||
" > " + Bytes.toStringBinary(endKey));
|
" > " + Bytes.toStringBinary(endKey));
|
||||||
}
|
}
|
||||||
final List<HRegionLocation> regionList = new ArrayList<HRegionLocation>();
|
List<byte[]> keysInRange = new ArrayList<byte[]>();
|
||||||
byte [] currentKey = startKey;
|
List<HRegionLocation> regionsInRange = new ArrayList<HRegionLocation>();
|
||||||
|
byte[] currentKey = startKey;
|
||||||
do {
|
do {
|
||||||
HRegionLocation regionLocation = getRegionLocation(currentKey, false);
|
HRegionLocation regionLocation = getRegionLocation(currentKey, false);
|
||||||
regionList.add(regionLocation);
|
keysInRange.add(currentKey);
|
||||||
|
regionsInRange.add(regionLocation);
|
||||||
currentKey = regionLocation.getRegionInfo().getEndKey();
|
currentKey = regionLocation.getRegionInfo().getEndKey();
|
||||||
} while (!Bytes.equals(currentKey, HConstants.EMPTY_END_ROW) &&
|
} while (!Bytes.equals(currentKey, HConstants.EMPTY_END_ROW)
|
||||||
(endKeyIsEndOfTable || Bytes.compareTo(currentKey, endKey) < 0));
|
&& (endKeyIsEndOfTable || Bytes.compareTo(currentKey, endKey) < 0
|
||||||
return regionList;
|
|| (includeEndKey && Bytes.compareTo(currentKey, endKey) == 0)));
|
||||||
|
return new Pair<List<byte[]>, List<HRegionLocation>>(keysInRange,
|
||||||
|
regionsInRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1369,33 +1389,13 @@ public class HTable implements HTableInterface {
|
||||||
|
|
||||||
private List<byte[]> getStartKeysInRange(byte[] start, byte[] end)
|
private List<byte[]> getStartKeysInRange(byte[] start, byte[] end)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Pair<byte[][],byte[][]> startEndKeys = getStartEndKeys();
|
|
||||||
byte[][] startKeys = startEndKeys.getFirst();
|
|
||||||
byte[][] endKeys = startEndKeys.getSecond();
|
|
||||||
|
|
||||||
if (start == null) {
|
if (start == null) {
|
||||||
start = HConstants.EMPTY_START_ROW;
|
start = HConstants.EMPTY_START_ROW;
|
||||||
}
|
}
|
||||||
if (end == null) {
|
if (end == null) {
|
||||||
end = HConstants.EMPTY_END_ROW;
|
end = HConstants.EMPTY_END_ROW;
|
||||||
}
|
}
|
||||||
|
return getKeysAndRegionsInRange(start, end, true).getFirst();
|
||||||
List<byte[]> rangeKeys = new ArrayList<byte[]>();
|
|
||||||
for (int i=0; i<startKeys.length; i++) {
|
|
||||||
if (Bytes.compareTo(start, startKeys[i]) >= 0 ) {
|
|
||||||
if (Bytes.equals(endKeys[i], HConstants.EMPTY_END_ROW) ||
|
|
||||||
Bytes.compareTo(start, endKeys[i]) < 0) {
|
|
||||||
rangeKeys.add(start);
|
|
||||||
}
|
|
||||||
} else if (Bytes.equals(end, HConstants.EMPTY_END_ROW) ||
|
|
||||||
Bytes.compareTo(startKeys[i], end) <= 0) {
|
|
||||||
rangeKeys.add(startKeys[i]);
|
|
||||||
} else {
|
|
||||||
break; // past stop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return rangeKeys;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOperationTimeout(int operationTimeout) {
|
public void setOperationTimeout(int operationTimeout) {
|
||||||
|
|
Loading…
Reference in New Issue