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/10/08 01:58:44 UTC
svn commit: r1530112 - in
/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop:
io/retry/RetryPolicies.java ipc/RetriableException.java
Author: jing9
Date: Mon Oct 7 23:58:44 2013
New Revision: 1530112
URL: http://svn.apache.org/r1530112
Log:
HDFS-5291. Standby namenode after transition to active goes into safemode. Contributed by Jing Zhao.
Added:
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RetriableException.java
Modified:
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicies.java
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=1530112&r1=1530111&r2=1530112&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 Mon Oct 7 23:58:44 2013
@@ -34,6 +34,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.ipc.RemoteException;
+import org.apache.hadoop.ipc.RetriableException;
import org.apache.hadoop.ipc.StandbyException;
import org.apache.hadoop.net.ConnectTimeoutException;
@@ -531,6 +532,15 @@ public class RetryPolicies {
this.maxDelayBase = maxDelayBase;
}
+ /**
+ * @return 0 if this is our first failover/retry (i.e., retry immediately),
+ * sleep exponentially otherwise
+ */
+ private long getFailoverOrRetrySleepTime(int times) {
+ return times == 0 ? 0 :
+ calculateExponentialTime(delayMillis, times, maxDelayBase);
+ }
+
@Override
public RetryAction shouldRetry(Exception e, int retries,
int failovers, boolean isIdempotentOrAtMostOnce) throws Exception {
@@ -546,11 +556,8 @@ public class RetryPolicies {
e instanceof StandbyException ||
e instanceof ConnectTimeoutException ||
isWrappedStandbyException(e)) {
- return new RetryAction(
- RetryAction.RetryDecision.FAILOVER_AND_RETRY,
- // retry immediately if this is our first failover, sleep otherwise
- failovers == 0 ? 0 :
- calculateExponentialTime(delayMillis, failovers, maxDelayBase));
+ return new RetryAction(RetryAction.RetryDecision.FAILOVER_AND_RETRY,
+ getFailoverOrRetrySleepTime(failovers));
} else if (e instanceof SocketException ||
(e instanceof IOException && !(e instanceof RemoteException))) {
if (isIdempotentOrAtMostOnce) {
@@ -561,8 +568,14 @@ public class RetryPolicies {
"whether it was invoked");
}
} else {
- return fallbackPolicy.shouldRetry(e, retries, failovers,
- isIdempotentOrAtMostOnce);
+ RetriableException re = getWrappedRetriableException(e);
+ if (re != null) {
+ return new RetryAction(RetryAction.RetryDecision.RETRY,
+ getFailoverOrRetrySleepTime(retries));
+ } else {
+ return fallbackPolicy.shouldRetry(e, retries, failovers,
+ isIdempotentOrAtMostOnce);
+ }
}
}
@@ -596,4 +609,14 @@ public class RetryPolicies {
StandbyException.class);
return unwrapped instanceof StandbyException;
}
+
+ private static RetriableException getWrappedRetriableException(Exception e) {
+ if (!(e instanceof RemoteException)) {
+ return null;
+ }
+ Exception unwrapped = ((RemoteException)e).unwrapRemoteException(
+ RetriableException.class);
+ return unwrapped instanceof RetriableException ?
+ (RetriableException) unwrapped : null;
+ }
}
Added: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RetriableException.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RetriableException.java?rev=1530112&view=auto
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RetriableException.java (added)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RetriableException.java Mon Oct 7 23:58:44 2013
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.ipc;
+
+import java.io.IOException;
+
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * Exception thrown by a server typically to indicate that server is in a state
+ * where request cannot be processed temporarily (such as still starting up).
+ * Client may retry the request. If the service is up, the server may be able to
+ * process a retried request.
+ */
+@InterfaceStability.Evolving
+public class RetriableException extends IOException {
+ private static final long serialVersionUID = 1915561725516487301L;
+
+ public RetriableException(Exception e) {
+ super(e);
+ }
+
+ public RetriableException(String msg) {
+ super(msg);
+ }
+}