kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [kudu] 02/02: KUDU-2802 [java] tableExists API optimizations
Date Wed, 22 May 2019 16:55:29 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 80737497466985fd87268b6f608aa22a112f7d53
Author: oclarms <oclarms@gmail.com>
AuthorDate: Wed May 22 15:27:02 2019 +0800

    KUDU-2802 [java] tableExists API optimizations
    
    Currently the Java client `tableExists()` method uses a ListTables
    rpc. Instead it should use a GetTableSchema rpc. Because ListTables
    is going to perform really poorly with a cold Sentry cache: it'll
    send an RPC to Sentry for every table in the catalog.
    
    Change-Id: I7076aea3850a716822563938d879289beb3fa67c
    Reviewed-on: http://gerrit.cloudera.org:8080/13401
    Tested-by: Kudu Jenkins
    Reviewed-by: Adar Dembo <adar@cloudera.com>
---
 .../org/apache/kudu/client/AsyncKuduClient.java    | 25 +++++++++++++++-------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduClient.java b/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduClient.java
index 74beb9e..6440702 100644
--- a/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduClient.java
+++ b/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduClient.java
@@ -832,18 +832,27 @@ public class AsyncKuduClient implements AutoCloseable {
     if (name == null) {
       throw new IllegalArgumentException("The table name cannot be null");
     }
-    return getTablesList().addCallbackDeferring(new Callback<Deferred<Boolean>,
-        ListTablesResponse>() {
+
+    Callback<Deferred<Boolean>, KuduTable> cb = new Callback<Deferred<Boolean>,
KuduTable>() {
+      @Override
+      public Deferred<Boolean> call(KuduTable table) throws Exception {
+        return Deferred.fromResult(true);
+      }
+    };
+    Callback<Deferred<Boolean>, Exception> eb = new Callback<Deferred<Boolean>,
Exception>() {
       @Override
-      public Deferred<Boolean> call(ListTablesResponse listTablesResponse) throws Exception
{
-        for (String tableName : listTablesResponse.getTablesList()) {
-          if (name.equals(tableName)) {
-            return Deferred.fromResult(true);
+      public Deferred<Boolean> call(Exception e) throws Exception {
+        if (e instanceof NonRecoverableException) {
+          Status status = ((NonRecoverableException) e).getStatus();
+          if (status.isNotFound()) {
+            return Deferred.fromResult(false);
           }
         }
-        return Deferred.fromResult(false);
+        return Deferred.fromError(e);
       }
-    });
+    };
+
+    return AsyncUtil.addCallbacksDeferring(getTableSchema(name, null, null), cb, eb);
   }
 
   /**


Mime
View raw message