make rmpeer report on size of transferred space, and not fail
Closes #2058.
This commit is contained in:
1 parent
c48eefa82d
commit
62d823850c
5 files changed
+34
-27
No files matched your search
+21
-10
@@ -376,29 +376,40 @@ func (alloc *Allocator) Shutdown() {
|
||||
<-doneChan
|
||||
}
|
||||
|
||||
// AdminTakeoverRanges (Sync) - take over the ranges owned by a given peer.
|
||||
// AdminTakeoverRanges (Sync) - take over the ranges owned by a given
|
||||
// peer, and return how much space was transferred in the process.
|
||||
// Only done on adminstrator command.
|
||||
func (alloc *Allocator) AdminTakeoverRanges(peerNameOrNickname string) error {
|
||||
resultChan := make(chan error)
|
||||
func (alloc *Allocator) AdminTakeoverRanges(peerNameOrNickname string) address.Count {
|
||||
resultChan := make(chan address.Count)
|
||||
alloc.actionChan <- func() {
|
||||
peername, err := alloc.lookupPeername(peerNameOrNickname)
|
||||
if err != nil {
|
||||
resultChan <- fmt.Errorf("Cannot find peer '%s'", peerNameOrNickname)
|
||||
alloc.warnf("attempt to take over range from unknown peer '%s'", peerNameOrNickname)
|
||||
resultChan <- address.Count(0)
|
||||
return
|
||||
}
|
||||
|
||||
alloc.debugln("AdminTakeoverRanges:", peername)
|
||||
if peername == alloc.ourName {
|
||||
resultChan <- fmt.Errorf("Cannot take over ranges from yourself!")
|
||||
alloc.warnf("attempt to take over range from ourself")
|
||||
resultChan <- address.Count(0)
|
||||
return
|
||||
}
|
||||
|
||||
newRanges, err := alloc.ring.Transfer(peername, alloc.ourName)
|
||||
if err == nil && len(newRanges) > 0 {
|
||||
alloc.space.AddRanges(newRanges)
|
||||
alloc.gossip.GossipBroadcast(alloc.Gossip())
|
||||
newRanges := alloc.ring.Transfer(peername, alloc.ourName)
|
||||
|
||||
if len(newRanges) == 0 {
|
||||
resultChan <- address.Count(0)
|
||||
return
|
||||
}
|
||||
resultChan <- err
|
||||
|
||||
before := alloc.space.NumFreeAddressesInRange(alloc.universe)
|
||||
alloc.space.AddRanges(newRanges)
|
||||
after := alloc.space.NumFreeAddressesInRange(alloc.universe)
|
||||
|
||||
alloc.gossip.GossipBroadcast(alloc.Gossip())
|
||||
|
||||
resultChan <- after - before
|
||||
}
|
||||
return <-resultChan
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user