From 233ca3e2a5145f006316f899e61a02bf97c38e75 Mon Sep 17 00:00:00 2001 From: Karthik Kambatla Date: Sat, 7 Jun 2014 00:51:50 +0000 Subject: [PATCH] YARN-2122. In AllocationFileLoaderService, the reloadThread should be created in init() and started in start(). (Robert Kanter via kasha) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1601046 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-yarn-project/CHANGES.txt | 4 + .../dev-support/findbugs-exclude.xml | 5 ++ .../fair/AllocationFileLoaderService.java | 82 ++++++++++--------- 3 files changed, 52 insertions(+), 39 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index ac1dcb7193d..236208215a0 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -124,6 +124,9 @@ Release 2.5.0 - UNRELEASED YARN-1977. Add tests on getApplicationRequest with filtering start time range. (junping_du) + YARN-2122. In AllocationFileLoaderService, the reloadThread should be created + in init() and started in start(). (Robert Kanter via kasha) + OPTIMIZATIONS BUG FIXES @@ -150,6 +153,7 @@ Release 2.5.0 - UNRELEASED YARN-2011. Fix typo and warning in TestLeafQueue (Chen He via junping_du) + YARN-2042. String shouldn't be compared using == in QueuePlacementRule#NestedUserQueue#getQueueForApp (Chen He via Sandy Ryza) diff --git a/hadoop-yarn-project/hadoop-yarn/dev-support/findbugs-exclude.xml b/hadoop-yarn-project/hadoop-yarn/dev-support/findbugs-exclude.xml index 79ce7460c21..2da958a08bf 100644 --- a/hadoop-yarn-project/hadoop-yarn/dev-support/findbugs-exclude.xml +++ b/hadoop-yarn-project/hadoop-yarn/dev-support/findbugs-exclude.xml @@ -142,6 +142,11 @@ + + + + + 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/fair/AllocationFileLoaderService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/AllocationFileLoaderService.java index 3a962a8ce52..064bdfc817f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/AllocationFileLoaderService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/AllocationFileLoaderService.java @@ -98,55 +98,59 @@ public AllocationFileLoaderService(Clock clock) { } @Override - public void init(Configuration conf) { + public void serviceInit(Configuration conf) throws Exception { this.allocFile = getAllocationFile(conf); - super.init(conf); - } - - @Override - public void start() { - if (allocFile == null) { - return; - } - reloadThread = new Thread() { - public void run() { - while (running) { - long time = clock.getTime(); - long lastModified = allocFile.lastModified(); - if (lastModified > lastSuccessfulReload && - time > lastModified + ALLOC_RELOAD_WAIT_MS) { - try { - reloadAllocations(); - } catch (Exception ex) { + if (allocFile != null) { + reloadThread = new Thread() { + @Override + public void run() { + while (running) { + long time = clock.getTime(); + long lastModified = allocFile.lastModified(); + if (lastModified > lastSuccessfulReload && + time > lastModified + ALLOC_RELOAD_WAIT_MS) { + try { + reloadAllocations(); + } catch (Exception ex) { + if (!lastReloadAttemptFailed) { + LOG.error("Failed to reload fair scheduler config file - " + + "will use existing allocations.", ex); + } + lastReloadAttemptFailed = true; + } + } else if (lastModified == 0l) { if (!lastReloadAttemptFailed) { - LOG.error("Failed to reload fair scheduler config file - " + - "will use existing allocations.", ex); + LOG.warn("Failed to reload fair scheduler config file because" + + " last modified returned 0. File exists: " + + allocFile.exists()); } lastReloadAttemptFailed = true; } - } else if (lastModified == 0l) { - if (!lastReloadAttemptFailed) { - LOG.warn("Failed to reload fair scheduler config file because" + - " last modified returned 0. File exists: " + allocFile.exists()); + try { + Thread.sleep(reloadIntervalMs); + } catch (InterruptedException ex) { + LOG.info( + "Interrupted while waiting to reload alloc configuration"); } - lastReloadAttemptFailed = true; - } - try { - Thread.sleep(reloadIntervalMs); - } catch (InterruptedException ex) { - LOG.info("Interrupted while waiting to reload alloc configuration"); } } - } - }; - reloadThread.setName("AllocationFileReloader"); - reloadThread.setDaemon(true); - reloadThread.start(); - super.start(); + }; + reloadThread.setName("AllocationFileReloader"); + reloadThread.setDaemon(true); + } + super.serviceInit(conf); } @Override - public void stop() { + public void serviceStart() throws Exception { + if (reloadThread != null) { + reloadThread.start(); + } + super.serviceStart(); + } + + @Override + public void serviceStop() throws Exception { running = false; if (reloadThread != null) { reloadThread.interrupt(); @@ -156,7 +160,7 @@ public void stop() { LOG.warn("reloadThread fails to join."); } } - super.stop(); + super.serviceStop(); } /**