kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danburk...@apache.org
Subject [1/2] kudu git commit: Add table id to AlterTableResponsePB
Date Wed, 10 Aug 2016 06:06:25 GMT
Repository: kudu
Updated Branches:
  refs/heads/master acf093c18 -> 1dbfb7550


Add table id to AlterTableResponsePB

This also changes the Java client to take advantage of the ID to selectively
clear the table locations cache on range partitioning alteration.

Change-Id: I63402581fbdaef2abdf37910c1dfaedbdcba76e2
Reviewed-on: http://gerrit.cloudera.org:8080/3859
Reviewed-by: Adar Dembo <adar@cloudera.com>
Tested-by: Kudu Jenkins


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/0f899ebd
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/0f899ebd
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/0f899ebd

Branch: refs/heads/master
Commit: 0f899ebd374aebbe17947b7842a559a4cf129feb
Parents: acf093c
Author: Dan Burkert <dan@cloudera.com>
Authored: Sun Aug 7 15:04:22 2016 -0700
Committer: Dan Burkert <dan@cloudera.com>
Committed: Wed Aug 10 06:06:06 2016 +0000

----------------------------------------------------------------------
 .../apache/kudu/client/AlterTableRequest.java   |  6 ++--
 .../apache/kudu/client/AlterTableResponse.java  | 12 +++++++-
 .../org/apache/kudu/client/AsyncKuduClient.java | 30 ++++++++++++++++----
 src/kudu/master/catalog_manager.cc              |  1 +
 src/kudu/master/master.proto                    |  4 +++
 5 files changed, 44 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/0f899ebd/java/kudu-client/src/main/java/org/apache/kudu/client/AlterTableRequest.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/AlterTableRequest.java
b/java/kudu-client/src/main/java/org/apache/kudu/client/AlterTableRequest.java
index 391e549..41eb1a1 100644
--- a/java/kudu-client/src/main/java/org/apache/kudu/client/AlterTableRequest.java
+++ b/java/kudu-client/src/main/java/org/apache/kudu/client/AlterTableRequest.java
@@ -69,8 +69,10 @@ class AlterTableRequest extends KuduRpc<AlterTableResponse> {
                                                 String tsUUID) throws Exception {
     final AlterTableResponsePB.Builder respBuilder = AlterTableResponsePB.newBuilder();
     readProtobuf(callResponse.getPBMessage(), respBuilder);
-    AlterTableResponse response = new AlterTableResponse(deadlineTracker.getElapsedMillis(),
-        tsUUID);
+    AlterTableResponse response = new AlterTableResponse(
+        deadlineTracker.getElapsedMillis(), tsUUID,
+        respBuilder.hasTableId() ? respBuilder.getTableId().toStringUtf8() : null);
+
     return new Pair<AlterTableResponse, Object>(
         response, respBuilder.hasError() ? respBuilder.getError() : null);
   }

http://git-wip-us.apache.org/repos/asf/kudu/blob/0f899ebd/java/kudu-client/src/main/java/org/apache/kudu/client/AlterTableResponse.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/AlterTableResponse.java
b/java/kudu-client/src/main/java/org/apache/kudu/client/AlterTableResponse.java
index 116816c..af582e1 100644
--- a/java/kudu-client/src/main/java/org/apache/kudu/client/AlterTableResponse.java
+++ b/java/kudu-client/src/main/java/org/apache/kudu/client/AlterTableResponse.java
@@ -23,10 +23,20 @@ import org.apache.kudu.annotations.InterfaceStability;
 @InterfaceStability.Evolving
 public class AlterTableResponse extends KuduRpcResponse {
 
+  private String tableId;
+
   /**
    * @param ellapsedMillis Time in milliseconds since RPC creation to now.
    */
-  AlterTableResponse(long ellapsedMillis, String tsUUID) {
+  AlterTableResponse(long ellapsedMillis, String tsUUID, String tableId) {
     super(ellapsedMillis, tsUUID);
+    this.tableId = tableId;
+  }
+
+  /**
+   * @return the ID of the altered table, or null if the master version is too old
+   */
+  public String getTableId() {
+    return tableId;
   }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/kudu/blob/0f899ebd/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduClient.java
----------------------------------------------------------------------
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 2b0cb75..70b06ed 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
@@ -354,18 +354,36 @@ public class AsyncKuduClient implements AutoCloseable {
 
     if (ato.hasAddDropRangePartitions()) {
       // Clear the table locations cache so the new partition is immediately visible.
-      Callback clearCacheCB = new Callback() {
+      return response.addCallback(new Callback<AlterTableResponse, AlterTableResponse>()
{
         @Override
-        public Object call(Object resp) throws Exception {
-          tableLocations.clear();
+        public AlterTableResponse call(AlterTableResponse resp) {
+          // If the master is of a recent enough version to return the table ID,
+          // we can selectively clear the cache only for the altered table.
+          // Otherwise, we clear the caches for all tables.
+          if (resp.getTableId() != null) {
+            tableLocations.remove(resp.getTableId());
+          } else {
+            tableLocations.clear();
+          }
           return resp;
         }
         @Override
         public String toString() {
-          return "ClearCacheCB";
+          return "ClearTableLocationsCacheCB";
+        }
+      }).addErrback(new Callback<Exception, Exception>() {
+        @Override
+        public Exception call(Exception e) {
+          // We clear the cache even on failure, just in
+          // case the alter table operation actually succeeded.
+          tableLocations.clear();
+          return e;
+        }
+        @Override
+        public String toString() {
+          return "ClearTableLocationsCacheEB";
         }
-      };
-      return response.addCallback(clearCacheCB).addErrback(clearCacheCB);
+      });
     }
     return response;
   }

http://git-wip-us.apache.org/repos/asf/kudu/blob/0f899ebd/src/kudu/master/catalog_manager.cc
----------------------------------------------------------------------
diff --git a/src/kudu/master/catalog_manager.cc b/src/kudu/master/catalog_manager.cc
index e22fb47..e2061d9 100644
--- a/src/kudu/master/catalog_manager.cc
+++ b/src/kudu/master/catalog_manager.cc
@@ -1428,6 +1428,7 @@ Status CatalogManager::AlterTable(const AlterTableRequestPB* req,
   }
 
   string table_name = l.data().name();
+  *resp->mutable_table_id() = table->id();
 
   // 4. Calculate new schema for the on-disk state, not persisted yet.
   Schema new_schema;

http://git-wip-us.apache.org/repos/asf/kudu/blob/0f899ebd/src/kudu/master/master.proto
----------------------------------------------------------------------
diff --git a/src/kudu/master/master.proto b/src/kudu/master/master.proto
index cae4dae..5b207a2 100644
--- a/src/kudu/master/master.proto
+++ b/src/kudu/master/master.proto
@@ -486,7 +486,11 @@ message AlterTableResponsePB {
   // The error, if an error occurred with this request.
   optional MasterErrorPB error = 1;
 
+  // The schema version of the altered table.
   optional uint32 schema_version = 2;
+
+  // The table ID of the altered table.
+  optional bytes table_id = 3;
 }
 
 message IsAlterTableDoneRequestPB {


Mime
View raw message