Skip to content

Commit

Permalink
KUDU-2802 [java] tableExists API optimizations
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
oclarms authored and adembo committed May 22, 2019
1 parent 2bf80b5 commit 8073749
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -832,18 +832,27 @@ public Deferred<Boolean> tableExists(final String name) {
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);
}

/**
Expand Down

0 comments on commit 8073749

Please sign in to comment.