Explorar el Código

YARN-10194. YARN RMWebServices /scheduler-conf/validate leaks ZK Connections. Contributed by Prabhu Joseph

(cherry picked from commit f91e21ac109e753e76d19c5c872c59a767b7b837)
Szilard Nemeth hace 5 años
padre
commit
c0b7b38e22

+ 11 - 7
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerConfigValidator.java

@@ -42,14 +42,18 @@ public final class CapacitySchedulerConfigValidator {
   public static boolean validateCSConfiguration(
           final Configuration oldConf, final Configuration newConf,
           final RMContext rmContext) throws IOException {
-    //TODO: extract all the validation steps and replace reinitialize with
-    //the specific validation steps
     CapacityScheduler newCs = new CapacityScheduler();
-    newCs.setConf(oldConf);
-    newCs.setRMContext(rmContext);
-    newCs.init(oldConf);
-    newCs.reinitialize(newConf, rmContext, true);
-    return true;
+    try {
+      //TODO: extract all the validation steps and replace reinitialize with
+      //the specific validation steps
+      newCs.setConf(oldConf);
+      newCs.setRMContext(rmContext);
+      newCs.init(oldConf);
+      newCs.reinitialize(newConf, rmContext, true);
+      return true;
+    } finally {
+      newCs.stop();
+    }
   }
 
   public static Set<String> validatePlacementRules(

+ 1 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/FSSchedulerConfigurationStore.java

@@ -358,6 +358,7 @@ public class FSSchedulerConfigurationStore extends YarnConfigurationStore {
     return CURRENT_VERSION_INFO;
   }
 
+  @Override
   public void close() throws IOException {
     if (fileSystem != null) {
       fileSystem.close();

+ 6 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/InMemoryConfigurationStore.java

@@ -22,6 +22,7 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.yarn.server.records.Version;
 import org.apache.hadoop.yarn.server.resourcemanager.RMContext;
 
+import java.io.IOException;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -150,4 +151,9 @@ public class InMemoryConfigurationStore extends YarnConfigurationStore {
   public void checkVersion() {
     // Does nothing. (Version is always compatible since it's in memory)
   }
+
+  @Override
+  public void close() throws IOException {
+    // Does nothing.
+  }
 }

+ 1 - 1
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/YarnConfigurationStore.java

@@ -99,7 +99,7 @@ public abstract class YarnConfigurationStore {
    * Closes the configuration store, releasing any required resources.
    * @throws IOException on failure to close
    */
-  public void close() throws IOException {}
+  public abstract void close() throws IOException;
 
   /**
    * Logs the configuration change to backing store.

+ 8 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/ZKConfigurationStore.java

@@ -31,6 +31,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.RMContext;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.data.ACL;
 
+import java.io.IOException;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.ObjectInputStream;
@@ -316,4 +317,11 @@ public class ZKConfigurationStore extends YarnConfigurationStore {
   private static <T> T unsafeCast(Object o) throws ClassCastException {
     return (T)o;
   }
+
+  @Override
+  public void close() throws IOException {
+    if (zkManager  != null) {
+      zkManager.close();
+    }
+  }
 }