The target of this JIRA is to offer the allocation slack resources to the framework. Here’re the key points of this design:
class HierarchicalAllocatorProcess
{
struct Slave
{
...
struct Optimistic
{
Resources total; // The total allocation slack resources
Resources allocated; // The allocated allocation slack resources
};
Optimistic optimistic;
};
}
class Resources
{
// Returns a Resources object with the same amount of each resource
// type as these Resources, but with all Resource objects marked as
// the specified `RevocableInfo::Type`; the other attribute is not
// affected.
Resources flatten(Resource::RevocableInfo::Type type);
// Return a Resources object that:
// - if role is given, the resources did not include role's reserved
// resources.
// - the resources's revocable type is `ALLOCATION_SLACK`
// - the role of resources is set to "*"
Resources allocationSlack(Option<string> role = None());
}
void HierarchicalAllocatorProcess::allocate(
const hashset<SlaveID>& slaveIds_)
{
foreach slave; foreach role; foreach framework
{
Resource optimistic;
if (framework.revocable) {
Resources total = slaves[slaveId].optimistic.total.allocationSlack(role);
optimistic = total - slaves[slaveId].optimistic.allocated;
}
...
offerable[frameworkId][slaveId] += resources + optimistic;
...
slaves[slaveId].optimistic.allocated += optimistic;
}
}
void HierarchicalAllocatorProcess::updateAllocation(
const FrameworkID& frameworkId,
const SlaveID& slaveId,
const vector<Offer::Operation>& operations)
{
...
Try<Resources> updatedOptimistic =
slaves[slaveId].optimistic.total.apply(operations);
CHECK_SOME(updatedTotal);
slaves[slaveId].optimistic.total =
updatedOptimistic.get().stateless().reserved().flatten(ALLOCATION_SLACK);
...
}
void HierarchicalAllocatorProcess::addSlave(
const SlaveID& slaveId,
const SlaveInfo& slaveInfo,
const Option<Unavailability>& unavailability,
const Resources& total,
const hashmap<FrameworkID, Resources>& used)
{
...
slaves[slaveId].optimistic.total =
total.stateless().reserved().flatten(ALLOCATION_SLACK);
...
}
void HierarchicalAllocatorProcess::recoverResources(
const FrameworkID& frameworkId,
const SlaveID& slaveId,
const Resources& resources,
const Option<Filters>& filters)
{
if (slaves.contains(slaveId))
{
...
slaves[slaveId].optimistic.allocated -= resources.allocationSlack();
...
}
}