kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdcry...@apache.org
Subject [1/2] incubator-kudu git commit: [java-client] make AsyncKuduSession#close idempotent
Date Fri, 06 May 2016 02:36:03 GMT
Repository: incubator-kudu
Updated Branches:
  refs/heads/master e88e0a7bf -> 93ff8fc5c


[java-client] make AsyncKuduSession#close idempotent

Change-Id: Ifa61426139ea95555ac0bce53187081ae9881bc8
Reviewed-on: http://gerrit.cloudera.org:8080/2976
Reviewed-by: Jean-Daniel Cryans
Reviewed-by: Adar Dembo <adar@cloudera.com>
Tested-by: Kudu Jenkins


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

Branch: refs/heads/master
Commit: 20d221796d3c7f4c9a89586adbb169c95625c348
Parents: e88e0a7
Author: Dan Burkert <dan@cloudera.com>
Authored: Thu May 5 16:34:55 2016 -0700
Committer: Dan Burkert <dan@cloudera.com>
Committed: Fri May 6 01:27:11 2016 +0000

----------------------------------------------------------------------
 .../java/org/kududb/client/AsyncKuduSession.java     | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/20d22179/java/kudu-client/src/main/java/org/kududb/client/AsyncKuduSession.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/main/java/org/kududb/client/AsyncKuduSession.java b/java/kudu-client/src/main/java/org/kududb/client/AsyncKuduSession.java
index 1bbc74f..baa1b7a 100644
--- a/java/kudu-client/src/main/java/org/kududb/client/AsyncKuduSession.java
+++ b/java/kudu-client/src/main/java/org/kududb/client/AsyncKuduSession.java
@@ -17,6 +17,7 @@
 package org.kududb.client;
 
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Range;
 import com.google.common.collect.Ranges;
 import com.google.common.collect.Sets;
@@ -249,9 +250,14 @@ public class AsyncKuduSession implements SessionConfiguration {
    * everything that was buffered at the time of the call has been flushed.
    */
   public Deferred<List<OperationResponse>> close() {
-    closed = true;
-    client.removeSession(this);
-    return flush();
+    if (!closed) {
+      closed = true;
+      client.removeSession(this);
+      return flush();
+    } else {
+      // Deferred#fromResult(T) is invariant on T, so the cast is necessary.
+      return Deferred.fromResult((List<OperationResponse>) ImmutableList.<OperationResponse>of());
+    }
   }
 
   /**
@@ -803,6 +809,9 @@ public class AsyncKuduSession implements SessionConfiguration {
     }
 
     public void run(final Timeout timeout) {
+      // This is a TOCTOU violation, but since {@link #flushTablet} is
+      // synchronized internally it is only an optimistic check, and
+      // false negatives do not cause thread safety issues.
       if (isClosed()) {
         return; // we ran too late, no-op
       }


Mime
View raw message