Return-Path: X-Original-To: apmail-hadoop-common-commits-archive@www.apache.org Delivered-To: apmail-hadoop-common-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 93EAD9C12 for ; Tue, 27 Mar 2012 01:31:52 +0000 (UTC) Received: (qmail 11242 invoked by uid 500); 27 Mar 2012 01:31:52 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 11189 invoked by uid 500); 27 Mar 2012 01:31:52 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 11180 invoked by uid 99); 27 Mar 2012 01:31:52 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Mar 2012 01:31:52 +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; Tue, 27 Mar 2012 01:31:50 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 8D7492388865; Tue, 27 Mar 2012 01:31:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1305704 - in /hadoop/common/trunk/hadoop-common-project/hadoop-common: CHANGES.txt src/main/java/org/apache/hadoop/ha/HealthMonitor.java src/main/java/org/apache/hadoop/ipc/RPC.java src/test/java/org/apache/hadoop/ipc/TestRPC.java Date: Tue, 27 Mar 2012 01:31:30 -0000 To: common-commits@hadoop.apache.org From: suresh@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120327013130.8D7492388865@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: suresh Date: Tue Mar 27 01:31:29 2012 New Revision: 1305704 URL: http://svn.apache.org/viewvc?rev=1305704&view=rev Log: HADOOP-8202. RPC stopProxy() does not close the proxy correctly. Contributed by Hari Mankude. Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HealthMonitor.java hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RPC.java hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestRPC.java Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1305704&r1=1305703&r2=1305704&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt (original) +++ hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt Tue Mar 27 01:31:29 2012 @@ -286,6 +286,9 @@ Release 0.23.3 - UNRELEASED HADOOP-8204. TestHealthMonitor fails occasionally (todd) + HADOOP-8202. RPC stopProxy() does not close the proxy correctly. + (Hari Mankude via suresh) + BREAKDOWN OF HADOOP-7454 SUBTASKS HADOOP-7455. HA: Introduce HA Service Protocol Interface. (suresh) Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HealthMonitor.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HealthMonitor.java?rev=1305704&r1=1305703&r2=1305704&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HealthMonitor.java (original) +++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HealthMonitor.java Tue Mar 27 01:31:29 2012 @@ -17,6 +17,7 @@ */ package org.apache.hadoop.ha; +import java.io.Closeable; import java.io.IOException; import java.util.Collections; import java.util.LinkedList; @@ -194,7 +195,9 @@ class HealthMonitor { } catch (Throwable t) { LOG.warn("Transport-level exception trying to monitor health of " + targetToMonitor + ": " + t.getLocalizedMessage()); - RPC.stopProxy(proxy); + if (proxy instanceof Closeable) { + RPC.stopProxy(proxy); + } proxy = null; enterState(State.SERVICE_NOT_RESPONDING); Thread.sleep(sleepAfterDisconnectMillis); Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RPC.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RPC.java?rev=1305704&r1=1305703&r2=1305704&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RPC.java (original) +++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RPC.java Tue Mar 27 01:31:29 2012 @@ -39,6 +39,7 @@ import javax.net.SocketFactory; import org.apache.commons.logging.*; +import org.apache.hadoop.HadoopIllegalArgumentException; import org.apache.hadoop.io.*; import org.apache.hadoop.ipc.Client.ConnectionId; import org.apache.hadoop.ipc.RpcPayloadHeader.RpcKind; @@ -572,38 +573,41 @@ public class RPC { } /** - * Stop this proxy and release its invoker's resource by getting the - * invocation handler for the given proxy object and calling - * {@link Closeable#close} if that invocation handler implements - * {@link Closeable}. + * Stop the proxy. Proxy must either implement {@link Closeable} or must have + * associated {@link RpcInvocationHandler}. * - * @param proxy the RPC proxy object to be stopped + * @param proxy + * the RPC proxy object to be stopped + * @throws HadoopIllegalArgumentException + * if the proxy does not implement {@link Closeable} interface or + * does not have closeable {@link InvocationHandler} */ public static void stopProxy(Object proxy) { - if (proxy instanceof ProtocolTranslator) { - RPC.stopProxy(((ProtocolTranslator)proxy) - .getUnderlyingProxyObject()); - return; + if (proxy == null) { + throw new HadoopIllegalArgumentException( + "Cannot close proxy since it is null"); } - - InvocationHandler invocationHandler = null; try { - invocationHandler = Proxy.getInvocationHandler(proxy); - } catch (IllegalArgumentException e) { - LOG.error("Tried to call RPC.stopProxy on an object that is not a proxy.", e); - } - if (proxy != null && invocationHandler != null && - invocationHandler instanceof Closeable) { - try { - ((Closeable)invocationHandler).close(); - } catch (IOException e) { - LOG.error("Stopping RPC invocation handler caused exception", e); + if (proxy instanceof Closeable) { + ((Closeable) proxy).close(); + return; + } else { + InvocationHandler handler = Proxy.getInvocationHandler(proxy); + if (handler instanceof Closeable) { + ((Closeable) handler).close(); + return; + } } - } else { - LOG.error("Could not get invocation handler " + invocationHandler + - " for proxy class " + (proxy == null ? null : proxy.getClass()) + - ", or invocation handler is not closeable."); + } catch (IOException e) { + LOG.error("Closing proxy or invocation handler caused exception", e); + } catch (IllegalArgumentException e) { + LOG.error("RPC.stopProxy called on non proxy.", e); } + + throw new HadoopIllegalArgumentException( + "Cannot close proxy - is not Closeable or " + + "does not provide closeable invocation handler " + + proxy.getClass()); } /** Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestRPC.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestRPC.java?rev=1305704&r1=1305703&r2=1305704&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestRPC.java (original) +++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestRPC.java Tue Mar 27 01:31:29 2012 @@ -33,6 +33,7 @@ import java.util.Arrays; import javax.net.SocketFactory; import org.apache.commons.logging.*; +import org.apache.hadoop.HadoopIllegalArgumentException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.CommonConfigurationKeys; import org.apache.hadoop.io.UTF8; @@ -584,9 +585,10 @@ public class TestRPC { * Test stopping a non-registered proxy * @throws Exception */ - @Test + @Test(expected=HadoopIllegalArgumentException.class) public void testStopNonRegisteredProxy() throws Exception { RPC.stopProxy(mock(TestProtocol.class)); + RPC.stopProxy(null); } @Test