HBASE-1350 New method in HTable.java to return start and end keys for regions in a table

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@769286 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2009-04-28 08:27:26 +00:00
parent 40245ba36e
commit 9edef7b6fa
2 changed files with 30 additions and 3 deletions

View File

@ -170,6 +170,8 @@ Release 0.20.0 - Unreleased
provide additional ByteBuffer primitives (Jon Gray via Stack)
HBASE-1183 New MR splitting algorithm and other new features need a way to
split a key range in N chunks (Jon Gray via Stack)
HBASE-1350 New method in HTable.java to return start and end keys for
regions in a table (Vimal Mathew via Stack)
Release 0.19.0 - 01/21/2009
INCOMPATIBLE CHANGES

View File

@ -47,6 +47,7 @@ import org.apache.hadoop.hbase.io.Cell;
import org.apache.hadoop.hbase.io.RowResult;
import org.apache.hadoop.hbase.io.HbaseMapWritable;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.hbase.util.Writables;
/**
@ -227,21 +228,45 @@ public class HTable {
* @throws IOException
*/
public byte [][] getStartKeys() throws IOException {
final List<byte[]> keyList = new ArrayList<byte[]>();
return getStartEndKeys().getFirst();
}
/**
* Gets the ending row key for every region in the currently open table
*
* @return Array of region ending row keys
* @throws IOException
*/
public byte[][] getEndKeys() throws IOException {
return getStartEndKeys().getSecond();
}
/**
* Gets the starting and ending row keys for every region in the currently open table
*
* @return Pair of arrays of region starting and ending row keys
* @throws IOException
*/
@SuppressWarnings("unchecked")
public Pair<byte[][],byte[][]> getStartEndKeys() throws IOException {
final List<byte[]> startKeyList = new ArrayList<byte[]>();
final List<byte[]> endKeyList = new ArrayList<byte[]>();
MetaScannerVisitor visitor = new MetaScannerVisitor() {
public boolean processRow(RowResult rowResult) throws IOException {
HRegionInfo info = Writables.getHRegionInfo(
rowResult.get(HConstants.COL_REGIONINFO));
if (Bytes.equals(info.getTableDesc().getName(), getTableName())) {
if (!(info.isOffline() || info.isSplit())) {
keyList.add(info.getStartKey());
startKeyList.add(info.getStartKey());
endKeyList.add(info.getEndKey());
}
}
return true;
}
};
MetaScanner.metaScan(configuration, visitor, this.tableName);
return keyList.toArray(new byte[keyList.size()][]);
return new Pair(startKeyList.toArray(new byte[startKeyList.size()][]),
endKeyList.toArray(new byte[endKeyList.size()][]));
}
/**