Skip to content

Commit

Permalink
fix: fix agent rebalance panic
Browse files Browse the repository at this point in the history
  • Loading branch information
roryye authored and SongZhen0704 committed Sep 20, 2024
1 parent 1bc6a13 commit 2ae743c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions server/controller/http/service/vtap.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,12 @@ func execAZRebalance(
}
}

if availableHostNum == 0 {
log.Warningf("available host num (%v) == 0", vtapNum, availableHostNum)
return model.AZVTapRebalanceResult{}
}
// 计算平均采集器个数(向上取整),仅考虑状态正常的控制器/数据节点
avgVTapNum := int(math.Ceil(float64(vtapNum) / float64(availableHostNum)))
avgVTapNum := uint64(math.Ceil(float64(vtapNum / availableHostNum)))

// 超出平均个数的控制器,对其上采集器进行重新分配
response := model.AZVTapRebalanceResult{}
Expand All @@ -535,12 +539,12 @@ func execAZRebalance(
}

// 未超出无需进行重新分配
if len(vtaps) <= avgVTapNum {
if uint64(len(vtaps)) <= avgVTapNum {
continue
}

// 遍历超出部分,进行重新分配
for i := avgVTapNum; i < len(vtaps); i++ {
for i := avgVTapNum; i < uint64(len(vtaps)); i++ {
vtap := vtaps[i]

// 优先分配剩余采集器个数最多的控制器/数据节点
Expand Down

0 comments on commit 2ae743c

Please sign in to comment.