HBASE-9438 Enhance hbase shell un/assign to take encoded region name

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1520383 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
jxiang 2013-09-05 18:54:34 +00:00
parent ab61360461
commit 2da88f9ce9
5 changed files with 35 additions and 3 deletions

View File

@ -1664,10 +1664,12 @@ public class HBaseAdmin implements Abortable, Closeable {
*/
public void assign(final byte[] regionName) throws MasterNotRunningException,
ZooKeeperConnectionException, IOException {
final byte[] toBeAssigned = getRegionName(regionName);
executeCallable(new MasterAdminCallable<Void>(getConnection()) {
@Override
public Void call() throws ServiceException {
AssignRegionRequest request = RequestConverter.buildAssignRegionRequest(regionName);
AssignRegionRequest request =
RequestConverter.buildAssignRegionRequest(toBeAssigned);
masterAdmin.assignRegion(null,request);
return null;
}
@ -1688,13 +1690,14 @@ public class HBaseAdmin implements Abortable, Closeable {
* @throws ZooKeeperConnectionException
* @throws IOException
*/
public void unassign(final byte [] regionName, final boolean force)
public void unassign(final byte [] getRegionName, final boolean force)
throws MasterNotRunningException, ZooKeeperConnectionException, IOException {
final byte[] toBeUnassigned = getRegionName(getRegionName);
executeCallable(new MasterAdminCallable<Void>(getConnection()) {
@Override
public Void call() throws ServiceException {
UnassignRegionRequest request =
RequestConverter.buildUnassignRegionRequest(regionName, force);
RequestConverter.buildUnassignRegionRequest(toBeUnassigned, force);
masterAdmin.unassignRegion(null,request);
return null;
}
@ -2003,6 +2006,26 @@ public class HBaseAdmin implements Abortable, Closeable {
return pair;
}
/**
* If the input is a region name, it is returned as is. If it's an
* encoded region name, the corresponding region is found from meta
* and its region name is returned. If we can't find any region in
* meta matching the input as either region name or encoded region
* name, the input is returned as is. We don't throw unknown
* region exception.
*/
private byte[] getRegionName(
final byte[] regionNameOrEncodedRegionName) throws IOException {
CatalogTracker ct = getCatalogTracker();
Pair<HRegionInfo, ServerName> regionServerPair
= getRegion(regionNameOrEncodedRegionName, ct);
byte[] tmp = regionNameOrEncodedRegionName;
if (regionServerPair != null && regionServerPair.getFirst() != null) {
tmp = regionServerPair.getFirst().getRegionName();
}
return tmp;
}
/**
* Check if table exists or not
* @param tableName Name of a table.

View File

@ -24,6 +24,10 @@ module Shell
return <<-EOF
Assign a region. Use with caution. If region already assigned,
this command will do a force reassign. For experts only.
Examples:
hbase> assign 'REGIONNAME'
hbase> assign 'ENCODED_REGIONNAME'
EOF
end

View File

@ -44,6 +44,8 @@ Examples:
hbase> close_region 'REGIONNAME'
hbase> close_region 'REGIONNAME', 'SERVER_NAME'
hbase> close_region 'ENCODED_REGIONNAME'
hbase> close_region 'ENCODED_REGIONNAME', 'SERVER_NAME'
EOF
end

View File

@ -27,6 +27,7 @@ flush an individual region. For example:
hbase> flush 'TABLENAME'
hbase> flush 'REGIONNAME'
hbase> flush 'ENCODED_REGIONNAME'
EOF
end

View File

@ -30,6 +30,8 @@ Use with caution. For expert use only. Examples:
hbase> unassign 'REGIONNAME'
hbase> unassign 'REGIONNAME', true
hbase> unassign 'ENCODED_REGIONNAME'
hbase> unassign 'ENCODED_REGIONNAME', true
EOF
end