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 8644610406 for ; Tue, 30 Jul 2013 06:20:03 +0000 (UTC) Received: (qmail 24596 invoked by uid 500); 30 Jul 2013 06:19:57 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 23968 invoked by uid 500); 30 Jul 2013 06:19:57 -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 23922 invoked by uid 99); 30 Jul 2013 06:19:54 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Jul 2013 06:19:54 +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, 30 Jul 2013 06:19:50 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 122802388831; Tue, 30 Jul 2013 06:19:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1508312 - in /hadoop/common/trunk/hadoop-common-project/hadoop-common: ./ src/main/java/org/apache/hadoop/io/retry/ src/test/java/org/apache/hadoop/io/retry/ Date: Tue, 30 Jul 2013 06:19:28 -0000 To: common-commits@hadoop.apache.org From: suresh@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130730061929.122802388831@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: suresh Date: Tue Jul 30 06:19:28 2013 New Revision: 1508312 URL: http://svn.apache.org/r1508312 Log: HADOOP-9792. Retry the methods that are tagged @AtMostOnce along with @Idempotent. Contributed by Suresh Srinivas. 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/io/retry/FailoverProxyProvider.java hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicies.java hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicy.java hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestFailoverProxy.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=1508312&r1=1508311&r2=1508312&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt (original) +++ hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt Tue Jul 30 06:19:28 2013 @@ -377,6 +377,9 @@ Release 2.1.0-beta - 2013-07-02 HADOOP-9762. RetryCache utility for implementing RPC retries. (Suresh Srinivas via jing9) + HADOOP-9792. Retry the methods that are tagged @AtMostOnce along + with @Idempotent. (suresh) + IMPROVEMENTS HADOOP-9164. Print paths of loaded native libraries in Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/FailoverProxyProvider.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/FailoverProxyProvider.java?rev=1508312&r1=1508311&r2=1508312&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/FailoverProxyProvider.java (original) +++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/FailoverProxyProvider.java Tue Jul 30 06:19:28 2013 @@ -51,8 +51,8 @@ public interface FailoverProxyProvider methodNameToPolicyMap; private Object currentProxy; - RetryInvocationHandler(FailoverProxyProvider proxyProvider, + protected RetryInvocationHandler(FailoverProxyProvider proxyProvider, RetryPolicy retryPolicy) { this(proxyProvider, retryPolicy, Collections.emptyMap()); } @@ -96,11 +96,16 @@ class RetryInvocationHandler implements hasMadeASuccessfulCall = true; return ret; } catch (Exception e) { - boolean isMethodIdempotent = proxyProvider.getInterface() + boolean isIdempotentOrAtMostOnce = proxyProvider.getInterface() .getMethod(method.getName(), method.getParameterTypes()) .isAnnotationPresent(Idempotent.class); + if (!isIdempotentOrAtMostOnce) { + isIdempotentOrAtMostOnce = proxyProvider.getInterface() + .getMethod(method.getName(), method.getParameterTypes()) + .isAnnotationPresent(AtMostOnce.class); + } RetryAction action = policy.shouldRetry(e, retries++, - invocationFailoverCount, isMethodIdempotent); + invocationFailoverCount, isIdempotentOrAtMostOnce); if (action.action == RetryAction.RetryDecision.FAIL) { if (action.reason != null) { LOG.warn("Exception while invoking " + @@ -168,7 +173,7 @@ class RetryInvocationHandler implements } } - private Object invokeMethod(Method method, Object[] args) throws Throwable { + protected Object invokeMethod(Method method, Object[] args) throws Throwable { try { if (!method.isAccessible()) { method.setAccessible(true); Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicies.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicies.java?rev=1508312&r1=1508311&r2=1508312&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicies.java (original) +++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicies.java Tue Jul 30 06:19:28 2013 @@ -153,7 +153,7 @@ public class RetryPolicies { static class TryOnceThenFail implements RetryPolicy { @Override public RetryAction shouldRetry(Exception e, int retries, int failovers, - boolean isMethodIdempotent) throws Exception { + boolean isIdempotentOrAtMostOnce) throws Exception { return RetryAction.FAIL; } } @@ -161,7 +161,7 @@ public class RetryPolicies { static class RetryForever implements RetryPolicy { @Override public RetryAction shouldRetry(Exception e, int retries, int failovers, - boolean isMethodIdempotent) throws Exception { + boolean isIdempotentOrAtMostOnce) throws Exception { return RetryAction.RETRY; } } @@ -196,7 +196,7 @@ public class RetryPolicies { @Override public RetryAction shouldRetry(Exception e, int retries, int failovers, - boolean isMethodIdempotent) throws Exception { + boolean isIdempotentOrAtMostOnce) throws Exception { if (retries >= maxRetries) { return RetryAction.FAIL; } @@ -305,7 +305,7 @@ public class RetryPolicies { @Override public RetryAction shouldRetry(Exception e, int curRetry, int failovers, - boolean isMethodIdempotent) throws Exception { + boolean isIdempotentOrAtMostOnce) throws Exception { final Pair p = searchPair(curRetry); if (p == null) { //no more retries. @@ -435,12 +435,12 @@ public class RetryPolicies { @Override public RetryAction shouldRetry(Exception e, int retries, int failovers, - boolean isMethodIdempotent) throws Exception { + boolean isIdempotentOrAtMostOnce) throws Exception { RetryPolicy policy = exceptionToPolicyMap.get(e.getClass()); if (policy == null) { policy = defaultPolicy; } - return policy.shouldRetry(e, retries, failovers, isMethodIdempotent); + return policy.shouldRetry(e, retries, failovers, isIdempotentOrAtMostOnce); } } @@ -463,7 +463,7 @@ public class RetryPolicies { @Override public RetryAction shouldRetry(Exception e, int retries, int failovers, - boolean isMethodIdempotent) throws Exception { + boolean isIdempotentOrAtMostOnce) throws Exception { RetryPolicy policy = null; if (e instanceof RemoteException) { policy = exceptionNameToPolicyMap.get( @@ -472,7 +472,7 @@ public class RetryPolicies { if (policy == null) { policy = defaultPolicy; } - return policy.shouldRetry(e, retries, failovers, isMethodIdempotent); + return policy.shouldRetry(e, retries, failovers, isIdempotentOrAtMostOnce); } } @@ -533,7 +533,7 @@ public class RetryPolicies { @Override public RetryAction shouldRetry(Exception e, int retries, - int failovers, boolean isMethodIdempotent) throws Exception { + int failovers, boolean isIdempotentOrAtMostOnce) throws Exception { if (failovers >= maxFailovers) { return new RetryAction(RetryAction.RetryDecision.FAIL, 0, "failovers (" + failovers + ") exceeded maximum allowed (" @@ -553,7 +553,7 @@ public class RetryPolicies { calculateExponentialTime(delayMillis, failovers, maxDelayBase)); } else if (e instanceof SocketException || (e instanceof IOException && !(e instanceof RemoteException))) { - if (isMethodIdempotent) { + if (isIdempotentOrAtMostOnce) { return RetryAction.FAILOVER_AND_RETRY; } else { return new RetryAction(RetryAction.RetryDecision.FAIL, 0, @@ -562,7 +562,7 @@ public class RetryPolicies { } } else { return fallbackPolicy.shouldRetry(e, retries, failovers, - isMethodIdempotent); + isIdempotentOrAtMostOnce); } } Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicy.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicy.java?rev=1508312&r1=1508311&r2=1508312&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicy.java (original) +++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicy.java Tue Jul 30 06:19:28 2013 @@ -75,24 +75,25 @@ public interface RetryPolicy { /** *

