mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-25 02:09:01 +02:00
fix loadbalancer panic on weight rebalance
This commit is contained in:
@@ -65,7 +65,6 @@ func (lb *LoadBalancer) Start(parent task.Parent) E.Error {
|
|||||||
lb.impl.OnRemoveServer(v)
|
lb.impl.OnRemoveServer(v)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
lb.pool.Clear()
|
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -171,12 +170,14 @@ func (lb *LoadBalancer) rebalance() {
|
|||||||
if lb.sumWeight == maxWeight {
|
if lb.sumWeight == maxWeight {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if lb.pool.Size() == 0 {
|
|
||||||
|
poolSize := lb.pool.Size()
|
||||||
|
if poolSize == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if lb.sumWeight == 0 { // distribute evenly
|
if lb.sumWeight == 0 { // distribute evenly
|
||||||
weightEach := maxWeight / Weight(lb.pool.Size())
|
weightEach := maxWeight / Weight(poolSize)
|
||||||
remainder := maxWeight % Weight(lb.pool.Size())
|
remainder := maxWeight % Weight(poolSize)
|
||||||
lb.pool.RangeAll(func(_ string, s *Server) {
|
lb.pool.RangeAll(func(_ string, s *Server) {
|
||||||
s.Weight = weightEach
|
s.Weight = weightEach
|
||||||
lb.sumWeight += weightEach
|
lb.sumWeight += weightEach
|
||||||
|
|||||||
Reference in New Issue
Block a user