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
This commit is contained in:
Karthik Kambatla 2014-06-07 00:51:50 +00:00
parent 38c0114f2b
commit 233ca3e2a5
3 changed files with 52 additions and 39 deletions

View File

@ -124,6 +124,9 @@ Release 2.5.0 - UNRELEASED
YARN-1977. Add tests on getApplicationRequest with filtering start time range. (junping_du) 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 OPTIMIZATIONS
BUG FIXES 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-2011. Fix typo and warning in TestLeafQueue (Chen He via junping_du)
YARN-2042. String shouldn't be compared using == in YARN-2042. String shouldn't be compared using == in
QueuePlacementRule#NestedUserQueue#getQueueForApp (Chen He via Sandy Ryza) QueuePlacementRule#NestedUserQueue#getQueueForApp (Chen He via Sandy Ryza)

View File

@ -142,6 +142,11 @@
<Class name="org.apache.hadoop.yarn.server.nodemanager.containermanager.logaggregation.LogAggregationService" /> <Class name="org.apache.hadoop.yarn.server.nodemanager.containermanager.logaggregation.LogAggregationService" />
<Bug pattern="IS2_INCONSISTENT_SYNC" /> <Bug pattern="IS2_INCONSISTENT_SYNC" />
</Match> </Match>
<Match>
<Class name="org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.AllocationFileLoaderService" />
<Field name="allocFile" />
<Bug pattern="IS2_INCONSISTENT_SYNC" />
</Match>
<!-- Inconsistent sync warning - minimumAllocation is only initialized once and never changed --> <!-- Inconsistent sync warning - minimumAllocation is only initialized once and never changed -->
<Match> <Match>
<Class name="org.apache.hadoop.yarn.server.resourcemanager.scheduler.AbstractYarnScheduler" /> <Class name="org.apache.hadoop.yarn.server.resourcemanager.scheduler.AbstractYarnScheduler" />

View File

@ -98,55 +98,59 @@ public AllocationFileLoaderService(Clock clock) {
} }
@Override @Override
public void init(Configuration conf) { public void serviceInit(Configuration conf) throws Exception {
this.allocFile = getAllocationFile(conf); this.allocFile = getAllocationFile(conf);
super.init(conf); if (allocFile != null) {
} reloadThread = new Thread() {
@Override
@Override public void run() {
public void start() { while (running) {
if (allocFile == null) { long time = clock.getTime();
return; long lastModified = allocFile.lastModified();
} if (lastModified > lastSuccessfulReload &&
reloadThread = new Thread() { time > lastModified + ALLOC_RELOAD_WAIT_MS) {
public void run() { try {
while (running) { reloadAllocations();
long time = clock.getTime(); } catch (Exception ex) {
long lastModified = allocFile.lastModified(); if (!lastReloadAttemptFailed) {
if (lastModified > lastSuccessfulReload && LOG.error("Failed to reload fair scheduler config file - " +
time > lastModified + ALLOC_RELOAD_WAIT_MS) { "will use existing allocations.", ex);
try { }
reloadAllocations(); lastReloadAttemptFailed = true;
} catch (Exception ex) { }
} else if (lastModified == 0l) {
if (!lastReloadAttemptFailed) { if (!lastReloadAttemptFailed) {
LOG.error("Failed to reload fair scheduler config file - " + LOG.warn("Failed to reload fair scheduler config file because" +
"will use existing allocations.", ex); " last modified returned 0. File exists: "
+ allocFile.exists());
} }
lastReloadAttemptFailed = true; lastReloadAttemptFailed = true;
} }
} else if (lastModified == 0l) { try {
if (!lastReloadAttemptFailed) { Thread.sleep(reloadIntervalMs);
LOG.warn("Failed to reload fair scheduler config file because" + } catch (InterruptedException ex) {
" last modified returned 0. File exists: " + allocFile.exists()); 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.setName("AllocationFileReloader"); reloadThread.setDaemon(true);
reloadThread.setDaemon(true); }
reloadThread.start(); super.serviceInit(conf);
super.start();
} }
@Override @Override
public void stop() { public void serviceStart() throws Exception {
if (reloadThread != null) {
reloadThread.start();
}
super.serviceStart();
}
@Override
public void serviceStop() throws Exception {
running = false; running = false;
if (reloadThread != null) { if (reloadThread != null) {
reloadThread.interrupt(); reloadThread.interrupt();
@ -156,7 +160,7 @@ public void stop() {
LOG.warn("reloadThread fails to join."); LOG.warn("reloadThread fails to join.");
} }
} }
super.stop(); super.serviceStop();
} }
/** /**