Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ApplicationMasterService.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ApplicationMasterService.java (revision 1455269) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ApplicationMasterService.java (working copy) @@ -277,6 +277,11 @@ Allocation allocation = this.rScheduler.allocate(appAttemptId, ask, release); + if (allocation.getError()) { + allocateResponse.setAMResponse(reboot); + return allocateResponse; + } + RMApp app = this.rmContext.getRMApps().get( appAttemptId.getApplicationId()); RMAppAttempt appAttempt = app.getRMAppAttempt(appAttemptId); Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fifo/FifoScheduler.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fifo/FifoScheduler.java (revision 1455269) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fifo/FifoScheduler.java (working copy) @@ -211,8 +211,8 @@ } } - private static final Allocation EMPTY_ALLOCATION = - new Allocation(EMPTY_CONTAINER_LIST, Resources.createResource(0)); + private static final Allocation EMPTY_ALLOCATION_WITH_ERROR = + new Allocation(EMPTY_CONTAINER_LIST, Resources.createResource(0), true); @Override public Allocation allocate( ApplicationAttemptId applicationAttemptId, List ask, @@ -221,7 +221,7 @@ if (application == null) { LOG.error("Calling allocate on removed " + "or non existant application " + applicationAttemptId); - return EMPTY_ALLOCATION; + return EMPTY_ALLOCATION_WITH_ERROR; } // Sanity check @@ -245,6 +245,15 @@ } synchronized (application) { + + // make sure we aren't stopping/removing the application + // when the allocate comes in + if (application.isStopped()) { + LOG.info("Calling allocate on a stopped " + + "application " + applicationAttemptId); + return EMPTY_ALLOCATION_WITH_ERROR; + } + if (!ask.isEmpty()) { LOG.debug("allocate: pre-update" + " applicationId=" + applicationAttemptId + Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacityScheduler.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacityScheduler.java (revision 1455269) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacityScheduler.java (working copy) @@ -445,8 +445,8 @@ applications.remove(applicationAttemptId); } - private static final Allocation EMPTY_ALLOCATION = - new Allocation(EMPTY_CONTAINER_LIST, Resources.createResource(0)); + private static final Allocation EMPTY_ALLOCATION_WITH_ERROR = + new Allocation(EMPTY_CONTAINER_LIST, Resources.createResource(0), true); @Override @Lock(Lock.NoLock.class) @@ -457,7 +457,7 @@ if (application == null) { LOG.info("Calling allocate on removed " + "or non existant application " + applicationAttemptId); - return EMPTY_ALLOCATION; + return EMPTY_ALLOCATION_WITH_ERROR; } // Sanity check @@ -481,6 +481,14 @@ } synchronized (application) { + + // make sure we aren't stopping/removing the application + // when the allocate comes in + if (application.isStopped()) { + LOG.info("Calling allocate on a stopped " + + "application " + applicationAttemptId); + return EMPTY_ALLOCATION_WITH_ERROR; + } if (!ask.isEmpty()) { Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/SchedulerApp.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/SchedulerApp.java (revision 1455269) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/SchedulerApp.java (working copy) @@ -82,6 +82,8 @@ = new HashMap(); private List newlyAllocatedContainers = new ArrayList(); + + private boolean isStopped = false; final Map> reservedContainers = new HashMap>(); @@ -125,7 +127,9 @@ public synchronized void updateResourceRequests( List requests) { - this.appSchedulingInfo.updateResourceRequests(requests); + if (!isStopped) { + this.appSchedulingInfo.updateResourceRequests(requests); + } } public Map getResourceRequests(Priority priority) { @@ -159,6 +163,10 @@ public boolean isPending() { return this.appSchedulingInfo.isPending(); } + + public synchronized boolean isStopped() { + return this.isStopped; + } public String getQueueName() { return this.appSchedulingInfo.getQueueName(); @@ -174,6 +182,7 @@ public synchronized void stop(RMAppAttemptState rmAppAttemptFinalState) { // Cleanup all scheduling information + this.isStopped = true; this.appSchedulingInfo.stop(rmAppAttemptFinalState); } @@ -226,6 +235,10 @@ Priority priority, ResourceRequest request, Container container) { + if (isStopped) { + return null; + } + // Required sanity check - AM can call 'allocate' to update resource // request without locking the scheduler, hence we need to check if (getTotalRequiredResources(priority) <= 0) { Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/Allocation.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/Allocation.java (revision 1455269) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/Allocation.java (working copy) @@ -26,11 +26,20 @@ public class Allocation { final List containers; final Resource resourceLimit; - + final Boolean error; + public Allocation(List containers, Resource resourceLimit) { this.containers = containers; this.resourceLimit = resourceLimit; + this.error = false; } + + public Allocation(List containers, Resource resourceLimit, + Boolean error) { + this.containers = containers; + this.resourceLimit = resourceLimit; + this.error = error; + } public List getContainers() { return containers; @@ -39,5 +48,13 @@ public Resource getResourceLimit() { return resourceLimit; } + + /** + * Check if an error occurred during Allocation + */ + public Boolean getError() { + return error; + } + }