From b1b5bed544c6a9fc471c5a8ffaed3bda308fdeac Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Wed, 5 Jul 2017 16:28:52 +0200 Subject: [PATCH] allocate: shortcut when not enough candidates repinFromPeer: use helper function. License: MIT Signed-off-by: Hector Sanjuan --- cluster.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cluster.go b/cluster.go index 04c7a65d..7384c5c0 100644 --- a/cluster.go +++ b/cluster.go @@ -314,11 +314,9 @@ func (c *Cluster) repinFromPeer(p peer.ID) { } list := cState.List() for _, pin := range list { - for _, alloc := range pin.Allocations { - if alloc == p { // found pin allocated to node - logger.Infof("repinning %s out of %s", pin.Cid, p.Pretty()) - c.pin(pin, []peer.ID{p}) // pin blacklisting this peer - } + if containsPeer(pin.Allocations, p) { + logger.Infof("repinning %s out of %s", pin.Cid, p.Pretty()) + c.pin(pin, []peer.ID{p}) // pin blacklisting this peer } } } @@ -1112,6 +1110,11 @@ func (c *Cluster) allocate(hash *cid.Cid, repl int, blacklist []peer.ID) ([]peer case needed <= 0: // set the allocations to the needed ones return validAllocations[0 : len(validAllocations)+needed], nil + case candidatesValid < needed: + err = logError( + "not enough candidates to allocate %s. Needed: %d. Got: %s", + hash, needed, candidatesValid) + return nil, err default: // this will return candidate peers in order of // preference according to the allocator.