void DRFSorter::allocated( const string& name, const SlaveID& slaveId, const Resources& resources) { set<Client, DRFComparator>::iterator it = find(name); if (it != clients.end()) { // TODO(benh): This should really be a CHECK. // TODO(benh): Refactor 'update' to be able to reuse it here. Client client(*it); // Update the 'allocations' to reflect the allocator decision. client.allocations++; // Remove and reinsert it to update the ordering appropriately. clients.erase(it); clients.insert(client); } allocations[name].resources[slaveId] += resources; allocations[name].scalars += resources.scalars(); // If the total resources have changed, we're going to // recalculate all the shares, so don't bother just // updating this client. if (!dirty) { update(name); } }
void DRFSorter::update( const string& name, const SlaveID& slaveId, const Resources& oldAllocation, const Resources& newAllocation) { CHECK(contains(name)); // TODO(bmahler): Check invariants between old and new allocations. // Namely, the roles and quantities of resources should be the same! // Otherwise, we need to ensure we re-calculate the shares, as // is being currently done, for safety. CHECK(total_.resources[slaveId].contains(oldAllocation)); CHECK(total_.scalars.contains(oldAllocation.scalars())); total_.resources[slaveId] -= oldAllocation; total_.resources[slaveId] += newAllocation; total_.scalars -= oldAllocation.scalars(); total_.scalars += newAllocation.scalars(); CHECK(allocations[name].resources[slaveId].contains(oldAllocation)); CHECK(allocations[name].scalars.contains(oldAllocation.scalars())); allocations[name].resources[slaveId] -= oldAllocation; allocations[name].resources[slaveId] += newAllocation; allocations[name].scalars -= oldAllocation.scalars(); allocations[name].scalars += newAllocation.scalars(); // Just assume the total has changed, per the TODO above. dirty = true; }
void DRFSorter::add(const SlaveID& slaveId, const Resources& resources) { if (!resources.empty()) { total_.resources[slaveId] += resources; total_.scalars += resources.scalars(); // We have to recalculate all shares when the total resources // change, but we put it off until sort is called so that if // something else changes before the next allocation we don't // recalculate everything twice. dirty = true; } }
void DRFSorter::update(const SlaveID& slaveId, const Resources& resources) { CHECK(total_.scalars.contains(total_.resources[slaveId].scalars())); total_.scalars -= total_.resources[slaveId].scalars(); total_.scalars += resources.scalars(); total_.resources[slaveId] = resources; if (total_.resources[slaveId].empty()) { total_.resources.erase(slaveId); } dirty = true; }
void DRFSorter::remove(const SlaveID& slaveId, const Resources& resources) { if (!resources.empty()) { CHECK(total_.resources.contains(slaveId)); total_.resources[slaveId] -= resources; total_.scalars -= resources.scalars(); if (total_.resources[slaveId].empty()) { total_.resources.erase(slaveId); } dirty = true; } }
void DRFSorter::unallocated( const string& name, const SlaveID& slaveId, const Resources& resources) { allocations[name].resources[slaveId] -= resources; allocations[name].scalars -= resources.scalars(); if (allocations[name].resources[slaveId].empty()) { allocations[name].resources.erase(slaveId); } if (!dirty) { update(name); } }