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 1D56D11F3C for ; Tue, 20 May 2014 18:19:06 +0000 (UTC) Received: (qmail 28481 invoked by uid 500); 20 May 2014 18:19:06 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 28438 invoked by uid 500); 20 May 2014 18:19:06 -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 28425 invoked by uid 99); 20 May 2014 18:19:06 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 May 2014 18:19:05 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 May 2014 18:19:04 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id A79862388994; Tue, 20 May 2014 18:18:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1596350 - in /hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client: HBaseAdmin.java TableServers.java Date: Tue, 20 May 2014 18:18:44 -0000 To: commits@hbase.apache.org From: liyin@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140520181844.A79862388994@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: liyin Date: Tue May 20 18:18:44 2014 New Revision: 1596350 URL: http://svn.apache.org/r1596350 Log: [HBASE-9704] Optimize tableExists in HBaseAdmin Author: manukranthk Summary: The Master's tableExists function is more optimal compared to HBaseAdmin's, reverting to use the master's logic. HBaseAdmin.tableExists previously used to take : ~25s. Now it takes ~2s. Test Plan: Tested on calypsohbase001-frc1 and found that it is 10X faster. Reviewers: rshroff, aaiyer Reviewed By: aaiyer Subscribers: hbase-eng@ Differential Revision: https://phabricator.fb.com/D1336866 Tasks: 4253634 Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/TableServers.java Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java?rev=1596350&r1=1596349&r2=1596350&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java Tue May 20 18:18:44 2014 @@ -61,6 +61,8 @@ import org.apache.hadoop.io.BooleanWrita import org.apache.hadoop.io.Writable; import org.apache.hadoop.ipc.RemoteException; +import com.google.common.base.Preconditions; + /** * Provides an interface to manage HBase database table metadata + general @@ -326,6 +328,7 @@ public class HBaseAdmin { tries = -1; } } + Preconditions.checkArgument(tableExists(desc.getName())); } /** Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/TableServers.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/TableServers.java?rev=1596350&r1=1596349&r2=1596350&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/TableServers.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/TableServers.java Tue May 20 18:18:44 2014 @@ -400,18 +400,29 @@ public class TableServers implements Ser if (isMetaTableName(tableName)) { return true; } - boolean exists = false; - try { - HTableDescriptor[] tables = listTables(); - for (HTableDescriptor table : tables) { - if (tableName.equalBytes(table.getName())) { - exists = true; + byte[] tname = Bytes.toBytes(tableName + ",,"); + Scan scan = new Scan(tname); + scan.addColumn(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER); + + try (HTable table = new HTable(conf, HConstants.META_TABLE_NAME)) { + try (ResultScanner scanner = table.getScanner(scan)) { + Result data = scanner.next(); + if (data != null && data.size() > 0) { + HRegionInfo info = Writables.getHRegionInfo( + data.getValue(HConstants.CATALOG_FAMILY, + HConstants.REGIONINFO_QUALIFIER)); + if (info.getTableDesc().getNameAsString().equals(tableName.getString())) { + // A region for this table already exists. Ergo table exists. + return true; + } } + } catch (IOException e) { + LOG.warn("Testing for table existence threw exception", e); } } catch (IOException e) { LOG.warn("Testing for table existence threw exception", e); } - return exists; + return false; } /*