From 08805166e8b8226d21476c732136550ae0511ce5 Mon Sep 17 00:00:00 2001 From: Andrew Kyle Purtell Date: Thu, 5 Feb 2009 05:52:26 +0000 Subject: [PATCH] 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 --- CHANGES.txt | 2 + .../org/apache/hadoop/hbase/HRegionInfo.java | 41 +++++++++++++++++++ .../apache/hadoop/hbase/master/HMaster.java | 34 +++++++++++++-- 3 files changed, 74 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 18174b4a820..bd3df7f03a2 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -17,6 +17,8 @@ Release 0.20.0 - Unreleased 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 diff --git a/src/java/org/apache/hadoop/hbase/HRegionInfo.java b/src/java/org/apache/hadoop/hbase/HRegionInfo.java index d5d6fa0a42d..987678ce2e5 100644 --- a/src/java/org/apache/hadoop/hbase/HRegionInfo.java +++ b/src/java/org/apache/hadoop/hbase/HRegionInfo.java @@ -217,6 +217,47 @@ public class HRegionInfo extends VersionedWritable implements WritableComparable 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; diff --git a/src/java/org/apache/hadoop/hbase/master/HMaster.java b/src/java/org/apache/hadoop/hbase/master/HMaster.java index 98f39380c22..fb883dd05b0 100644 --- a/src/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/src/java/org/apache/hadoop/hbase/master/HMaster.java @@ -768,6 +768,29 @@ public class HMaster extends Thread implements HConstants, HMasterInterface, return null; } + private Pair + getTableRegionFromName(final byte [] regionName) + throws IOException { + byte [] tableName = HRegionInfo.parseRegionName(regionName)[0]; + Set 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(info, server); + } + } + return null; + } + /** * Get row from meta table. * @param row @@ -813,9 +836,14 @@ public class HMaster extends Thread implements HConstants, HMasterInterface, if (!(args[0] instanceof ImmutableBytesWritable)) throw new IOException( "request argument must be ImmutableBytesWritable"); - byte [] rowKey = ((ImmutableBytesWritable)args[0]).get(); - Pair pair = - getTableRegionClosest(tableName, rowKey); + Pair 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);