HBASE-23554 Encoded regionname to regionname utility (#923); ADDENDUM

This commit is contained in:
stack 2019-12-11 11:02:59 -08:00
parent 8742265d85
commit b0233a294f
3 changed files with 31 additions and 24 deletions

View File

@ -1723,18 +1723,26 @@ public final class ProtobufUtil {
final RpcController controller, final AdminService.BlockingInterface admin,
final byte[] regionName) throws IOException {
try {
GetRegionInfoRequest request =
org.apache.hadoop.hbase.client.RegionInfo.isEncodedRegionName(regionName)?
GetRegionInfoRequest.newBuilder().setRegion(RequestConverter.
buildRegionSpecifier(RegionSpecifierType.ENCODED_REGION_NAME, regionName)).build():
RequestConverter.buildGetRegionInfoRequest(regionName);
GetRegionInfoResponse response = admin.getRegionInfo(controller, request);
GetRegionInfoRequest request = getGetRegionInfoRequest(regionName);
GetRegionInfoResponse response = admin.getRegionInfo(controller,
getGetRegionInfoRequest(regionName));
return toRegionInfo(response.getRegionInfo());
} catch (ServiceException se) {
throw getRemoteException(se);
}
}
/**
* @return A GetRegionInfoRequest for the passed in regionName.
*/
public static GetRegionInfoRequest getGetRegionInfoRequest(final byte [] regionName)
throws IOException {
return org.apache.hadoop.hbase.client.RegionInfo.isEncodedRegionName(regionName)?
GetRegionInfoRequest.newBuilder().setRegion(RequestConverter.
buildRegionSpecifier(RegionSpecifierType.ENCODED_REGION_NAME, regionName)).build():
RequestConverter.buildGetRegionInfoRequest(regionName);
}
/**
* A helper to close a region given a region name
* using admin protocol.

View File

@ -53,6 +53,7 @@ import org.apache.hadoop.hbase.regionserver.HStore;
import org.apache.hadoop.hbase.testclassification.ClientTests;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.FutureUtils;
import org.apache.hadoop.hbase.wal.AbstractFSWALProvider;
import org.junit.Assert;
import org.junit.ClassRule;
@ -698,29 +699,27 @@ public class TestAdmin2 extends TestAdminBase {
// Test querying using the encoded name only. When encoded name passed,
// and the target server is the Master, we return the full region name.
// Convenience.
testGetWithEncodedRegionName(conn, region.getRegionInfo());
testGetWithRegionName(conn, region.getRegionInfo());
ServerName sn = null;
try (Admin admin = TEST_UTIL.getConnection().getAdmin()) {
sn = admin.getMaster();
}
RegionInfo ri = region.getRegionInfo();
testGetWithRegionName(sn, ri, ri.getEncodedNameAsBytes());
testGetWithRegionName(sn, ri, ri.getRegionName());
// Try querying meta encoded name.
testGetWithEncodedRegionName(conn, RegionInfoBuilder.FIRST_META_REGIONINFO);
testGetWithRegionName(conn, RegionInfoBuilder.FIRST_META_REGIONINFO);
ri = RegionInfoBuilder.FIRST_META_REGIONINFO;
testGetWithRegionName(sn, ri, ri.getEncodedNameAsBytes());
testGetWithRegionName(sn, ri, ri.getRegionName());
}
/**
* Do get of RegionInfo from Master using encoded region name.
*/
private void testGetWithEncodedRegionName(ClusterConnection conn, RegionInfo inputRI)
throws IOException {
RegionInfo ri = ProtobufUtil.getRegionInfo(null,
conn.getAdmin(TEST_UTIL.getMiniHBaseCluster().getMaster().getServerName()),
inputRI.getEncodedNameAsBytes());
assertEquals(inputRI, ri);
}
private void testGetWithRegionName(ClusterConnection conn, RegionInfo inputRI)
throws IOException {
RegionInfo ri = ProtobufUtil.getRegionInfo(null,
conn.getAdmin(TEST_UTIL.getMiniHBaseCluster().getMaster().getServerName()),
inputRI.getRegionName());
private void testGetWithRegionName(ServerName sn, RegionInfo inputRI,
byte [] regionName) throws IOException {
RegionInfo ri = ProtobufUtil.toRegionInfo(FutureUtils.get(
TEST_UTIL.getAsyncConnection().getRegionServerAdmin(sn).getRegionInfo(
ProtobufUtil.getGetRegionInfoRequest(regionName))).getRegionInfo());
assertEquals(inputRI, ri);
}

View File

@ -38,7 +38,7 @@ EOF
def command(regionname)
connection = org.apache.hadoop.hbase.client.ConnectionFactory.createConnection()
admin = connection.getAdmin()
sn = servername != nil ? ServerName.valueOf(servername): admin.getMaster()
sn = admin.getMaster()
puts org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil.getRegionInfo(nil,
connection.getAdmin(sn), regionname.to_java_bytes)
end