hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject hbase git commit: HBASE-15856 Don't cache unresolved addresses for connections
Date Fri, 20 May 2016 19:31:39 GMT
Repository: hbase
Updated Branches:
  refs/heads/0.98 b8cb2e43d -> 5d2cd28c6


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/5d2cd28c
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/5d2cd28c
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/5d2cd28c

Branch: refs/heads/0.98
Commit: 5d2cd28c606b928ec4725e7c3fe194b8d1b9b82b
Parents: b8cb2e4
Author: Gary Helmling <garyh@apache.org>
Authored: Thu May 19 12:43:18 2016 -0700
Committer: Gary Helmling <garyh@apache.org>
Committed: Fri May 20 12:29:40 2016 -0700

----------------------------------------------------------------------
 .../org/apache/hadoop/hbase/ipc/RpcClient.java  |  7 +-
 .../hadoop/hbase/client/TestClientTimeouts.java |  5 +-
 .../client/TestConnectionImplementation.java    | 95 ++++++++++++++++++++
 .../hbase/master/TestMasterNoCluster.java       | 15 ++--
 4 files changed, 110 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/5d2cd28c/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcClient.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcClient.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcClient.java
index 08a5182..5e2ce90 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcClient.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcClient.java
@@ -1721,7 +1721,7 @@ public class RpcClient {
    * @return A blocking rpc channel that goes via this rpc client instance.
    */
   public BlockingRpcChannel createBlockingRpcChannel(final ServerName sn,
-      final User ticket, final int rpcTimeout) {
+      final User ticket, final int rpcTimeout) throws UnknownHostException {
     return new BlockingRpcChannelImplementation(this, sn, ticket, rpcTimeout);
   }
 
@@ -1744,8 +1744,11 @@ public class RpcClient {
     private final User ticket;
 
     protected BlockingRpcChannelImplementation(final RpcClient rpcClient, final ServerName
sn,
-        final User ticket, final int rpcTimeout) {
+        final User ticket, final int rpcTimeout) throws UnknownHostException {
       this.isa = new InetSocketAddress(sn.getHostname(), sn.getPort());
+      if (this.isa.isUnresolved()) {
+        throw new UnknownHostException(sn.getHostname());
+      }
       this.rpcClient = rpcClient;
       // Set the rpc timeout to be the minimum of configured timeout and whatever the current
       // thread local setting is.

http://git-wip-us.apache.org/repos/asf/hbase/blob/5d2cd28c/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 2e1a9b7..322a37a 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
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 import java.net.SocketTimeoutException;
+import java.net.UnknownHostException;
 import java.util.Random;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -129,7 +130,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);
       }
     };
@@ -144,7 +145,7 @@ public class TestClientTimeouts {
     private static AtomicInteger invokations = new AtomicInteger();
 
     RandomTimeoutBlockingRpcChannel(final RpcClient 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/5d2cd28c/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..26f7ba7
--- /dev/null
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestConnectionImplementation.java
@@ -0,0 +1,95 @@
+/*
+ * 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 HConnectionManager.HConnectionImplementation conn;
+
+  @BeforeClass
+  public static void setupBeforeClass() throws Exception {
+    testUtil = HBaseTestingUtility.createLocalHTU();
+    testUtil.startMiniCluster();
+    conn = (HConnectionManager.HConnectionImplementation) HConnectionManager.createConnection(
+        testUtil.getConfiguration());
+  }
+
+  @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/5d2cd28c/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 5471888..a2a1fce 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
@@ -172,6 +172,12 @@ public class TestMasterNoCluster {
     };
     rs1.setNextResults(HRegionInfo.FIRST_META_REGIONINFO.getRegionName(), results);
 
+    // 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 HConnection mockedConnection = HConnectionTestingUtility.getMockedConnectionAndDecorate(
+        TESTUTIL.getConfiguration(), rs0, rs0, rs0.getServerName(),
+        HRegionInfo.FIRST_META_REGIONINFO);
     // Create master.  Subclass to override a few methods so we can insert mocks
     // and get notification on transitions.  We need to fake out any rpcs the
     // master does opening/closing regions.  Also need to fake out the address
@@ -202,14 +208,7 @@ public class TestMasterNoCluster {
       CatalogTracker createCatalogTracker(ZooKeeperWatcher zk,
           Configuration conf, Abortable abortable)
       throws IOException {
-        // Insert a mock for the connection used by the CatalogTracker.  Any
-        // regionserver should do.  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.
-        HConnection connection =
-          HConnectionTestingUtility.getMockedConnectionAndDecorate(TESTUTIL.getConfiguration(),
-            rs0, rs0, rs0.getServerName(), HRegionInfo.FIRST_META_REGIONINFO);
-        return new CatalogTracker(zk, conf, connection, abortable);
+        return new CatalogTracker(zk, conf, mockedConnection, abortable);
       }
 
       @Override


Mime
View raw message