hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject hbase git commit: HBASE-14203 remove duplicate code getTableDescriptor in HTable (Heng Chen)
Date Mon, 17 Aug 2015 23:12:30 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 c619e0c76 -> c9b3d837a


HBASE-14203 remove duplicate code getTableDescriptor in HTable (Heng Chen)

Conflicts:
	hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/c9b3d837
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/c9b3d837
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/c9b3d837

Branch: refs/heads/branch-1
Commit: c9b3d837a0ca4677e9f86f35ef78b6cb4710527b
Parents: c619e0c
Author: Enis Soztutar <enis@apache.org>
Authored: Mon Aug 17 16:05:26 2015 -0700
Committer: Enis Soztutar <enis@apache.org>
Committed: Mon Aug 17 16:12:18 2015 -0700

----------------------------------------------------------------------
 .../apache/hadoop/hbase/client/HBaseAdmin.java  | 44 +++++++++++++-------
 .../org/apache/hadoop/hbase/client/HTable.java  | 23 +---------
 2 files changed, 30 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/c9b3d837/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
index c014cbd..57a171c 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
@@ -444,25 +444,32 @@ public class HBaseAdmin implements Admin {
   @Override
   public HTableDescriptor getTableDescriptor(final TableName tableName)
   throws TableNotFoundException, IOException {
-    if (tableName == null) return null;
-    HTableDescriptor htd = executeCallable(new MasterCallable<HTableDescriptor>(getConnection())
{
-      @Override
-      public HTableDescriptor call(int callTimeout) throws ServiceException {
-        GetTableDescriptorsResponse htds;
-        GetTableDescriptorsRequest req =
-            RequestConverter.buildGetTableDescriptorsRequest(tableName);
-        htds = master.getTableDescriptors(null, req);
+     return getTableDescriptor(tableName, getConnection(), rpcCallerFactory, operationTimeout);
+  }
 
-        if (!htds.getTableSchemaList().isEmpty()) {
-          return HTableDescriptor.convert(htds.getTableSchemaList().get(0));
+  static HTableDescriptor getTableDescriptor(final TableName tableName,
+         HConnection connection, RpcRetryingCallerFactory rpcCallerFactory,
+         int operationTimeout) throws TableNotFoundException, IOException {
+
+      if (tableName == null) return null;
+      HTableDescriptor htd = executeCallable(new MasterCallable<HTableDescriptor>(connection)
{
+        @Override
+        public HTableDescriptor call(int callTimeout) throws ServiceException {
+          GetTableDescriptorsResponse htds;
+          GetTableDescriptorsRequest req =
+                  RequestConverter.buildGetTableDescriptorsRequest(tableName);
+          htds = master.getTableDescriptors(null, req);
+
+          if (!htds.getTableSchemaList().isEmpty()) {
+            return HTableDescriptor.convert(htds.getTableSchemaList().get(0));
+          }
+          return null;
         }
-        return null;
+      }, rpcCallerFactory, operationTimeout);
+      if (htd != null) {
+        return htd;
       }
-    });
-    if (htd != null) {
-      return htd;
-    }
-    throw new TableNotFoundException(tableName.getNameAsString());
+      throw new TableNotFoundException(tableName.getNameAsString());
   }
 
   public HTableDescriptor getTableDescriptor(final byte[] tableName)
@@ -4000,6 +4007,11 @@ public class HBaseAdmin implements Admin {
   }
 
   private <V> V executeCallable(MasterCallable<V> callable) throws IOException
{
+    return executeCallable(callable, rpcCallerFactory, operationTimeout);
+  }
+
+  private static <V> V executeCallable(MasterCallable<V> callable,
+             RpcRetryingCallerFactory rpcCallerFactory, int operationTimeout) throws IOException
{
     RpcRetryingCaller<V> caller = rpcCallerFactory.newCaller();
     try {
       return caller.callWithRetries(callable, operationTimeout);

http://git-wip-us.apache.org/repos/asf/hbase/blob/c9b3d837/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java
index 22aee5a..2793ae2 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java
@@ -571,30 +571,11 @@ public class HTable implements HTableInterface, RegionLocator {
    */
   @Override
   public HTableDescriptor getTableDescriptor() throws IOException {
-    // TODO: This is the same as HBaseAdmin.getTableDescriptor(). Only keep one.
-    if (tableName == null) return null;
-    if (tableName.equals(TableName.META_TABLE_NAME)) {
-      return HTableDescriptor.META_TABLEDESC;
-    }
-    HTableDescriptor htd = executeMasterCallable(
-      new MasterCallable<HTableDescriptor>(getConnection()) {
-      @Override
-      public HTableDescriptor call(int callTimeout) throws ServiceException {
-        GetTableDescriptorsResponse htds;
-        GetTableDescriptorsRequest req =
-            RequestConverter.buildGetTableDescriptorsRequest(tableName);
-        htds = master.getTableDescriptors(null, req);
-
-        if (!htds.getTableSchemaList().isEmpty()) {
-          return HTableDescriptor.convert(htds.getTableSchemaList().get(0));
-        }
-        return null;
-      }
-    });
+    HTableDescriptor htd = HBaseAdmin.getTableDescriptor(tableName, connection, rpcCallerFactory,
operationTimeout);
     if (htd != null) {
       return new UnmodifyableHTableDescriptor(htd);
     }
-    throw new TableNotFoundException(tableName.getNameAsString());
+    return null;
   }
 
   private <V> V executeMasterCallable(MasterCallable<V> callable) throws IOException
{


Mime
View raw message