Repository: hbase
Updated Branches:
  refs/heads/branch-1.2 ac3cd465f -> 88c415c2f


HBASE-15856 Don't cache unresolved addresses for connections


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

Branch: refs/heads/branch-1.2
Commit: 88c415c2f9af360fe67bf0805bcee06a0f5b8ab6
Parents: ac3cd46
Author: Gary Helmling <ga...@apache.org>
Authored: Thu May 19 12:43:18 2016 -0700
Committer: Gary Helmling <ga...@apache.org>
Committed: Fri May 20 10:22:51 2016 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/ipc/AbstractRpcClient.java     |  9 +-
 .../hadoop/hbase/client/TestClientTimeouts.java |  5 +-
 .../client/TestConnectionImplementation.java    | 94 ++++++++++++++++++++
 .../hbase/master/TestMasterNoCluster.java       | 17 ++--
 4 files changed, 111 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/88c415c2/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/AbstractRpcClient.java
----------------------------------------------------------------------
diff --git 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/AbstractRpcClient.java 
b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/AbstractRpcClient.java
index ec6332a..6e9f61b 100644
--- 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/AbstractRpcClient.java
+++ 
b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/AbstractRpcClient.java
@@ -30,6 +30,7 @@ import java.net.ConnectException;
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
 import java.net.SocketTimeoutException;
