Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CBAE01835C for ; Mon, 17 Aug 2015 23:23:23 +0000 (UTC) Received: (qmail 69778 invoked by uid 500); 17 Aug 2015 23:23:23 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 69737 invoked by uid 500); 17 Aug 2015 23:23:23 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 69728 invoked by uid 99); 17 Aug 2015 23:23:23 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Aug 2015 23:23:23 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 854A3E0424; Mon, 17 Aug 2015 23:23:23 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: enis@apache.org To: commits@hbase.apache.org Message-Id: <97e6f3a5218d460ea6b0b80443d59a58@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hbase git commit: HBASE-14203 remove duplicate code getTableDescriptor in HTable (Heng Chen) Date: Mon, 17 Aug 2015 23:23:23 +0000 (UTC) Repository: hbase Updated Branches: refs/heads/branch-1.2 05328c7a4 -> 158839552 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/15883955 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/15883955 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/15883955 Branch: refs/heads/branch-1.2 Commit: 158839552fb765e3e330a3a905511c22eec6b2ce Parents: 05328c7 Author: Enis Soztutar Authored: Mon Aug 17 16:05:26 2015 -0700 Committer: Enis Soztutar Committed: Mon Aug 17 16:20:57 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/15883955/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 cb64fb3..7cedf76 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(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(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) @@ -3927,6 +3934,11 @@ public class HBaseAdmin implements Admin { } private V executeCallable(MasterCallable callable) throws IOException { + return executeCallable(callable, rpcCallerFactory, operationTimeout); + } + + private static V executeCallable(MasterCallable callable, + RpcRetryingCallerFactory rpcCallerFactory, int operationTimeout) throws IOException { RpcRetryingCaller caller = rpcCallerFactory.newCaller(); try { return caller.callWithRetries(callable, operationTimeout); http://git-wip-us.apache.org/repos/asf/hbase/blob/15883955/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(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 executeMasterCallable(MasterCallable callable) throws IOException {