* @param status The new status for the task tracker
* @return Was an old status found?
*/
boolean updateTaskTrackerStatus(String trackerName,
TaskTrackerStatus status) {
TaskTracker tt = getTaskTracker(trackerName);
TaskTrackerStatus oldStatus = (tt == null) ? null : tt.getStatus();
// update the total cluster capacity first
if (status != null) {
// we have a fresh tasktracker status
if (!faultyTrackers.isBlacklisted(status.getHost())) {
// if the task tracker host is not blacklisted - then
// we update the cluster capacity with the capacity
// reported by the tasktracker
updateTotalTaskCapacity(status);
} else {
// if the tasktracker is blacklisted - then it's capacity
// is already removed and will only be added back to the
// cluster capacity when it's unblacklisted
}
} else {
if (oldStatus != null) {
// old status exists - but no new status. in this case
// we are removing the tracker from the cluster.
if (!faultyTrackers.isBlacklisted(oldStatus.getHost())) {
// we update the total task capacity based on the old status
// this seems redundant - but this call is idempotent - so just
// make it. the danger of not making it is that we may accidentally
// remove something we never had
updateTotalTaskCapacity(oldStatus);
removeTaskTrackerCapacity(oldStatus);
} else {
// if the host is blacklisted - then the tracker's capacity
// has already been removed and there's nothing to do
}
}
}
if (oldStatus != null) {
totalMaps -= oldStatus.countMapTasks();
totalReduces -= oldStatus.countReduceTasks();
occupiedMapSlots -= oldStatus.countOccupiedMapSlots();
occupiedReduceSlots -= oldStatus.countOccupiedReduceSlots();
getInstrumentation().decRunningMaps(oldStatus.countMapTasks());
getInstrumentation().decRunningReduces(oldStatus.countReduceTasks());
getInstrumentation().decOccupiedMapSlots(oldStatus.countOccupiedMapSlots());
getInstrumentation().decOccupiedReduceSlots(oldStatus.countOccupiedReduceSlots());
if (status == null) {
taskTrackers.remove(trackerName);
Integer numTaskTrackersInHost =
uniqueHostsMap.get(oldStatus.getHost());
if (numTaskTrackersInHost != null) {
numTaskTrackersInHost --;
if (numTaskTrackersInHost > 0) {
uniqueHostsMap.put(oldStatus.getHost(), numTaskTrackersInHost);
}
else {
uniqueHostsMap.remove(oldStatus.getHost());
}
}
}
}
if (status != null) {
totalMaps += status.countMapTasks();
totalReduces += status.countReduceTasks();
occupiedMapSlots += status.countOccupiedMapSlots();
occupiedReduceSlots += status.countOccupiedReduceSlots();
getInstrumentation().addRunningMaps(status.countMapTasks());
getInstrumentation().addRunningReduces(status.countReduceTasks());
getInstrumentation().addOccupiedMapSlots(status.countOccupiedMapSlots());
getInstrumentation().addOccupiedReduceSlots(status.countOccupiedReduceSlots());
boolean alreadyPresent = false;
TaskTracker taskTracker = taskTrackers.get(trackerName);
if (taskTracker != null) {
alreadyPresent = true;
} else {
taskTracker = new TaskTracker(trackerName);
}
taskTracker.setStatus(status);
taskTrackers.put(trackerName, taskTracker);
if (LOG.isDebugEnabled()) {
int runningMaps = 0, runningReduces = 0;
int commitPendingMaps = 0, commitPendingReduces = 0;