+import java.net.UnknownHostException;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -262,7 +263,7 @@ public abstract class AbstractRpcClient implements 
RpcClient {
 
   @Override
   public BlockingRpcChannel createBlockingRpcChannel(final ServerName sn, 
final User ticket,
-      int defaultOperationTimeout) {
+      int defaultOperationTimeout) throws UnknownHostException {
     return new BlockingRpcChannelImplementation(this, sn, ticket, 
defaultOperationTimeout);
   }
 
@@ -307,8 +308,12 @@ public abstract class AbstractRpcClient implements 
RpcClient {
      * @param channelOperationTimeout - the default timeout when no timeout is 
given
      */
     protected BlockingRpcChannelImplementation(final AbstractRpcClient 
rpcClient,
-        final ServerName sn, final User ticket, int channelOperationTimeout) {
+        final ServerName sn, final User ticket, int channelOperationTimeout)
+        throws UnknownHostException {
       this.isa = new InetSocketAddress(sn.getHostname(), sn.getPort());
+      if (this.isa.isUnresolved()) {
+        throw new UnknownHostException(sn.getHostname());
+      }
       this.rpcClient = rpcClient;
       this.ticket = ticket;
       this.channelOperationTimeout = channelOperationTimeout;

http://git-wip-us.apache.org/repos/asf/hbase/blob/88c415c2/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestClientTimeouts.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestClientTimeouts.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestClientTimeouts.java
index 4a3b776..a475e5a 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestClientTimeouts.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestClientTimeouts.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue;
 
 import java.net.SocketAddress;
 import java.net.SocketTimeoutException;
+import java.net.UnknownHostException;
 import java.util.Random;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -138,7 +139,7 @@ public class TestClientTimeouts {
     // Return my own instance, one that does random timeouts
     @Override
     public BlockingRpcChannel createBlockingRpcChannel(ServerName sn,
-        User ticket, int rpcTimeout) {
+        User ticket, int rpcTimeout) throws UnknownHostException {
       return new RandomTimeoutBlockingRpcChannel(this, sn, ticket, rpcTimeout);
     }
   }
@@ -153,7 +154,7 @@ public class TestClientTimeouts {
     private static AtomicInteger invokations = new AtomicInteger();
 
     RandomTimeoutBlockingRpcChannel(final RpcClientImpl rpcClient, final 
ServerName sn,
-        final User ticket, final int rpcTimeout) {
+        final User ticket, final int rpcTimeout) throws UnknownHostException {
       super(rpcClient, sn, ticket, rpcTimeout);
     }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/88c415c2/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestConnectionImplementation.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestConnectionImplementation.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestConnectionImplementation.java
new file mode 100644
index 0000000..49a2203
--- /dev/null
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestConnectionImplementation.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hbase.client;
+
+import static org.junit.Assert.fail;
+
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.testclassification.ClientTests;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.net.UnknownHostException;
+
+/**
+ * Tests that we fail fast when hostname resolution is not working and do not 
cache
+ * unresolved InetSocketAddresses.
+ */
+@Category({MediumTests.class, ClientTests.class})
+public class TestConnectionImplementation {
+  private static HBaseTestingUtility testUtil;
+  private static ConnectionManager.HConnectionImplementation conn;
+
+  @BeforeClass
+  public static void setupBeforeClass() throws Exception {
+    testUtil = HBaseTestingUtility.createLocalHTU();
+    testUtil.startMiniCluster();
+    conn = (ConnectionManager.HConnectionImplementation) 
testUtil.getConnection();
+  }
+
+  @AfterClass
+  public static void teardownAfterClass() throws Exception {
+    conn.close();
+    testUtil.shutdownMiniCluster();
+  }
+
+  @Test(expected = UnknownHostException.class)
+  public void testGetAdminBadHostname() throws Exception {
+    // verify that we can get an instance with the cluster hostname
+    ServerName master = testUtil.getHBaseCluster().getMaster().getServerName();
+    try {
+      conn.getAdmin(master);
+    } catch (UnknownHostException uhe) {
+      fail("Obtaining admin to the cluster master should have succeeded");
+    }
+
+    // test that we fail to get a client to an unresolvable hostname, which
+    // means it won't be cached
+    ServerName badHost =
+        ServerName.valueOf("unknownhost.example.com:" + 
HConstants.DEFAULT_MASTER_PORT,
+        System.currentTimeMillis());
+    conn.getAdmin(badHost);
+    fail("Obtaining admin to unresolvable hostname should have failed");
+  }
+
+  @Test(expected = UnknownHostException.class)
+  public void testGetClientBadHostname() throws Exception {
+    // verify that we can get an instance with the cluster hostname
+    ServerName rs = 
testUtil.getHBaseCluster().getRegionServer(0).getServerName();
+    try {
+      conn.getClient(rs);
+    } catch (UnknownHostException uhe) {
+      fail("Obtaining client to the cluster regionserver should have 
succeeded");
+    }
+
+    // test that we fail to get a client to an unresolvable hostname, which
+    // means it won't be cached
+    ServerName badHost =
+        ServerName.valueOf("unknownhost.example.com:" + 
HConstants.DEFAULT_REGIONSERVER_PORT,
+        System.currentTimeMillis());
+    conn.getAdmin(badHost);
+    fail("Obtaining client to unresolvable hostname should have failed");
+  }
+}

http://git-wip-us.apache.org/repos/asf/hbase/blob/88c415c2/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterNoCluster.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterNoCluster.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterNoCluster.java
index e27b3a4..4483fce 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterNoCluster.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterNoCluster.java
@@ -180,6 +180,12 @@ public class TestMasterNoCluster {
     // of the 'remote' mocked up regionservers.
     CoordinatedStateManager cp = 
CoordinatedStateManagerFactory.getCoordinatedStateManager(
       TESTUTIL.getConfiguration());
+    // Insert a mock for the connection, use TESTUTIL.getConfiguration rather 
than
+    // the conf from the master; the conf will already have an HConnection
+    // associate so the below mocking of a connection will fail.
+    final ClusterConnection mockedConnection = 
HConnectionTestingUtility.getMockedConnectionAndDecorate(
+        TESTUTIL.getConfiguration(), rs0, rs0, rs0.getServerName(),
+        HRegionInfo.FIRST_META_REGIONINFO);
     HMaster master = new HMaster(conf, cp) {
       InetAddress getRemoteInetAddress(final int port, final long 
serverStartCode)
       throws UnknownHostException {
@@ -207,16 +213,7 @@ public class TestMasterNoCluster {
 
       @Override
       public ClusterConnection getConnection() {
-        // Insert a mock for the connection, use TESTUTIL.getConfiguration 
rather than
-        // the conf from the master; the conf will already have an HConnection
-        // associate so the below mocking of a connection will fail.
-        try {
-          return HConnectionTestingUtility.getMockedConnectionAndDecorate(
-            TESTUTIL.getConfiguration(), rs0, rs0, rs0.getServerName(),
-            HRegionInfo.FIRST_META_REGIONINFO);
-        } catch (IOException e) {
-          return null;
-        }
+        return mockedConnection;
       }
 
       @Override

Reply via email to