YARN-6144. FairScheduler: preempted resources can become negative. (Miklos Szegedi via kasha)

(cherry picked from commit 08f93978f3)
This commit is contained in:
Karthik Kambatla 2017-02-09 14:45:04 -08:00
parent 5de6f1b791
commit e259a818ad
2 changed files with 25 additions and 7 deletions

View File

@ -542,18 +542,20 @@ public class FSAppAttempt extends SchedulerApplicationAttempt
} }
void trackContainerForPreemption(RMContainer container) { void trackContainerForPreemption(RMContainer container) {
containersToPreempt.add(container); if (containersToPreempt.add(container)) {
synchronized (preemptedResources) { synchronized (preemptedResources) {
Resources.addTo(preemptedResources, container.getAllocatedResource()); Resources.addTo(preemptedResources, container.getAllocatedResource());
}
} }
} }
private void untrackContainerForPreemption(RMContainer container) { private void untrackContainerForPreemption(RMContainer container) {
synchronized (preemptedResources) { if (containersToPreempt.remove(container)) {
Resources.subtractFrom(preemptedResources, synchronized (preemptedResources) {
container.getAllocatedResource()); Resources.subtractFrom(preemptedResources,
container.getAllocatedResource());
}
} }
containersToPreempt.remove(container);
} }
Set<RMContainer> getPreemptionContainers() { Set<RMContainer> getPreemptionContainers() {

View File

@ -3640,6 +3640,8 @@ public class TestFairScheduler extends FairSchedulerTestBase {
scheduler.handle(updateEvent); scheduler.handle(updateEvent);
assertEquals("Application1's AM should be finished", assertEquals("Application1's AM should be finished",
0, app1.getLiveContainers().size()); 0, app1.getLiveContainers().size());
assertEquals("Finished application usage should be none",
Resources.none(), app1.getResourceUsage());
assertEquals("Application3's AM should be running", assertEquals("Application3's AM should be running",
1, app3.getLiveContainers().size()); 1, app3.getLiveContainers().size());
assertEquals("Application3's AM requests 1024 MB memory", assertEquals("Application3's AM requests 1024 MB memory",
@ -3658,6 +3660,8 @@ public class TestFairScheduler extends FairSchedulerTestBase {
0, app4.getAMResource().getMemorySize()); 0, app4.getAMResource().getMemorySize());
assertEquals("Application4's AM should not be running", assertEquals("Application4's AM should not be running",
0, app4.getLiveContainers().size()); 0, app4.getLiveContainers().size());
assertEquals("Finished application usage should be none",
Resources.none(), app4.getResourceUsage());
assertEquals("Queue1's AM resource usage should be 2048 MB memory", assertEquals("Queue1's AM resource usage should be 2048 MB memory",
2048, queue1.getAmResourceUsage().getMemorySize()); 2048, queue1.getAmResourceUsage().getMemorySize());
@ -3672,6 +3676,8 @@ public class TestFairScheduler extends FairSchedulerTestBase {
0, app5.getAMResource().getMemorySize()); 0, app5.getAMResource().getMemorySize());
assertEquals("Application5's AM should not be running", assertEquals("Application5's AM should not be running",
0, app5.getLiveContainers().size()); 0, app5.getLiveContainers().size());
assertEquals("Finished application usage should be none",
Resources.none(), app5.getResourceUsage());
assertEquals("Queue1's AM resource usage should be 2048 MB memory", assertEquals("Queue1's AM resource usage should be 2048 MB memory",
2048, queue1.getAmResourceUsage().getMemorySize()); 2048, queue1.getAmResourceUsage().getMemorySize());
@ -3683,6 +3689,8 @@ public class TestFairScheduler extends FairSchedulerTestBase {
scheduler.handle(updateEvent); scheduler.handle(updateEvent);
assertEquals("Application5's AM should not be running", assertEquals("Application5's AM should not be running",
0, app5.getLiveContainers().size()); 0, app5.getLiveContainers().size());
assertEquals("Finished application usage should be none",
Resources.none(), app5.getResourceUsage());
assertEquals("Queue1's AM resource usage should be 2048 MB memory", assertEquals("Queue1's AM resource usage should be 2048 MB memory",
2048, queue1.getAmResourceUsage().getMemorySize()); 2048, queue1.getAmResourceUsage().getMemorySize());
@ -3697,8 +3705,12 @@ public class TestFairScheduler extends FairSchedulerTestBase {
scheduler.handle(updateEvent); scheduler.handle(updateEvent);
assertEquals("Application2's AM should be finished", assertEquals("Application2's AM should be finished",
0, app2.getLiveContainers().size()); 0, app2.getLiveContainers().size());
assertEquals("Finished application usage should be none",
Resources.none(), app2.getResourceUsage());
assertEquals("Application3's AM should be finished", assertEquals("Application3's AM should be finished",
0, app3.getLiveContainers().size()); 0, app3.getLiveContainers().size());
assertEquals("Finished application usage should be none",
Resources.none(), app3.getResourceUsage());
assertEquals("Application5's AM should be running", assertEquals("Application5's AM should be running",
1, app5.getLiveContainers().size()); 1, app5.getLiveContainers().size());
assertEquals("Application5's AM requests 2048 MB memory", assertEquals("Application5's AM requests 2048 MB memory",
@ -3718,6 +3730,8 @@ public class TestFairScheduler extends FairSchedulerTestBase {
scheduler.handle(containerExpired); scheduler.handle(containerExpired);
assertEquals("Application5's AM should have 0 container", assertEquals("Application5's AM should have 0 container",
0, app5.getLiveContainers().size()); 0, app5.getLiveContainers().size());
assertEquals("Finished application usage should be none",
Resources.none(), app5.getResourceUsage());
assertEquals("Queue1's AM resource usage should be 2048 MB memory", assertEquals("Queue1's AM resource usage should be 2048 MB memory",
2048, queue1.getAmResourceUsage().getMemorySize()); 2048, queue1.getAmResourceUsage().getMemorySize());
scheduler.update(); scheduler.update();
@ -3740,6 +3754,8 @@ public class TestFairScheduler extends FairSchedulerTestBase {
scheduler.handle(updateEvent); scheduler.handle(updateEvent);
assertEquals("Application6's AM should not be running", assertEquals("Application6's AM should not be running",
0, app6.getLiveContainers().size()); 0, app6.getLiveContainers().size());
assertEquals("Finished application usage should be none",
Resources.none(), app6.getResourceUsage());
assertEquals("Application6's AM resource shouldn't be updated", assertEquals("Application6's AM resource shouldn't be updated",
0, app6.getAMResource().getMemorySize()); 0, app6.getAMResource().getMemorySize());
assertEquals("Queue1's AM resource usage should be 2048 MB memory", assertEquals("Queue1's AM resource usage should be 2048 MB memory",