Some extra safety around negative numbers

An extra check that available is > 0, not just != 0.

Also, when rebalancing subrequests after a grant, if the grant
was not made, set the value of the subrequest to 0, and use that
when adjusting the amount available for the provider and amounts
of other subrequests.  In the case that a subrequest was for a
negative value, it could cause the total request amount as well
as the provider's available amount to increase.  Now the negative
case is handled as a grant of 0.

Change-Id: I83c56b35e02defaba8a7338dcdf17363d687266f
This commit is contained in:
James E. Blair 2014-08-29 13:46:26 -07:00
parent 80675bd315
commit ed29412ed2
1 changed files with 2 additions and 1 deletions

View File

@ -173,7 +173,7 @@ class AllocationProvider(object):
for w in waiters:
w = w[0]
if self.available:
if self.available > 0:
w.grant(min(int(w.amount), self.available))
else:
reqs.append(w)
@ -309,6 +309,7 @@ class AllocationSubRequest(object):
self.provider.grants.append(grant)
else:
grant = None
amount = 0
self.amount = amount
# Adjust provider and request values accordingly.
self.request.amount -= amount