YARN-6864. FSPreemptionThread cleanup for readability. (Daniel Templeton via Yufei Gu)

This commit is contained in:
Yufei Gu 2017-07-27 23:19:39 -07:00
parent 38c6fa5c7a
commit 9902be72cb

View File

@ -66,11 +66,11 @@ class FSPreemptionThread extends Thread {
schedulerReadLock = scheduler.getSchedulerReadLock();
}
@Override
public void run() {
while (!Thread.interrupted()) {
FSAppAttempt starvedApp;
try {
starvedApp = context.getStarvedApps().take();
FSAppAttempt starvedApp = context.getStarvedApps().take();
// Hold the scheduler readlock so this is not concurrent with the
// update thread.
schedulerReadLock.lock();
@ -82,7 +82,7 @@ public void run() {
starvedApp.preemptionTriggered(delayBeforeNextStarvationCheck);
} catch (InterruptedException e) {
LOG.info("Preemption thread interrupted! Exiting.");
return;
Thread.currentThread().interrupt();
}
}
}
@ -112,16 +112,19 @@ private List<RMContainer> identifyContainersToPreempt(
PreemptableContainers bestContainers = null;
List<FSSchedulerNode> potentialNodes = scheduler.getNodeTracker()
.getNodesByResourceName(rr.getResourceName());
int maxAMContainers = Integer.MAX_VALUE;
for (FSSchedulerNode node : potentialNodes) {
int maxAMContainers = bestContainers == null ?
Integer.MAX_VALUE : bestContainers.numAMContainers;
PreemptableContainers preemptableContainers =
identifyContainersToPreemptOnNode(
rr.getCapability(), node, maxAMContainers);
if (preemptableContainers != null) {
// This set is better than any previously identified set.
bestContainers = preemptableContainers;
if (preemptableContainers.numAMContainers == 0) {
maxAMContainers = bestContainers.numAMContainers;
if (maxAMContainers == 0) {
break;
}
}
@ -182,13 +185,10 @@ private PreemptableContainers identifyContainersToPreemptOnNode(
return preemptableContainers;
}
}
return null;
}
private boolean isNodeAlreadyReserved(
FSSchedulerNode node, FSAppAttempt app) {
FSAppAttempt nodeReservedApp = node.getReservedAppSchedulable();
return nodeReservedApp != null && !nodeReservedApp.equals(app);
// Return null if the sum of all preemptable containers' resources
// isn't enough to satisfy the starved request.
return null;
}
private void trackPreemptionsAgainstNode(List<RMContainer> containers,
@ -214,7 +214,7 @@ private void preemptContainers(List<RMContainer> containers) {
}
private class PreemptContainersTask extends TimerTask {
private List<RMContainer> containers;
private final List<RMContainer> containers;
PreemptContainersTask(List<RMContainer> containers) {
this.containers = containers;