HBASE-1175 HBA administrative tools do not work when specifying region name

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@741018 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew Kyle Purtell 2009-02-05 05:52:26 +00:00
parent 46d3e17942
commit 08805166e8
3 changed files with 74 additions and 3 deletions

View File

@ -17,6 +17,8 @@ Release 0.20.0 - Unreleased
HBASE-1148 Always flush HLog on root or meta region updates 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) HBASE-1181 src/saveVersion.sh bails on non-standard Bourne shells (e.g. dash)
(K M via Jean-Daniel Cryans) (K M via Jean-Daniel Cryans)
HBASE-1175 HBA administrative tools do not work when specifying region
name (Jonathan Gray via Andrew Purtell)
IMPROVEMENTS IMPROVEMENTS
HBASE-1089 Add count of regions on filesystem to master UI; add percentage HBASE-1089 Add count of regions on filesystem to master UI; add percentage

View File

@ -217,6 +217,47 @@ public class HRegionInfo extends VersionedWritable implements WritableComparable
return b; 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 */ /** @return the endKey */
public byte [] getEndKey(){ public byte [] getEndKey(){
return endKey; return endKey;

View File

@ -768,6 +768,29 @@ public class HMaster extends Thread implements HConstants, HMasterInterface,
return null; 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. * Get row from meta table.
* @param row * @param row
@ -813,9 +836,14 @@ public class HMaster extends Thread implements HConstants, HMasterInterface,
if (!(args[0] instanceof ImmutableBytesWritable)) if (!(args[0] instanceof ImmutableBytesWritable))
throw new IOException( throw new IOException(
"request argument must be ImmutableBytesWritable"); "request argument must be ImmutableBytesWritable");
Pair<HRegionInfo,HServerAddress> pair = null;
if(tableName == null) {
byte [] regionName = ((ImmutableBytesWritable)args[0]).get();
pair = getTableRegionFromName(regionName);
} else {
byte [] rowKey = ((ImmutableBytesWritable)args[0]).get(); byte [] rowKey = ((ImmutableBytesWritable)args[0]).get();
Pair<HRegionInfo,HServerAddress> pair = pair = getTableRegionClosest(tableName, rowKey);
getTableRegionClosest(tableName, rowKey); }
if (pair != null) { if (pair != null) {
this.regionManager.startAction(pair.getFirst().getRegionName(), this.regionManager.startAction(pair.getFirst().getRegionName(),
pair.getFirst(), pair.getSecond(), op); pair.getFirst(), pair.getSecond(), op);