### Eclipse Workspace Patch 1.0
#P apache-trunk
Index: hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java
===================================================================
--- hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java (revision 1465316)
+++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java (working copy)
@@ -18,8 +18,25 @@
*/
package org.apache.hadoop.hbase.client;
-import com.google.protobuf.Service;
-import com.google.protobuf.ServiceException;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.NavigableMap;
+import java.util.TreeMap;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.classification.InterfaceAudience;
@@ -54,23 +71,8 @@
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.hbase.util.Threads;
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.InterruptedIOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.NavigableMap;
-import java.util.TreeMap;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-import java.util.concurrent.SynchronousQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
+import com.google.protobuf.Service;
+import com.google.protobuf.ServiceException;
/**
*
Used to communicate with a single HBase table.
@@ -488,22 +490,41 @@
*/
public List getRegionsInRange(final byte [] startKey,
final byte [] endKey) throws IOException {
- final boolean endKeyIsEndOfTable = Bytes.equals(endKey,
- HConstants.EMPTY_END_ROW);
+ return new ArrayList(getKeysToRegionsInRange(startKey,
+ endKey, false).values());
+ }
+
+ /**
+ * Get the corresponding start keys to regions map for an arbitrary range of
+ * keys.
+ *
+ * @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 map of start keys to HRegionLocations that contain the specified
+ * range
+ * @throws IOException if a remote or network exception occurs
+ */
+ public LinkedHashMap getKeysToRegionsInRange(
+ 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) {
throw new IllegalArgumentException(
"Invalid range: " + Bytes.toStringBinary(startKey) +
" > " + Bytes.toStringBinary(endKey));
}
- final List regionList = new ArrayList();
- byte [] currentKey = startKey;
+ final LinkedHashMap startKeysToRegionMap =
+ new LinkedHashMap();
+ byte[] currentKey = startKey;
do {
HRegionLocation regionLocation = getRegionLocation(currentKey, false);
- regionList.add(regionLocation);
+ startKeysToRegionMap.put(currentKey, regionLocation);
currentKey = regionLocation.getRegionInfo().getEndKey();
- } while (!Bytes.equals(currentKey, HConstants.EMPTY_END_ROW) &&
- (endKeyIsEndOfTable || Bytes.compareTo(currentKey, endKey) < 0));
- return regionList;
+ } while (!Bytes.equals(currentKey, HConstants.EMPTY_END_ROW)
+ && (endKeyIsEndOfTable || Bytes.compareTo(currentKey, endKey) < 0
+ || (includeEndKey && Bytes.compareTo(currentKey, endKey) == 0)));
+ return startKeysToRegionMap;
}
/**
@@ -1330,7 +1351,7 @@
final Batch.Callback callback) throws ServiceException, Throwable {
// get regions covered by the row range
- List keys = getStartKeysInRange(startKey, endKey);
+ List keys = getStartKeysInRange(startKey, endKey, true);
Map> futures =
new TreeMap>(Bytes.BYTES_COMPARATOR);
@@ -1367,35 +1388,40 @@
}
}
- private List getStartKeysInRange(byte[] start, byte[] end)
+ private List getStartKeysInRange(byte[] start, byte[] end,
+ boolean useCache)
throws IOException {
- Pair startEndKeys = getStartEndKeys();
- byte[][] startKeys = startEndKeys.getFirst();
- byte[][] endKeys = startEndKeys.getSecond();
-
if (start == null) {
start = HConstants.EMPTY_START_ROW;
}
if (end == null) {
end = HConstants.EMPTY_END_ROW;
}
+ if (useCache) {
+ return new ArrayList(getKeysToRegionsInRange(start, end, true)
+ .keySet());
+ } else {
+ Pair startEndKeys = getStartEndKeys();
+ byte[][] startKeys = startEndKeys.getFirst();
+ byte[][] endKeys = startEndKeys.getSecond();
- List rangeKeys = new ArrayList();
- for (int i=0; i= 0 ) {
- if (Bytes.equals(endKeys[i], HConstants.EMPTY_END_ROW) ||
- Bytes.compareTo(start, endKeys[i]) < 0) {
- rangeKeys.add(start);
+ List rangeKeys = new ArrayList();
+ 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
}
- } 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;
}
-
- return rangeKeys;
}
public void setOperationTimeout(int operationTimeout) {