- * Determines whether the framework should retry a - * method for the given exception, and the number - * of retries that have been made for that operation + * Determines whether the framework should retry a method for the given + * exception, and the number of retries that have been made for that operation * so far. *

+ * * @param e The exception that caused the method to fail * @param retries The number of times the method has been retried * @param failovers The number of times the method has failed over to a - * different backend implementation - * @param isMethodIdempotent true if the method is idempotent - * and so can reasonably be retried on failover when we don't know if the - * previous attempt reached the server or not + * different backend implementation + * @param isIdempotentOrAtMostOnce true if the method is + * {@link Idempotent} or {@link AtMostOnce} and so can reasonably be + * retried on failover when we don't know if the previous attempt + * reached the server or not * @return true if the method should be retried, - * false if the method should not be retried - * but shouldn't fail with an exception (only for void methods) - * @throws Exception The re-thrown exception e indicating - * that the method failed and should not be retried further + * false if the method should not be retried but + * shouldn't fail with an exception (only for void methods) + * @throws Exception The re-thrown exception e indicating that + * the method failed and should not be retried further */ public RetryAction shouldRetry(Exception e, int retries, int failovers, - boolean isMethodIdempotent) throws Exception; + boolean isIdempotentOrAtMostOnce) throws Exception; } Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestFailoverProxy.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestFailoverProxy.java?rev=1508312&r1=1508311&r2=1508312&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestFailoverProxy.java (original) +++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestFailoverProxy.java Tue Jul 30 06:19:28 2013 @@ -78,7 +78,7 @@ public class TestFailoverProxy { @Override public RetryAction shouldRetry(Exception e, int retries, int failovers, - boolean isMethodIdempotent) { + boolean isIdempotentOrAtMostOnce) { return failovers < 1 ? RetryAction.FAILOVER_AND_RETRY : RetryAction.FAIL; }