*/
private synchronized Map<CookieContainerRequest, Container>
assignDelayedContainer(HeldContainer heldContainer) {
DAGAppMasterState state = appContext.getAMState();
boolean isNew = heldContainer.isNew();
if (LOG.isDebugEnabled()) {
LOG.debug("Trying to assign a delayed container"
+ ", containerId=" + heldContainer.getContainer().getId()
+ ", nextScheduleTime=" + heldContainer.getNextScheduleTime()
+ ", containerExpiryTime=" + heldContainer.getContainerExpiryTime()
+ ", AMState=" + state
+ ", matchLevel=" + heldContainer.getLocalityMatchLevel()
+ ", taskRequestsCount=" + taskRequests.size()
+ ", heldContainers=" + heldContainers.size()
+ ", delayedContainers=" + delayedContainerManager.delayedContainers.size()
+ ", isNew=" + isNew);
}
if (state.equals(DAGAppMasterState.IDLE) || taskRequests.isEmpty()) {
// reset locality level on held container
// if sessionDelay defined, push back into delayed queue if not already
// done so
// Compute min held containers.
if (appContext.isSession() && sessionNumMinHeldContainers > 0 &&
sessionMinHeldContainers.isEmpty()) {
// session mode and need to hold onto containers and not done so already
determineMinHeldContainers();
}
heldContainer.resetLocalityMatchLevel();
long currentTime = System.currentTimeMillis();
boolean releaseContainer = false;
if (isNew || (heldContainer.getContainerExpiryTime() <= currentTime
&& idleContainerTimeoutMin != -1)) {
// container idle timeout has expired or is a new unused container.
// new container is possibly a spurious race condition allocation.
if (!isNew && appContext.isSession() &&
sessionMinHeldContainers.contains(heldContainer.getContainer().getId())) {
// Not a potentially spurious new container.
// In session mode and container in set of chosen min held containers
// increase the idle container expire time to maintain sanity with
// the rest of the code
heldContainer.setContainerExpiryTime(getHeldContainerExpireTime(currentTime));
} else {
releaseContainer = true;
}
}
if (releaseContainer) {
LOG.info("No taskRequests. Container's idle timeout delay expired or is new. " +
"Releasing container"
+ ", containerId=" + heldContainer.container.getId()
+ ", containerExpiryTime="
+ heldContainer.getContainerExpiryTime()
+ ", idleTimeout=" + idleContainerTimeoutMin
+ ", taskRequestsCount=" + taskRequests.size()
+ ", heldContainers=" + heldContainers.size()
+ ", delayedContainers=" + delayedContainerManager.delayedContainers.size()
+ ", isNew=" + isNew);
releaseUnassignedContainers(
Lists.newArrayList(heldContainer.container));
} else {
// no outstanding work and container idle timeout not expired
if (LOG.isDebugEnabled()) {
LOG.debug("Holding onto idle container with no work. CId: "
+ heldContainer.getContainer().getId() + " with expiry: "
+ heldContainer.getContainerExpiryTime() + " currentTime: "
+ currentTime + " next look: "
+ (currentTime + localitySchedulingDelay));
}
// put back and wait for new requests until expiry
heldContainer.resetLocalityMatchLevel();
delayedContainerManager.addDelayedContainer(
heldContainer.getContainer(), currentTime
+ localitySchedulingDelay);
}
} else if (state.equals(DAGAppMasterState.RUNNING)) {
// clear min held containers since we need to allocate to tasks
sessionMinHeldContainers.clear();
HeldContainer.LocalityMatchLevel localityMatchLevel =
heldContainer.getLocalityMatchLevel();
Map<CookieContainerRequest, Container> assignedContainers =