This is an automated email from the ASF dual-hosted git repository.

stack pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/master by this push:
     new b0233a2   HBASE-23554 Encoded regionname to regionname utility (#923); 
ADDENDUM
b0233a2 is described below

commit b0233a294f1fb4f952e21da53b8f7ee46a239747
Author: stack <[email protected]>
AuthorDate: Wed Dec 11 11:02:59 2019 -0800

     HBASE-23554 Encoded regionname to regionname utility (#923); ADDENDUM
---
 .../hadoop/hbase/shaded/protobuf/ProtobufUtil.java | 20 +++++++++----
 .../org/apache/hadoop/hbase/client/TestAdmin2.java | 33 +++++++++++-----------
 .../src/main/ruby/shell/commands/regioninfo.rb     |  2 +-
 3 files changed, 31 insertions(+), 24 deletions(-)

diff --git 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java
 
b/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java
index 9176e49..5a71917 100644
--- 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java
+++ 
b/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java
@@ -1723,12 +1723,9 @@ 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);
@@ -1736,6 +1733,17 @@ public final class ProtobufUtil {
   }
 
   /**
+   * @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.
    *
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin2.java 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin2.java
index dbe86c2..75a6be1 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin2.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin2.java
@@ -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);
   }
 
diff --git a/hbase-shell/src/main/ruby/shell/commands/regioninfo.rb 
b/hbase-shell/src/main/ruby/shell/commands/regioninfo.rb
index c611705..725dd65 100644
--- a/hbase-shell/src/main/ruby/shell/commands/regioninfo.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/regioninfo.rb
@@ -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

Reply via email to