Browse Source

YARN-1559. Race between ServerRMProxy and ClientRMProxy setting RMProxy#INSTANCE. (kasha and vinodkv via kasha)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1555971 13f79535-47bb-0310-9956-ffa450edef68
Karthik Kambatla 11 years ago
parent
commit
db2afa8bae

+ 3 - 0
hadoop-yarn-project/CHANGES.txt

@@ -268,6 +268,9 @@ Release 2.4.0 - UNRELEASED
     YARN-1549. Fixed a bug in ResourceManager's ApplicationMasterService that
     was causing unamanged AMs to not finish correctly. (haosdent via vinodkv)
 
+    YARN-1559. Race between ServerRMProxy and ClientRMProxy setting 
+    RMProxy#INSTANCE. (kasha and vinodkv via kasha)
+
 Release 2.3.0 - UNRELEASED
 
   INCOMPATIBLE CHANGES

+ 0 - 9
hadoop-yarn-project/hadoop-yarn/dev-support/findbugs-exclude.xml

@@ -309,13 +309,4 @@
     <Class name="org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKRMStateStore" />
     <Bug pattern="IS2_INCONSISTENT_SYNC" />
   </Match>
-
-  <!-- Ignore INSTANCE not being final as it is created in sub-classes -->
-  <Match>
-    <Class name="org.apache.hadoop.yarn.client.RMProxy" />
-    <Field name="INSTANCE" />
-    <Bug pattern="MS_SHOULD_BE_FINAL"/>
-  </Match>
-
-
 </FindBugsFilter>

+ 2 - 7
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/ClientRMProxy.java

@@ -39,16 +39,13 @@ import com.google.common.base.Preconditions;
 
 public class ClientRMProxy<T> extends RMProxy<T>  {
   private static final Log LOG = LogFactory.getLog(ClientRMProxy.class);
+  private static final ClientRMProxy INSTANCE = new ClientRMProxy();
 
   private interface ClientRMProtocols extends ApplicationClientProtocol,
       ApplicationMasterProtocol, ResourceManagerAdministrationProtocol {
     // Add nothing
   }
 
-  static {
-    INSTANCE = new ClientRMProxy();
-  }
-
   private ClientRMProxy(){
     super();
   }
@@ -63,9 +60,7 @@ public class ClientRMProxy<T> extends RMProxy<T>  {
    */
   public static <T> T createRMProxy(final Configuration configuration,
       final Class<T> protocol) throws IOException {
-    // This method exists only to initiate this class' static INSTANCE. TODO:
-    // FIX if possible
-    return RMProxy.createRMProxy(configuration, protocol);
+    return createRMProxy(configuration, protocol, INSTANCE);
   }
 
   private static void setupTokens(InetSocketAddress resourceManagerAddress)

+ 3 - 23
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/client/RMProxy.java

@@ -50,7 +50,6 @@ import com.google.common.annotations.VisibleForTesting;
 public class RMProxy<T> {
 
   private static final Log LOG = LogFactory.getLog(RMProxy.class);
-  protected static RMProxy INSTANCE;
 
   protected RMProxy() {}
 
@@ -79,17 +78,17 @@ public class RMProxy<T> {
    */
   @Private
   protected static <T> T createRMProxy(final Configuration configuration,
-      final Class<T> protocol) throws IOException {
+      final Class<T> protocol, RMProxy instance) throws IOException {
     YarnConfiguration conf = (configuration instanceof YarnConfiguration)
         ? (YarnConfiguration) configuration
         : new YarnConfiguration(configuration);
     RetryPolicy retryPolicy = createRetryPolicy(conf);
     if (HAUtil.isHAEnabled(conf)) {
       RMFailoverProxyProvider<T> provider =
-          INSTANCE.createRMFailoverProxyProvider(conf, protocol);
+          instance.createRMFailoverProxyProvider(conf, protocol);
       return (T) RetryProxy.create(protocol, provider, retryPolicy);
     } else {
-      InetSocketAddress rmAddress = INSTANCE.getRMAddress(conf, protocol);
+      InetSocketAddress rmAddress = instance.getRMAddress(conf, protocol);
       LOG.info("Connecting to ResourceManager at " + rmAddress);
       T proxy = RMProxy.<T>getProxy(conf, protocol, rmAddress);
       return (T) RetryProxy.create(protocol, proxy, retryPolicy);
@@ -159,25 +158,6 @@ public class RMProxy<T> {
     return provider;
   }
 
-  /**
-   * A RetryPolicy to allow failing over upto the specified maximum time.
-   */
-  private static class FailoverUptoMaximumTimePolicy implements RetryPolicy {
-    private long maxTime;
-
-    FailoverUptoMaximumTimePolicy(long maxTime) {
-      this.maxTime = maxTime;
-    }
-
-    @Override
-    public RetryAction shouldRetry(Exception e, int retries, int failovers,
-        boolean isIdempotentOrAtMostOnce) throws Exception {
-      return System.currentTimeMillis() < maxTime
-          ? RetryAction.FAILOVER_AND_RETRY
-          : RetryAction.FAIL;
-    }
-  }
-
   /**
    * Fetch retry policy from Configuration
    */

+ 3 - 8
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/ServerRMProxy.java

@@ -32,10 +32,7 @@ import com.google.common.base.Preconditions;
 
 public class ServerRMProxy<T> extends RMProxy<T> {
   private static final Log LOG = LogFactory.getLog(ServerRMProxy.class);
-
-  static {
-    INSTANCE = new ServerRMProxy();
-  }
+  private static final ServerRMProxy INSTANCE = new ServerRMProxy();
 
   private ServerRMProxy() {
     super();
@@ -51,10 +48,8 @@ public class ServerRMProxy<T> extends RMProxy<T> {
    */
   public static <T> T createRMProxy(final Configuration configuration,
       final Class<T> protocol) throws IOException {
-    // This method exists only to initiate this class' static INSTANCE. TODO:
-    // FIX if possible
-    return RMProxy.createRMProxy(configuration, protocol);
-  }
+    return createRMProxy(configuration, protocol, INSTANCE);
+}
 
   @InterfaceAudience.Private
   @Override