hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From la...@apache.org
Subject git commit: HBASE-9746 RegionServer can't start when replication tries to replicate to an unknown host.
Date Tue, 26 Aug 2014 00:02:48 GMT
Repository: hbase
Updated Branches:
  refs/heads/0.94 6283ff920 -> 2928e6447


HBASE-9746 RegionServer can't start when replication tries to replicate to an unknown host.


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

Branch: refs/heads/0.94
Commit: 2928e64474029693d2a7a9c960fcf8170650ff70
Parents: 6283ff9
Author: Lars Hofhansl <larsh@apache.org>
Authored: Mon Aug 25 17:02:24 2014 -0700
Committer: Lars Hofhansl <larsh@apache.org>
Committed: Mon Aug 25 17:02:24 2014 -0700

----------------------------------------------------------------------
 .../hbase/zookeeper/RecoverableZooKeeper.java   | 75 ++++++++++++--------
 .../apache/hadoop/hbase/zookeeper/ZKConfig.java |  8 +--
 .../hbase/zookeeper/ZooKeeperWatcher.java       |  4 +-
 3 files changed, 50 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/2928e644/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java b/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java
index ba5db2d..3cb6d2d 100644
--- a/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java
+++ b/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java
@@ -95,7 +95,6 @@ public class RecoverableZooKeeper {
   public RecoverableZooKeeper(String quorumServers, int sessionTimeout,
       Watcher watcher, int maxRetries, int retryIntervalMillis) 
   throws IOException {
-    this.zk = new ZooKeeper(quorumServers, sessionTimeout, watcher);
     this.retryCounterFactory =
       new RetryCounterFactory(maxRetries, retryIntervalMillis);
 
@@ -106,15 +105,35 @@ public class RecoverableZooKeeper {
     this.watcher = watcher;
     this.sessionTimeout = sessionTimeout;
     this.quorumServers = quorumServers;
+    try {checkZk();} catch (Exception x) {/* ignore */}
+  }
+
+  /**
+   * Try to create a Zookeeper connection. Turns any exception encountered into a
+   * {@link KeeperException.OperationTimeoutException} so it can retried.
+   * @return The created Zookeeper connection object
+   * @throws KeeperException
+   */
+  protected ZooKeeper checkZk() throws KeeperException {
+    if (this.zk == null) {
+      try {
+        this.zk = new ZooKeeper(quorumServers, sessionTimeout, watcher);
+      } catch (Exception uhe) {
+        LOG.warn("Unable to create ZooKeeper Connection", uhe);
+        throw new KeeperException.OperationTimeoutException();
+      }
+    }
+    return zk;
   }
 
   public void reconnectAfterExpiration()
-        throws IOException, InterruptedException {
-    LOG.info("Closing dead ZooKeeper connection, session" +
-      " was: 0x"+Long.toHexString(zk.getSessionId()));
-    zk.close();
-    this.zk = new ZooKeeper(this.quorumServers,
-      this.sessionTimeout, this.watcher);
+        throws IOException, KeeperException, InterruptedException {
+    if (zk != null) {
+      LOG.info("Closing dead ZooKeeper connection, session" +
+        " was: 0x"+Long.toHexString(zk.getSessionId()));
+      zk.close();
+    }
+    checkZk();
     LOG.info("Recreated a ZooKeeper, session" +
       " is: 0x"+Long.toHexString(zk.getSessionId()));
   }
@@ -130,7 +149,7 @@ public class RecoverableZooKeeper {
     boolean isRetry = false; // False for first attempt, true for all retries.
     while (true) {
       try {
-        zk.delete(path, version);
+        checkZk().delete(path, version);
         return;
       } catch (KeeperException e) {
         switch (e.code()) {
@@ -169,7 +188,7 @@ public class RecoverableZooKeeper {
     RetryCounter retryCounter = retryCounterFactory.create();
     while (true) {
       try {
-        return zk.exists(path, watcher);
+        return checkZk().exists(path, watcher);
       } catch (KeeperException e) {
         switch (e.code()) {
           case CONNECTIONLOSS:
@@ -196,7 +215,7 @@ public class RecoverableZooKeeper {
     RetryCounter retryCounter = retryCounterFactory.create();
     while (true) {
       try {
-        return zk.exists(path, watch);
+        return checkZk().exists(path, watch);
       } catch (KeeperException e) {
         switch (e.code()) {
           case CONNECTIONLOSS:
@@ -233,7 +252,7 @@ public class RecoverableZooKeeper {
     RetryCounter retryCounter = retryCounterFactory.create();
     while (true) {
       try {
-        return zk.getChildren(path, watcher);
+        return checkZk().getChildren(path, watcher);
       } catch (KeeperException e) {
         switch (e.code()) {
           case CONNECTIONLOSS:
@@ -260,7 +279,7 @@ public class RecoverableZooKeeper {
     RetryCounter retryCounter = retryCounterFactory.create();
     while (true) {
       try {
-        return zk.getChildren(path, watch);
+        return checkZk().getChildren(path, watch);
       } catch (KeeperException e) {
         switch (e.code()) {
           case CONNECTIONLOSS:
@@ -287,7 +306,7 @@ public class RecoverableZooKeeper {
     RetryCounter retryCounter = retryCounterFactory.create();
     while (true) {
       try {
-        byte[] revData = zk.getData(path, watcher, stat);       
+        byte[] revData = checkZk().getData(path, watcher, stat);       
         return this.removeMetaData(revData);
       } catch (KeeperException e) {
         switch (e.code()) {
@@ -315,7 +334,7 @@ public class RecoverableZooKeeper {
     RetryCounter retryCounter = retryCounterFactory.create();
     while (true) {
       try {
-        byte[] revData = zk.getData(path, watch, stat);
+        byte[] revData = checkZk().getData(path, watch, stat);
         return this.removeMetaData(revData);
       } catch (KeeperException e) {
         switch (e.code()) {
@@ -346,7 +365,7 @@ public class RecoverableZooKeeper {
     byte[] newData = appendMetaData(data);
     while (true) {
       try {
-        return zk.setData(path, newData, version);
+        return checkZk().setData(path, newData, version);
       } catch (KeeperException e) {
         switch (e.code()) {
           case CONNECTIONLOSS:
@@ -358,7 +377,7 @@ public class RecoverableZooKeeper {
             // try to verify whether the previous setData success or not
             try{
               Stat stat = new Stat();
-              byte[] revData = zk.getData(path, false, stat);
+              byte[] revData = checkZk().getData(path, false, stat);
               if (Bytes.equals(revData, newData)) {
                 // the bad version is caused by previous successful setData
                 return stat;
@@ -418,7 +437,7 @@ public class RecoverableZooKeeper {
     boolean isRetry = false; // False for first attempt, true for all retries.
     while (true) {
       try {
-        return zk.create(path, data, acl, createMode);
+        return checkZk().create(path, data, acl, createMode);
       } catch (KeeperException e) {
         switch (e.code()) {
           case NODEEXISTS:
@@ -426,7 +445,7 @@ public class RecoverableZooKeeper {
               // If the connection was lost, there is still a possibility that
               // we have successfully created the node at our previous attempt,
               // so we read the node and compare. 
-              byte[] currentData = zk.getData(path, false, null);
+              byte[] currentData = checkZk().getData(path, false, null);
               if (currentData != null &&
                   Bytes.compareTo(currentData, data) == 0) { 
                 // We successfully created a non-sequential node
@@ -473,7 +492,7 @@ public class RecoverableZooKeeper {
           }
         }
         first = false;
-        return zk.create(newPath, data, acl, createMode);
+        return checkZk().create(newPath, data, acl, createMode);
       } catch (KeeperException e) {
         switch (e.code()) {
           case CONNECTIONLOSS:
@@ -528,7 +547,7 @@ public class RecoverableZooKeeper {
     Iterable<Op> multiOps = prepareZKMulti(ops);
     while (true) {
       try {
-        return zk.multi(multiOps);
+        return checkZk().multi(multiOps);
       } catch (KeeperException e) {
         switch (e.code()) {
           case CONNECTIONLOSS:
@@ -553,11 +572,11 @@ public class RecoverableZooKeeper {
     String parent = path.substring(0, lastSlashIdx);
     String nodePrefix = path.substring(lastSlashIdx+1);
 
-    List<String> nodes = zk.getChildren(parent, false);
+    List<String> nodes = checkZk().getChildren(parent, false);
     List<String> matching = filterByPrefix(nodes, nodePrefix);
     for (String node : matching) {
       String nodePath = parent + "/" + node;
-      Stat stat = zk.exists(nodePath, false);
+      Stat stat = checkZk().exists(nodePath, false);
       if (stat != null) {
         return nodePath;
       }
@@ -602,15 +621,15 @@ public class RecoverableZooKeeper {
   }
 
   public long getSessionId() {
-    return zk.getSessionId();
+    return zk == null ? null : zk.getSessionId();
   }
 
   public void close() throws InterruptedException {
-    zk.close();
+    if (zk != null) zk.close();
   }
 
   public States getState() {
-    return zk.getState();
+    return zk == null ? null : zk.getState();
   }
 
   public ZooKeeper getZooKeeper() {
@@ -618,11 +637,11 @@ public class RecoverableZooKeeper {
   }
 
   public byte[] getSessionPasswd() {
-    return zk.getSessionPasswd();
+    return zk == null ? null : zk.getSessionPasswd();
   }
 
-  public void sync(String path, AsyncCallback.VoidCallback cb, Object ctx) {
-    this.zk.sync(path, null, null);
+  public void sync(String path, AsyncCallback.VoidCallback cb, Object ctx) throws KeeperException
{
+    checkZk().sync(path, null, null);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hbase/blob/2928e644/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKConfig.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKConfig.java b/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKConfig.java
index 4cc9c01..9161b85 100644
--- a/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKConfig.java
+++ b/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKConfig.java
@@ -196,13 +196,7 @@ public class ZKConfig {
       else if (key.startsWith("server.")) {
         String host = value.substring(0, value.indexOf(':'));
         servers.add(host);
-        try {
-          //noinspection ResultOfMethodCallIgnored
-          InetAddress.getByName(host);
-          anyValid = true;
-        } catch (UnknownHostException e) {
-          LOG.warn(StringUtils.stringifyException(e));
-        }
+        anyValid = true;
       }
     }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/2928e644/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java b/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java
index e023692..81081d5 100644
--- a/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java
+++ b/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java
@@ -271,7 +271,7 @@ public class ZooKeeperWatcher implements Watcher, Abortable {
     return recoverableZooKeeper;
   }
 
-  public void reconnectAfterExpiration() throws IOException, InterruptedException {
+  public void reconnectAfterExpiration() throws IOException, KeeperException, InterruptedException
{
     recoverableZooKeeper.reconnectAfterExpiration();
   }
 
@@ -399,7 +399,7 @@ public class ZooKeeperWatcher implements Watcher, Abortable {
    * previously read version and data.  We want to ensure that the version read
    * is up-to-date from when we begin the operation.
    */
-  public void sync(String path) {
+  public void sync(String path) throws KeeperException {
     this.recoverableZooKeeper.sync(path, null, null);
   }
 


Mime
View raw message