Merge pull request #2001 from weaveworks/issues/1996-try-all-pending-allocations

Try all pending allocations - LGTM.  Fixes #1996
This commit is contained in:
Bryan Boreham committed 2016-02-29 08:20:49 -08:00
commit ce4857f5dc
1 file changed
+11 -17
+11 -17
View File
@@ -140,29 +140,23 @@ func (alloc *Allocator) cancelOpsFor(ops *[]operation, ident string) bool {
return found return found
} }
// Try all pending operations // Try all operations in a queue
func (alloc *Allocator) tryPendingOps() { func (alloc *Allocator) tryOps(ops *[]operation) {
// The slightly different semantics requires us to operate on 'claims' and for i := 0; i < len(*ops); {
// 'allocates' separately: op := (*ops)[i]
// Claims must be tried before Allocates
for i := 0; i < len(alloc.pendingClaims); {
op := alloc.pendingClaims[i]
if !op.Try(alloc) { if !op.Try(alloc) {
i++ i++
continue continue
} }
alloc.pendingClaims = append(alloc.pendingClaims[:i], alloc.pendingClaims[i+1:]...) *ops = append((*ops)[:i], (*ops)[i+1:]...)
} }
}
// When the first Allocate fails, bail - no need to // Try all pending operations
// send too many begs for space. func (alloc *Allocator) tryPendingOps() {
for i := 0; i < len(alloc.pendingAllocates); { // Process existing claims before servicing new allocations
op := alloc.pendingAllocates[i] alloc.tryOps(&alloc.pendingClaims)
if !op.Try(alloc) { alloc.tryOps(&alloc.pendingAllocates)
break
}
alloc.pendingAllocates = append(alloc.pendingAllocates[:i], alloc.pendingAllocates[i+1:]...)
}
} }
func (alloc *Allocator) spaceRequestDenied(sender mesh.PeerName, r address.Range) { func (alloc *Allocator) spaceRequestDenied(sender mesh.PeerName, r address.Range) {