Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSLeafQueue.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSLeafQueue.java (date 1487894411000) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSLeafQueue.java (date 1487898911000) @@ -331,20 +331,20 @@ public void updateDemand() { // Compute demand by iterating through apps in the queue // Limit demand to maxResources - demand = Resources.createResource(0); + Resource tempDemand = Resources.createResource(0); readLock.lock(); try { for (FSAppAttempt sched : runnableApps) { - updateDemandForApp(sched); + tempDemand = updateDemandForApp(tempDemand, sched); } for (FSAppAttempt sched : nonRunnableApps) { - updateDemandForApp(sched); + tempDemand = updateDemandForApp(tempDemand, sched); } } finally { readLock.unlock(); } // Cap demand to maxShare to limit allocation to maxShare - demand = Resources.componentwiseMin(demand, maxShare); + demand = Resources.componentwiseMin(tempDemand, maxShare); if (LOG.isDebugEnabled()) { LOG.debug("The updated demand for " + getName() + " is " + demand + "; the max is " + maxShare); @@ -353,15 +353,15 @@ } } - private void updateDemandForApp(FSAppAttempt sched) { + private Resource updateDemandForApp(Resource tempDemand, FSAppAttempt sched) { sched.updateDemand(); Resource toAdd = sched.getDemand(); if (LOG.isDebugEnabled()) { LOG.debug("Counting resource from " + sched.getName() + " " + toAdd + "; Total resource demand for " + getName() + " now " - + demand); + + tempDemand); } - demand = Resources.add(demand, toAdd); + return Resources.add(tempDemand, toAdd); } @Override Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFSAppStarvation.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFSAppStarvation.java (date 1487894411000) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFSAppStarvation.java (date 1487898911000) @@ -92,10 +92,15 @@ * Test to verify application starvation is computed correctly when * preemption is turned on. */ - @Test + @Test(timeout = 60000) public void testPreemptionEnabled() throws Exception { setupClusterAndSubmitJobs(); + // Wait for apps to be processed by MockPreemptionThread + while(preemptionThread.uniqueAppsAdded() < 3) { + Thread.sleep(10); + } + assertNotNull("FSContext does not have an FSStarvedApps instance", scheduler.getContext().getStarvedApps()); assertEquals("Expecting 3 starved applications, one each for the " @@ -113,8 +118,16 @@ clock.tickMsec( FairSchedulerWithMockPreemption.DELAY_FOR_NEXT_STARVATION_CHECK_MS); scheduler.update(); + + // Wait for apps to be processed by MockPreemptionThread + while(preemptionThread.uniqueAppsAdded() >= + preemptionThread.totalAppsAdded()) { + Thread.sleep(10); + } + assertTrue("Each app is marked as starved exactly once", - preemptionThread.totalAppsAdded() > preemptionThread.uniqueAppsAdded()); + preemptionThread.totalAppsAdded() > + preemptionThread.uniqueAppsAdded()); } /* @@ -154,9 +167,6 @@ // Scheduler update to populate starved apps scheduler.update(); - - // Wait for apps to be processed by MockPreemptionThread - Thread.yield(); } /**