kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danburk...@apache.org
Subject incubator-kudu git commit: [java-client] fix NPE when batch flush fails
Date Tue, 05 Jul 2016 17:16:32 GMT
Repository: incubator-kudu
Updated Branches:
  refs/heads/master 1ebfa6c66 -> 3692233b8


[java-client] fix NPE when batch flush fails

Change-Id: Icaf8ab20a0d8142ea38a17a648839e935aaef741
Reviewed-on: http://gerrit.cloudera.org:8080/3564
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/3692233b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kudu/tree/3692233b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kudu/diff/3692233b

Branch: refs/heads/master
Commit: 3692233b8d27f2f5841871bdca57a1801c982a69
Parents: 1ebfa6c
Author: Dan Burkert <dan@cloudera.com>
Authored: Fri Jul 1 17:15:07 2016 -0700
Committer: Dan Burkert <dan@cloudera.com>
Committed: Tue Jul 5 17:12:04 2016 +0000

----------------------------------------------------------------------
 .../org/kududb/client/AsyncKuduSession.java     |  6 ++---
 .../java/org/kududb/client/BaseKuduTest.java    | 16 +++++++++++++
 .../java/org/kududb/client/MiniKuduCluster.java | 24 ++++++++++++++++++++
 .../org/kududb/client/TestAsyncKuduSession.java | 23 +++++++++++++++++++
 4 files changed, 66 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/3692233b/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 3c5daa5..8ac70c4 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
@@ -639,14 +639,14 @@ public class AsyncKuduSession implements SessionConfiguration {
       }
     }
 
-    final class BatchErrCallback implements Callback<Void, Exception> {
+    final class BatchErrCallback implements Callback<Exception, Exception> {
       @Override
-      public Void call(Exception e) throws Exception {
+      public Exception call(Exception e) {
         // Send the same exception to all the operations.
         for (Operation operation : request.operations) {
           operation.errback(e);
         }
-        return null;
+        return e;
       }
       @Override
       public String toString() {

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/3692233b/java/kudu-client/src/test/java/org/kududb/client/BaseKuduTest.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/test/java/org/kududb/client/BaseKuduTest.java b/java/kudu-client/src/test/java/org/kududb/client/BaseKuduTest.java
index dfb48d7..994fec1 100644
--- a/java/kudu-client/src/test/java/org/kududb/client/BaseKuduTest.java
+++ b/java/kudu-client/src/test/java/org/kududb/client/BaseKuduTest.java
@@ -388,4 +388,20 @@ public class BaseKuduTest {
   protected static String getMasterAddresses() {
     return masterAddresses;
   }
+
+  /**
+   * Kills all tablet servers in the cluster.
+   * @throws InterruptedException
+   */
+  protected void killTabletServers() throws InterruptedException {
+    miniCluster.killTabletServers();
+  }
+
+  /**
+   * Restarts killed tablet servers in the cluster.
+   * @throws Exception
+   */
+  protected void restartTabletServers() throws Exception {
+    miniCluster.restartDeadTabletServers();
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/3692233b/java/kudu-client/src/test/java/org/kududb/client/MiniKuduCluster.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/test/java/org/kududb/client/MiniKuduCluster.java b/java/kudu-client/src/test/java/org/kududb/client/MiniKuduCluster.java
index 7ddced4..9dbd181 100644
--- a/java/kudu-client/src/test/java/org/kududb/client/MiniKuduCluster.java
+++ b/java/kudu-client/src/test/java/org/kududb/client/MiniKuduCluster.java
@@ -64,6 +64,7 @@ public class MiniKuduCluster implements AutoCloseable {
 
   private final List<String> pathsToDelete = new ArrayList<>();
   private final List<HostAndPort> masterHostPorts = new ArrayList<>();
+  private List<Integer> tserverPorts = new ArrayList<>();
 
   // Client we can use for common operations.
   private final KuduClient syncClient;
@@ -118,6 +119,7 @@ public class MiniKuduCluster implements AutoCloseable {
     List<Integer> ports = TestUtils.findFreePorts(startPort, numTservers * 2);
     for (int i = 0; i < numTservers; i++) {
       int rpcPort = ports.get(i * 2);
+      tserverPorts.add(rpcPort);
       String dataDirPath = baseDirPath + "/ts-" + i + "-" + now;
       String flagsPath = TestUtils.getFlagsPath();
       String[] tsCmdLine = {
@@ -296,6 +298,28 @@ public class MiniKuduCluster implements AutoCloseable {
   }
 
   /**
+   * Kills all tablet servers.
+   * @throws InterruptedException
+   */
+  public void killTabletServers() throws InterruptedException {
+    for (Process tserver : tserverProcesses.values()) {
+      tserver.destroy();
+      tserver.waitFor();
+    }
+    tserverProcesses.clear();
+  }
+
+  /**
+   * Restarts the dead tablet servers on the port.
+   * @throws Exception
+   */
+  public void restartDeadTabletServers() throws Exception {
+    for (int port : tserverPorts) {
+      restartDeadTabletServerOnPort(port);
+    }
+  }
+
+  /**
    * Kills the master listening on the provided port. Doesn't do anything if the master was
    * already killed.
    * @param port port on which the master is listening on

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/3692233b/java/kudu-client/src/test/java/org/kududb/client/TestAsyncKuduSession.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/test/java/org/kududb/client/TestAsyncKuduSession.java b/java/kudu-client/src/test/java/org/kududb/client/TestAsyncKuduSession.java
index dba1437..c4c2b57 100644
--- a/java/kudu-client/src/test/java/org/kududb/client/TestAsyncKuduSession.java
+++ b/java/kudu-client/src/test/java/org/kududb/client/TestAsyncKuduSession.java
@@ -23,6 +23,7 @@ import org.kududb.tserver.Tserver.TabletServerErrorPB;
 
 import com.stumbleupon.async.Callback;
 import com.stumbleupon.async.Deferred;
+import com.stumbleupon.async.DeferredGroupException;
 import com.stumbleupon.async.TimeoutException;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -148,6 +149,28 @@ public class TestAsyncKuduSession extends BaseKuduTest {
     }
   }
 
+  /** Regression test for a failure to correctly handle a timeout when flushing a batch.
*/
+  @Test
+  public void testInsertIntoUnavailableTablet() throws Exception {
+    killTabletServers();
+    try {
+      AsyncKuduSession session = client.newSession();
+      session.setTimeoutMillis(1);
+      session.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH);
+      Insert insert = createInsert(1);
+      session.apply(insert);
+      try {
+        session.flush().join();
+        fail("expected exception");
+      } catch (DeferredGroupException e) {
+        assertEquals(1, e.results().size());
+        assertTrue(e.results().get(0).toString().contains("timeout"));
+      }
+    } finally {
+      restartTabletServers();
+    }
+  }
+
   @Test(timeout = 100000)
   public void test() throws Exception {
 


Mime
View raw message