mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 12:42:34 +02:00
fix loadbalancer panic on weight rebalance
This commit is contained in:
parent
cd74b76483
commit
320e29ba84
1 changed files with 5 additions and 4 deletions
|
@ -65,7 +65,6 @@ func (lb *LoadBalancer) Start(parent task.Parent) E.Error {
|
|||
lb.impl.OnRemoveServer(v)
|
||||
})
|
||||
}
|
||||
lb.pool.Clear()
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
@ -171,12 +170,14 @@ func (lb *LoadBalancer) rebalance() {
|
|||
if lb.sumWeight == maxWeight {
|
||||
return
|
||||
}
|
||||
if lb.pool.Size() == 0 {
|
||||
|
||||
poolSize := lb.pool.Size()
|
||||
if poolSize == 0 {
|
||||
return
|
||||
}
|
||||
if lb.sumWeight == 0 { // distribute evenly
|
||||
weightEach := maxWeight / Weight(lb.pool.Size())
|
||||
remainder := maxWeight % Weight(lb.pool.Size())
|
||||
weightEach := maxWeight / Weight(poolSize)
|
||||
remainder := maxWeight % Weight(poolSize)
|
||||
lb.pool.RangeAll(func(_ string, s *Server) {
|
||||
s.Weight = weightEach
|
||||
lb.sumWeight += weightEach
|
||||
|
|
Loading…
Add table
Reference in a new issue