Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9E95DCD0C for ; Thu, 3 May 2012 16:27:10 +0000 (UTC) Received: (qmail 35755 invoked by uid 500); 3 May 2012 16:27:10 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 35684 invoked by uid 500); 3 May 2012 16:27:09 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 35675 invoked by uid 99); 3 May 2012 16:27:09 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 May 2012 16:27:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 May 2012 16:27:06 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 81EDF2388B3A for ; Thu, 3 May 2012 16:26:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1333530 - in /hbase/trunk/src/main/java/org/apache/hadoop/hbase: catalog/CatalogTracker.java ipc/HBaseRPC.java Date: Thu, 03 May 2012 16:26:44 -0000 To: commits@hbase.apache.org From: tedyu@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120503162644.81EDF2388B3A@eris.apache.org> Author: tedyu Date: Thu May 3 16:26:44 2012 New Revision: 1333530 URL: http://svn.apache.org/viewvc?rev=1333530&view=rev Log: HBASE-5883 Backup master is going down due to connection refused exception (Jieshan) Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/catalog/CatalogTracker.java hbase/trunk/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/catalog/CatalogTracker.java URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/catalog/CatalogTracker.java?rev=1333530&r1=1333529&r2=1333530&view=diff ============================================================================== --- hbase/trunk/src/main/java/org/apache/hadoop/hbase/catalog/CatalogTracker.java (original) +++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/catalog/CatalogTracker.java Thu May 3 16:26:44 2012 @@ -577,7 +577,9 @@ public class CatalogTracker { LOG.debug("Unknown host exception connecting to " + sn); } 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")) { Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java?rev=1333530&r1=1333529&r2=1333530&view=diff ============================================================================== --- hbase/trunk/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java (original) +++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java Thu May 3 16:26:44 2012 @@ -235,21 +235,34 @@ public class HBaseRPC { 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) { + if (System.currentTimeMillis() - timeout >= startTime) { throw ioe; } @@ -263,6 +276,25 @@ public class HBaseRPC { } /** + * @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. *