YARN-6582. FSAppAttempt demand can be updated atomically in updateDemand(). (Karthik Kambatla via Yufei Gu)

(cherry picked from commit 87590090c8)
This commit is contained in:
Yufei Gu 2017-05-25 14:22:13 -07:00
parent 4c44ff69df
commit fc6cb4b2dd
1 changed files with 10 additions and 13 deletions

View File

@ -1284,24 +1284,21 @@ public class FSAppAttempt extends SchedulerApplicationAttempt
@Override
public void updateDemand() {
demand = Resources.createResource(0);
// Demand is current consumption plus outstanding requests
Resources.addTo(demand, getCurrentConsumption());
Resource tmpDemand = Resources.clone(getCurrentConsumption());
// Add up outstanding resource requests
try {
writeLock.lock();
for (SchedulerRequestKey k : getSchedulerKeys()) {
PendingAsk pendingAsk = getPendingAsk(k, ResourceRequest.ANY);
if (pendingAsk.getCount() > 0) {
Resources.multiplyAndAddTo(demand,
pendingAsk.getPerAllocationResource(),
pendingAsk.getCount());
}
for (SchedulerRequestKey k : getSchedulerKeys()) {
PendingAsk pendingAsk = getPendingAsk(k, ResourceRequest.ANY);
if (pendingAsk.getCount() > 0) {
Resources.multiplyAndAddTo(tmpDemand,
pendingAsk.getPerAllocationResource(),
pendingAsk.getCount());
}
} finally {
writeLock.unlock();
}
// Update demand
demand = tmpDemand;
}
@Override