diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/ZKRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/ZKRMStateStore.java index dcf891a48d2..f8b7384ee74 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/ZKRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/ZKRMStateStore.java @@ -1425,6 +1425,14 @@ void delete(final String path) throws Exception { zkManager.delete(path); } + @Override + public void serviceStop() throws Exception { + if (zkManager != resourceManager.getZKManager()) { + zkManager.close(); + } + super.serviceStop(); + } + /** * Helper class that periodically attempts creating a znode to ensure that * this RM continues to be the Active. diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AbstractYarnScheduler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AbstractYarnScheduler.java index da5353014a5..bd5dbf10e0c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AbstractYarnScheduler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AbstractYarnScheduler.java @@ -181,6 +181,8 @@ protected SchedulingMonitorManager schedulingMonitorManager = new SchedulingMonitorManager(); + Timer cacheCleanupTimer = new Timer("Release Cache Cleanup Timer"); + /** * Construct the service. * @@ -208,7 +210,6 @@ public void serviceInit(Configuration conf) throws Exception { nodeTracker.setConfiguredMaxAllocationWaitTime( configuredMaximumAllocationWaitTime); maxClusterLevelAppPriority = getMaxPriorityFromConf(conf); - createReleaseCache(); autoUpdateContainers = conf.getBoolean(YarnConfiguration.RM_AUTO_UPDATE_CONTAINERS, YarnConfiguration.DEFAULT_RM_AUTO_UPDATE_CONTAINERS); @@ -230,6 +231,14 @@ protected void serviceStart() throws Exception { updateThread.start(); } schedulingMonitorManager.startAll(); + // Cleanup the cache after nm expire interval. + cacheCleanupTimer.schedule(new TimerTask() { + @Override + public void run() { + clearPendingContainerCache(); + LOG.info("Release request cache is cleaned up"); + } + }, nmExpireInterval); super.serviceStart(); } @@ -240,6 +249,10 @@ protected void serviceStop() throws Exception { updateThread.join(THREAD_JOIN_TIMEOUT_MS); } schedulingMonitorManager.stop(); + if (cacheCleanupTimer != null) { + cacheCleanupTimer.cancel(); + cacheCleanupTimer = null; + } super.serviceStop(); } @@ -633,17 +646,6 @@ private void recoverResourceRequestForContainer(RMContainer rmContainer) { } } - protected void createReleaseCache() { - // Cleanup the cache after nm expire interval. - new Timer().schedule(new TimerTask() { - @Override - public void run() { - clearPendingContainerCache(); - LOG.info("Release request cache is cleaned up"); - } - }, nmExpireInterval); - } - @VisibleForTesting public void clearPendingContainerCache() { for (SchedulerApplication app : applications.values()) {