Index: src/main/java/org/apache/hadoop/hbase/catalog/CatalogTracker.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/catalog/CatalogTracker.java (revision 1333302) +++ src/main/java/org/apache/hadoop/hbase/catalog/CatalogTracker.java (working copy) @@ -456,7 +456,9 @@ LOG.debug("Exception connecting to " + address); } catch (IOException ioe) { Throwable cause = ioe.getCause(); - if (cause != null && cause instanceof EOFException) { + if (ioe instanceof ConnectException) { + // Catch. Connect refused. + } else if (cause != null && cause instanceof EOFException) { // Catch. Other end disconnected us. } else if (cause != null && cause.getMessage() != null && cause.getMessage().toLowerCase().contains("connection reset")) { Index: src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java (revision 1333302) +++ src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java (working copy) @@ -347,18 +347,31 @@ while (true) { try { return getProxy(protocol, clientVersion, addr, conf, rpcTimeout); - } catch(ConnectException se) { // namenode has not been started - ioe = se; - if (maxAttempts >= 0 && ++reconnectAttempts >= maxAttempts) { - LOG.info("Server at " + addr + " could not be reached after " + - reconnectAttempts + " tries, giving up."); - throw new RetriesExhaustedException("Failed setting up proxy " + - protocol + " to " + addr.toString() + " after attempts=" + - reconnectAttempts, se); - } } catch(SocketTimeoutException te) { // namenode is busy LOG.info("Problem connecting to server: " + addr); ioe = te; + } catch (IOException ioex) { + // We only handle the ConnectException. + ConnectException ce = null; + if (ioex instanceof ConnectException) { + ce = (ConnectException) ioex; + ioe = ce; + } else if (ioex.getCause() != null + && ioex.getCause() instanceof ConnectException) { + ce = (ConnectException) ioex.getCause(); + ioe = ce; + } else if (ioex.getMessage().toLowerCase() + .contains("connection refused")) { + ce = new ConnectException(ioex.getMessage()); + ioe = ce; + } else { + // This is the exception we can't handle. + ioe = ioex; + } + if (ce != null) { + handleConnectionException(++reconnectAttempts, maxAttempts, protocol, + addr, ce); + } } // check if timed out if (System.currentTimeMillis()-timeout >= startTime) { @@ -375,6 +388,25 @@ } /** + * @param retries current retried times. + * @param maxAttmpts max attempts + * @param protocol protocol interface + * @param addr address of remote service + * @param ce ConnectException + * @throws RetriesExhaustedException + */ + private static void handleConnectionException(int retries, int maxAttmpts, + Class protocol, InetSocketAddress addr, ConnectException ce) + throws RetriesExhaustedException { + if (maxAttmpts >= 0 && retries >= maxAttmpts) { + LOG.info("Server at " + addr + " could not be reached after " + + maxAttmpts + " tries, giving up."); + throw new RetriesExhaustedException("Failed setting up proxy " + protocol + + " to " + addr.toString() + " after attempts=" + maxAttmpts, ce); + } + } + + /** * Construct a client-side proxy object that implements the named protocol, * talking to a server at the named address. *