You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ap...@apache.org on 2009/02/05 06:52:26 UTC
svn commit: r741018 - in /hadoop/hbase/trunk: CHANGES.txt
src/java/org/apache/hadoop/hbase/HRegionInfo.java
src/java/org/apache/hadoop/hbase/master/HMaster.java
Author: apurtell
Date: Thu Feb 5 05:52:26 2009
New Revision: 741018
URL: http://svn.apache.org/viewvc?rev=741018&view=rev
Log:
HBASE-1175 HBA administrative tools do not work when specifying region name
Modified:
hadoop/hbase/trunk/CHANGES.txt
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HRegionInfo.java
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/master/HMaster.java
Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=741018&r1=741017&r2=741018&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Thu Feb 5 05:52:26 2009
@@ -17,6 +17,8 @@
HBASE-1148 Always flush HLog on root or meta region updates
HBASE-1181 src/saveVersion.sh bails on non-standard Bourne shells (e.g. dash)
(K M via Jean-Daniel Cryans)
+ HBASE-1175 HBA administrative tools do not work when specifying region
+ name (Jonathan Gray via Andrew Purtell)
IMPROVEMENTS
HBASE-1089 Add count of regions on filesystem to master UI; add percentage
Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HRegionInfo.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HRegionInfo.java?rev=741018&r1=741017&r2=741018&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HRegionInfo.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HRegionInfo.java Thu Feb 5 05:52:26 2009
@@ -217,6 +217,47 @@
return b;
}
+ /**
+ * Separate elements of a regionName.
+ * @param regionName
+ * @return Array of byte[] containing tableName, startKey and id
+ */
+ public static byte [][] parseRegionName(final byte [] regionName)
+ throws IOException {
+ int offset = -1;
+ for (int i = 0; i < regionName.length; i++) {
+ if (regionName[i] == DELIMITER) {
+ offset = i;
+ break;
+ }
+ }
+ if(offset == -1) throw new IOException("Invalid regionName format");
+ byte [] tableName = new byte[offset];
+ System.arraycopy(regionName, 0, tableName, 0, offset);
+ offset = -1;
+ for (int i = regionName.length - 1; i > 0; i--) {
+ if(regionName[i] == DELIMITER) {
+ offset = i;
+ break;
+ }
+ }
+ if(offset == -1) throw new IOException("Invalid regionName format");
+ byte [] startKey = HConstants.EMPTY_BYTE_ARRAY;
+ if(offset != tableName.length + 1) {
+ startKey = new byte[offset - tableName.length - 1];
+ System.arraycopy(regionName, tableName.length + 1, startKey, 0,
+ offset - tableName.length - 1);
+ }
+ byte [] id = new byte[regionName.length - offset - 1];
+ System.arraycopy(regionName, offset + 1, id, 0,
+ regionName.length - offset - 1);
+ byte [][] elements = new byte[3][];
+ elements[0] = tableName;
+ elements[1] = startKey;
+ elements[2] = id;
+ return elements;
+ }
+
/** @return the endKey */
public byte [] getEndKey(){
return endKey;
Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/master/HMaster.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/master/HMaster.java?rev=741018&r1=741017&r2=741018&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/master/HMaster.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/master/HMaster.java Thu Feb 5 05:52:26 2009
@@ -768,6 +768,29 @@
return null;
}
+ private Pair<HRegionInfo,HServerAddress>
+ getTableRegionFromName(final byte [] regionName)
+ throws IOException {
+ byte [] tableName = HRegionInfo.parseRegionName(regionName)[0];
+ Set<MetaRegion> regions = regionManager.getMetaRegionsForTable(tableName);
+ for (MetaRegion m: regions) {
+ byte [] metaRegionName = m.getRegionName();
+ HRegionInterface srvr = connection.getHRegionConnection(m.getServer());
+ RowResult data = srvr.getRow(metaRegionName, regionName,
+ new byte[][] {COL_REGIONINFO, COL_SERVER},
+ HConstants.LATEST_TIMESTAMP, 1, -1L);
+ if(data == null || data.size() <= 0) continue;
+ HRegionInfo info = Writables.getHRegionInfo(data.get(COL_REGIONINFO));
+ Cell cell = data.get(COL_SERVER);
+ if(cell != null) {
+ HServerAddress server =
+ new HServerAddress(Bytes.toString(cell.getValue()));
+ return new Pair<HRegionInfo,HServerAddress>(info, server);
+ }
+ }
+ return null;
+ }
+
/**
* Get row from meta table.
* @param row
@@ -813,9 +836,14 @@
if (!(args[0] instanceof ImmutableBytesWritable))
throw new IOException(
"request argument must be ImmutableBytesWritable");
- byte [] rowKey = ((ImmutableBytesWritable)args[0]).get();
- Pair<HRegionInfo,HServerAddress> pair =
- getTableRegionClosest(tableName, rowKey);
+ Pair<HRegionInfo,HServerAddress> pair = null;
+ if(tableName == null) {
+ byte [] regionName = ((ImmutableBytesWritable)args[0]).get();
+ pair = getTableRegionFromName(regionName);
+ } else {
+ byte [] rowKey = ((ImmutableBytesWritable)args[0]).get();
+ pair = getTableRegionClosest(tableName, rowKey);
+ }
if (pair != null) {
this.regionManager.startAction(pair.getFirst().getRegionName(),
pair.getFirst(), pair.getSecond(), op);