|
@@ -970,37 +970,27 @@ public class FairScheduler extends
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void continuousScheduling() {
|
|
|
- while (true) {
|
|
|
- List<NodeId> nodeIdList = new ArrayList<NodeId>(nodes.keySet());
|
|
|
- // Sort the nodes by space available on them, so that we offer
|
|
|
- // containers on emptier nodes first, facilitating an even spread. This
|
|
|
- // requires holding the scheduler lock, so that the space available on a
|
|
|
- // node doesn't change during the sort.
|
|
|
- synchronized (this) {
|
|
|
- Collections.sort(nodeIdList, nodeAvailableResourceComparator);
|
|
|
- }
|
|
|
+ void continuousSchedulingAttempt() {
|
|
|
+ List<NodeId> nodeIdList = new ArrayList<NodeId>(nodes.keySet());
|
|
|
+ // Sort the nodes by space available on them, so that we offer
|
|
|
+ // containers on emptier nodes first, facilitating an even spread. This
|
|
|
+ // requires holding the scheduler lock, so that the space available on a
|
|
|
+ // node doesn't change during the sort.
|
|
|
+ synchronized (this) {
|
|
|
+ Collections.sort(nodeIdList, nodeAvailableResourceComparator);
|
|
|
+ }
|
|
|
|
|
|
- // iterate all nodes
|
|
|
- for (NodeId nodeId : nodeIdList) {
|
|
|
- if (nodes.containsKey(nodeId)) {
|
|
|
- FSSchedulerNode node = getFSSchedulerNode(nodeId);
|
|
|
- try {
|
|
|
- if (Resources.fitsIn(minimumAllocation,
|
|
|
- node.getAvailableResource())) {
|
|
|
- attemptScheduling(node);
|
|
|
- }
|
|
|
- } catch (Throwable ex) {
|
|
|
- LOG.warn("Error while attempting scheduling for node " + node +
|
|
|
- ": " + ex.toString(), ex);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ // iterate all nodes
|
|
|
+ for (NodeId nodeId : nodeIdList) {
|
|
|
+ FSSchedulerNode node = getFSSchedulerNode(nodeId);
|
|
|
try {
|
|
|
- Thread.sleep(getContinuousSchedulingSleepMs());
|
|
|
- } catch (InterruptedException e) {
|
|
|
- LOG.warn("Error while doing sleep in continuous scheduling: " +
|
|
|
- e.toString(), e);
|
|
|
+ if (node != null && Resources.fitsIn(minimumAllocation,
|
|
|
+ node.getAvailableResource())) {
|
|
|
+ attemptScheduling(node);
|
|
|
+ }
|
|
|
+ } catch (Throwable ex) {
|
|
|
+ LOG.error("Error while attempting scheduling for node " + node +
|
|
|
+ ": " + ex.toString(), ex);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1010,6 +1000,12 @@ public class FairScheduler extends
|
|
|
|
|
|
@Override
|
|
|
public int compare(NodeId n1, NodeId n2) {
|
|
|
+ if (!nodes.containsKey(n1)) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ if (!nodes.containsKey(n2)) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
return RESOURCE_CALCULATOR.compare(clusterResource,
|
|
|
nodes.get(n2).getAvailableResource(),
|
|
|
nodes.get(n1).getAvailableResource());
|
|
@@ -1234,7 +1230,16 @@ public class FairScheduler extends
|
|
|
new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- continuousScheduling();
|
|
|
+ while (!Thread.currentThread().isInterrupted()) {
|
|
|
+ try {
|
|
|
+ continuousSchedulingAttempt();
|
|
|
+ Thread.sleep(getContinuousSchedulingSleepMs());
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ LOG.error("Continuous scheduling thread interrupted. Exiting. ",
|
|
|
+ e);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
);
|