hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject hbase git commit: HBASE-13067. Fix caching of stubs to allow IP address changes of restarted remote servers.
Date Tue, 24 Feb 2015 06:15:10 GMT
Repository: hbase
Updated Branches:
  refs/heads/master 4a74f5e82 -> 70412d886


HBASE-13067. Fix caching of stubs to allow IP address changes of restarted remote servers.


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

Branch: refs/heads/master
Commit: 70412d886c647d3669827145f2790417fab6d9c1
Parents: 4a74f5e
Author: Devaraj Das <ddas@apache.org>
Authored: Mon Feb 23 22:15:03 2015 -0800
Committer: Devaraj Das <ddas@apache.org>
Committed: Mon Feb 23 22:15:03 2015 -0800

----------------------------------------------------------------------
 .../hadoop/hbase/client/ConnectionManager.java  | 25 ++++++++++++++++----
 1 file changed, 20 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/70412d88/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java
index b1f43d4..0126df5 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java
@@ -19,10 +19,13 @@
 package org.apache.hadoop.hbase.client;
 
 import javax.annotation.Nullable;
+
 import java.io.Closeable;
 import java.io.IOException;
 import java.io.InterruptedIOException;
 import java.lang.reflect.UndeclaredThrowableException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashSet;
@@ -44,6 +47,7 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.protobuf.BlockingRpcChannel;
 import com.google.protobuf.RpcController;
 import com.google.protobuf.ServiceException;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
@@ -1487,7 +1491,7 @@ final class ConnectionManager {
             throw new MasterNotRunningException(sn + " is dead.");
           }
           // Use the security info interface name as our stub key
-          String key = getStubKey(getServiceName(), sn.getHostAndPort());
+          String key = getStubKey(getServiceName(), sn.getHostname(), sn.getPort());
           connectionLock.putIfAbsent(key, key);
           Object stub = null;
           synchronized (connectionLock.get(key)) {
@@ -1576,7 +1580,7 @@ final class ConnectionManager {
         throw new RegionServerStoppedException(serverName + " is dead.");
       }
       String key = getStubKey(AdminService.BlockingInterface.class.getName(),
-        serverName.getHostAndPort());
+          serverName.getHostname(), serverName.getPort());
       this.connectionLock.putIfAbsent(key, key);
       AdminService.BlockingInterface stub = null;
       synchronized (this.connectionLock.get(key)) {
@@ -1597,7 +1601,8 @@ final class ConnectionManager {
       if (isDeadServer(sn)) {
         throw new RegionServerStoppedException(sn + " is dead.");
       }
-      String key = getStubKey(ClientService.BlockingInterface.class.getName(), sn.getHostAndPort());
+      String key = getStubKey(ClientService.BlockingInterface.class.getName(), sn.getHostname(),
+          sn.getPort());
       this.connectionLock.putIfAbsent(key, key);
       ClientService.BlockingInterface stub = null;
       synchronized (this.connectionLock.get(key)) {
@@ -1614,8 +1619,18 @@ final class ConnectionManager {
       return stub;
     }
 
-    static String getStubKey(final String serviceName, final String rsHostnamePort) {
-      return serviceName + "@" + rsHostnamePort;
+    static String getStubKey(final String serviceName, final String rsHostname, int port)
{
+      // Sometimes, servers go down and they come back up with the same hostname but a different
+      // IP address. Force a resolution of the rsHostname by trying to instantiate an
+      // InetSocketAddress, and this way we will rightfully get a new stubKey.
+      // Also, include the hostname in the key so as to take care of those cases where the
+      // DNS name is different but IP address remains the same.
+      InetAddress i =  new InetSocketAddress(rsHostname, port).getAddress();
+      String address = rsHostname;
+      if (i != null) {
+        address = i.getHostAddress() + "-" + rsHostname;
+      }
+      return serviceName + "@" + address + ":" + port;
     }
 
     private ZooKeeperKeepAliveConnection keepAliveZookeeper;


Mime
View raw message