YARN-6175. FairScheduler: Negative vcore for resource needed to preempt. (Yufei Gu via kasha)

This commit is contained in:
Karthik Kambatla 2017-02-23 14:29:30 -08:00
parent b1ec790662
commit 1d156c8758
3 changed files with 23 additions and 11 deletions

View File

@ -172,6 +172,24 @@ public class Resources {
return subtractFrom(clone(lhs), rhs);
}
/**
* Subtract <code>rhs</code> from <code>lhs</code> and reset any negative
* values to zero.
* @param lhs {@link Resource} to subtract from
* @param rhs {@link Resource} to subtract
* @return the value of lhs after subtraction
*/
public static Resource subtractFromNonNegative(Resource lhs, Resource rhs) {
subtractFrom(lhs, rhs);
if (lhs.getMemorySize() < 0) {
lhs.setMemorySize(0);
}
if (lhs.getVirtualCores() < 0) {
lhs.setVirtualCores(0);
}
return lhs;
}
public static Resource negate(Resource resource) {
return subtract(NONE, resource);
}

View File

@ -194,16 +194,10 @@ public class FSAppAttempt extends SchedulerApplicationAttempt
for (NodeId nodeId: blacklistNodeIds) {
SchedulerNode node = scheduler.getSchedulerNode(nodeId);
if (node != null) {
Resources.subtractFrom(availableResources,
Resources.subtractFromNonNegative(availableResources,
node.getAvailableResource());
}
}
if (availableResources.getMemory() < 0) {
availableResources.setMemory(0);
}
if (availableResources.getVirtualCores() < 0) {
availableResources.setVirtualCores(0);
}
}
/**

View File

@ -531,14 +531,14 @@ public class FairScheduler extends
if (curTime - sched.getLastTimeAtMinShare() > minShareTimeout) {
Resource target = Resources.componentwiseMin(
sched.getMinShare(), sched.getDemand());
resDueToMinShare = Resources.max(calc, clusterResource,
Resources.none(), Resources.subtract(target, sched.getResourceUsage()));
resDueToMinShare =
Resources.subtractFromNonNegative(target, sched.getResourceUsage());
}
if (curTime - sched.getLastTimeAtFairShareThreshold() > fairShareTimeout) {
Resource target = Resources.componentwiseMin(
sched.getFairShare(), sched.getDemand());
resDueToFairShare = Resources.max(calc, clusterResource,
Resources.none(), Resources.subtract(target, sched.getResourceUsage()));
resDueToFairShare =
Resources.subtractFromNonNegative(target, sched.getResourceUsage());
}
Resource deficit = Resources.max(calc, clusterResource,
resDueToMinShare, resDueToFairShare);