hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From li...@apache.org
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 GMT
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;
   }
 
   /*



Mime
View raw message