You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ji...@apache.org on 2013/07/30 07:47:54 UTC
svn commit: r1508307 - in
/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common:
CHANGES.txt
src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java
src/test/java/org/apache/hadoop/io/retry/TestRetryProxy.java
Author: jing9
Date: Tue Jul 30 05:47:54 2013
New Revision: 1508307
URL: http://svn.apache.org/r1508307
Log:
HADOOP-9786. Merge change r1508304 from trunk.
Modified:
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestRetryProxy.java
Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1508307&r1=1508306&r2=1508307&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt (original)
+++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt Tue Jul 30 05:47:54 2013
@@ -233,6 +233,9 @@ Release 2.1.0-beta - 2013-07-02
HADOOP-9770. Make RetryCache#state non volatile. (suresh)
+ HADOOP-9786. RetryInvocationHandler#isRpcInvocation should support
+ ProtocolTranslator. (suresh and jing9)
+
OPTIMIZATIONS
HADOOP-9150. Avoid unnecessary DNS resolution attempts for logical URIs
Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java?rev=1508307&r1=1508306&r2=1508307&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java (original)
+++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java Tue Jul 30 05:47:54 2013
@@ -31,12 +31,13 @@ import org.apache.commons.logging.LogFac
import org.apache.hadoop.io.retry.RetryPolicy.RetryAction;
import org.apache.hadoop.ipc.Client;
import org.apache.hadoop.ipc.Client.ConnectionId;
+import org.apache.hadoop.ipc.ProtocolTranslator;
import org.apache.hadoop.ipc.RPC;
import org.apache.hadoop.ipc.RpcConstants;
import org.apache.hadoop.ipc.RpcInvocationHandler;
import org.apache.hadoop.util.ThreadUtil;
-import com.google.common.base.Preconditions;
+import com.google.common.annotations.VisibleForTesting;
class RetryInvocationHandler implements RpcInvocationHandler {
public static final Log LOG = LogFactory.getLog(RetryInvocationHandler.class);
@@ -76,7 +77,7 @@ class RetryInvocationHandler implements
// The number of times this method invocation has been failed over.
int invocationFailoverCount = 0;
- final boolean isRpc = isRpcInvocation();
+ final boolean isRpc = isRpcInvocation(currentProxy);
final int callId = isRpc? Client.nextCallId(): RpcConstants.INVALID_CALL_ID;
int retries = 0;
while (true) {
@@ -179,11 +180,15 @@ class RetryInvocationHandler implements
}
}
- private boolean isRpcInvocation() {
- if (!Proxy.isProxyClass(currentProxy.getClass())) {
+ @VisibleForTesting
+ static boolean isRpcInvocation(Object proxy) {
+ if (proxy instanceof ProtocolTranslator) {
+ proxy = ((ProtocolTranslator) proxy).getUnderlyingProxyObject();
+ }
+ if (!Proxy.isProxyClass(proxy.getClass())) {
return false;
}
- final InvocationHandler ih = Proxy.getInvocationHandler(currentProxy);
+ final InvocationHandler ih = Proxy.getInvocationHandler(proxy);
return ih instanceof RpcInvocationHandler;
}
Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestRetryProxy.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestRetryProxy.java?rev=1508307&r1=1508306&r2=1508307&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestRetryProxy.java (original)
+++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestRetryProxy.java Tue Jul 30 05:47:54 2013
@@ -35,6 +35,7 @@ import junit.framework.TestCase;
import org.apache.hadoop.io.retry.UnreliableInterface.FatalException;
import org.apache.hadoop.io.retry.UnreliableInterface.UnreliableException;
+import org.apache.hadoop.ipc.ProtocolTranslator;
import org.apache.hadoop.ipc.RemoteException;
public class TestRetryProxy extends TestCase {
@@ -58,6 +59,38 @@ public class TestRetryProxy extends Test
}
}
+ /**
+ * Test for {@link RetryInvocationHandler#isRpcInvocation(Object)}
+ */
+ public void testRpcInvocation() throws Exception {
+ // For a proxy method should return true
+ final UnreliableInterface unreliable = (UnreliableInterface)
+ RetryProxy.create(UnreliableInterface.class, unreliableImpl, RETRY_FOREVER);
+ assertTrue(RetryInvocationHandler.isRpcInvocation(unreliable));
+
+ // Embed the proxy in ProtocolTranslator
+ ProtocolTranslator xlator = new ProtocolTranslator() {
+ int count = 0;
+ @Override
+ public Object getUnderlyingProxyObject() {
+ count++;
+ return unreliable;
+ }
+ @Override
+ public String toString() {
+ return "" + count;
+ }
+ };
+
+ // For a proxy wrapped in ProtocolTranslator method should return true
+ assertTrue(RetryInvocationHandler.isRpcInvocation(xlator));
+ // Ensure underlying proxy was looked at
+ assertEquals(xlator.toString(), "1");
+
+ // For non-proxy the method must return false
+ assertFalse(RetryInvocationHandler.isRpcInvocation(new Object()));
+ }
+
public void testRetryForever() throws UnreliableException {
UnreliableInterface unreliable = (UnreliableInterface)
RetryProxy.create(UnreliableInterface.class, unreliableImpl, RETRY_FOREVER);
@@ -138,7 +171,7 @@ public class TestRetryProxy extends Test
}
}
- public void testRetryByRemoteException() throws UnreliableException {
+ public void testRetryByRemoteException() {
Map<Class<? extends Exception>, RetryPolicy> exceptionToPolicyMap =
Collections.<Class<? extends Exception>, RetryPolicy>singletonMap(FatalException.class, TRY_ONCE_THEN_FAIL);