Bläddra i källkod

HADOOP-8116. RetriableCommand is using RetryPolicy incorrectly after HADOOP-7896. Contributed by Aaron T. Myers.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-1623@1294729 13f79535-47bb-0310-9956-ffa450edef68
Aaron Myers 13 år sedan
förälder
incheckning
dcd2056e46

+ 2 - 0
hadoop-common-project/hadoop-common/CHANGES.HDFS-1623.txt

@@ -49,3 +49,5 @@ core-default.xml file. (Uma Maheswara Rao G via atm)
 HADOOP-8041. Log a warning when a failover is first attempted (todd)
 
 HADOOP-8068. void methods can swallow exceptions when going through failover path (todd)
+
+HADOOP-8116. RetriableCommand is using RetryPolicy incorrectly after HADOOP-7896. (atm)

+ 10 - 2
hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/util/RetriableCommand.java

@@ -22,7 +22,9 @@ package org.apache.hadoop.tools.util;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.io.retry.RetryPolicy;
+import org.apache.hadoop.io.retry.RetryPolicy.RetryAction;
 import org.apache.hadoop.io.retry.RetryPolicies;
+import org.apache.hadoop.util.ThreadUtil;
 
 import java.io.IOException;
 import java.util.concurrent.TimeUnit;
@@ -80,7 +82,7 @@ public abstract class RetriableCommand {
   public Object execute(Object... arguments) throws Exception {
     Exception latestException;
     int counter = 0;
-    do {
+    while (true) {
       try {
         return doExecute(arguments);
       } catch(Exception exception) {
@@ -88,7 +90,13 @@ public abstract class RetriableCommand {
         latestException = exception;
       }
       counter++;
-    } while (retryPolicy.shouldRetry(latestException, counter, 0, true).equals(RetryPolicy.RetryAction.RETRY));
+      RetryAction action = retryPolicy.shouldRetry(latestException, counter, 0, true);
+      if (action.action == RetryPolicy.RetryAction.RetryDecision.RETRY) {
+        ThreadUtil.sleepAtLeastIgnoreInterrupts(action.delayMillis);
+      } else {
+        break;
+      }
+    }
 
     throw new IOException("Couldn't run retriable-command: " + description,
                           latestException);

+ 6 - 1
hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/mapred/TestCopyMapper.java

@@ -545,7 +545,12 @@ public class TestCopyMapper {
             Assert.fail("Didn't expect the file to be copied");
           } catch (AccessControlException ignore) {
           } catch (Exception e) {
-            if (e.getCause() == null || !(e.getCause() instanceof AccessControlException)) {
+            // We want to make sure the underlying cause of the exception is
+            // due to permissions error. The exception we're interested in is
+            // wrapped twice - once in RetriableCommand and again in CopyMapper
+            // itself.
+            if (e.getCause() == null || e.getCause().getCause() == null ||
+                !(e.getCause().getCause() instanceof AccessControlException)) {
               throw new RuntimeException(e);
             }
           }