You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2017/11/08 05:12:32 UTC

hbase git commit: HBASE-19205 Backport HBASE-18441 ZookeeperWatcher#interruptedException should throw exception

Repository: hbase
Updated Branches:
  refs/heads/branch-1.2 9f0a450e5 -> eb8560cab


HBASE-19205 Backport HBASE-18441 ZookeeperWatcher#interruptedException should throw exception


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

Branch: refs/heads/branch-1.2
Commit: eb8560cab55018236f502f25a77c69610f3c56da
Parents: 9f0a450
Author: stack <st...@ve0528.halxg.cloudera.com>
Authored: Tue Nov 7 21:10:42 2017 -0800
Committer: Michael Stack <st...@apache.org>
Committed: Tue Nov 7 21:12:22 2017 -0800

----------------------------------------------------------------------
 .../hbase/zookeeper/ZooKeeperWatcher.java       | 30 ++++++++++++--------
 .../hadoop/hbase/zookeeper/TestZKUtil.java      | 23 +++++++++++++++
 .../hbase/zookeeper/ZooKeeperMainServer.java    |  5 ++--
 3 files changed, 44 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/eb8560ca/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java
index 73a3a9e..c50c230 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java
@@ -249,7 +249,7 @@ public class ZooKeeperWatcher implements Watcher, Abortable, Closeable {
     } catch(KeeperException.NoNodeException nne) {
       return;
     } catch(InterruptedException ie) {
-      interruptedException(ie);
+      interruptedExceptionNoThrow(ie, false);
     } catch (IOException|KeeperException e) {
       LOG.warn("Received exception while checking and setting zookeeper ACLs", e);
     }
@@ -747,20 +747,26 @@ public class ZooKeeperWatcher implements Watcher, Abortable, Closeable {
 
   /**
    * Handles InterruptedExceptions in client calls.
-   * <p>
-   * This may be temporary but for now this gives one place to deal with these.
-   * <p>
-   * TODO: Currently, this method does nothing.
-   *       Is this ever expected to happen?  Do we abort or can we let it run?
-   *       Maybe this should be logged as WARN?  It shouldn't happen?
-   * <p>
-   * @param ie
+   * @param ie the InterruptedException instance thrown
+   * @throws KeeperException the exception to throw, transformed from the InterruptedException
+   */
+  public void interruptedException(InterruptedException ie) throws KeeperException {
+    interruptedExceptionNoThrow(ie, true);
+    // Throw a system error exception to let upper level handle it
+    throw new KeeperException.SystemErrorException();
+  }
+
+  /**
+   * Log the InterruptedException and interrupt current thread
+   * @param ie The IterruptedException to log
+   * @param throwLater Whether we will throw the exception latter
    */
-  public void interruptedException(InterruptedException ie) {
-    LOG.debug(prefix("Received InterruptedException, doing nothing here"), ie);
+  public void interruptedExceptionNoThrow(InterruptedException ie, boolean throwLater) {
+    LOG.debug(prefix("Received InterruptedException, will interrupt current thread"
+        + (throwLater ? " and rethrow a SystemErrorException" : "")),
+      ie);
     // At least preserver interrupt.
     Thread.currentThread().interrupt();
-    // no-op
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hbase/blob/eb8560ca/hbase-client/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKUtil.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKUtil.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKUtil.java
index 1099e5e..83e29e2 100644
--- a/hbase-client/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKUtil.java
+++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKUtil.java
@@ -27,6 +27,7 @@ import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.ZooKeeperConnectionException;
 import org.apache.hadoop.hbase.security.Superusers;
 import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooDefs.Perms;
 import org.apache.zookeeper.data.ACL;
@@ -34,6 +35,7 @@ import org.apache.zookeeper.data.Id;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
+import org.mockito.Mockito;
 
 /**
  *
@@ -78,4 +80,25 @@ public class TestZKUtil {
     Assert.assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "user2"))));
     Assert.assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "user3"))));
   }
+
+  @Test
+  public void testInterruptedDuringAction()
+      throws ZooKeeperConnectionException, IOException, KeeperException, InterruptedException {
+    final RecoverableZooKeeper recoverableZk = Mockito.mock(RecoverableZooKeeper.class);
+    ZooKeeperWatcher zkw = new ZooKeeperWatcher(HBaseConfiguration.create(), "unittest", null) {
+      @Override
+      public RecoverableZooKeeper getRecoverableZooKeeper() {
+        return recoverableZk;
+      }
+    };
+    Mockito.doThrow(new InterruptedException()).when(recoverableZk)
+        .getChildren(zkw.baseZNode, null);
+    try {
+      ZKUtil.listChildrenNoWatch(zkw, zkw.baseZNode);
+    } catch (KeeperException.SystemErrorException e) {
+      // expected
+      return;
+    }
+    Assert.fail("Should have thrown KeeperException but not");
+  }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/eb8560ca/hbase-server/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperMainServer.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperMainServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperMainServer.java
index 92460fe..ac466a4 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperMainServer.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperMainServer.java
@@ -54,8 +54,9 @@ public class ZooKeeperMainServer {
       long startTime = System.currentTimeMillis();
       while (!this.zk.getState().isConnected()) {
         Thread.sleep(1);
-        if ((System.currentTimeMillis() - startTime) > 10000) {
-          throw new InterruptedException("Failed connect " + this.zk);
+        long elapsed = System.currentTimeMillis() - startTime;
+        if (elapsed > 30000) {
+          throw new InterruptedException("Failed connect after " + elapsed + "ms; " + this.zk);
         }
       }
     }