Skip to content

Commit

Permalink
remove useless copy in strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Feb 15, 2021
1 parent c927f5d commit 0a6e110
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func dial(ctx context.Context, addr string, authConfig types.AuthConfig) (*grpc.
opts := []grpc.DialOption{
grpc.WithInsecure(),
grpc.WithKeepaliveParams(keepalive.ClientParameters{Time: 6 * 60 * time.Second, Timeout: time.Second}),
grpc.WithBalancerName("round_robin"), // nolint:staticcheck
grpc.WithBalancerName("round_robin"), // nolintlint
grpc.WithUnaryInterceptor(interceptor.NewUnaryRetry(interceptor.RetryOptions{Max: 1})),
grpc.WithStreamInterceptor(interceptor.NewStreamRetry(interceptor.RetryOptions{Max: 1})),
}
Expand Down
8 changes: 3 additions & 5 deletions strategy/average.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@ func AveragePlan(infos []Info, need, total, limit int) (map[string]int, error) {
return nil, errors.WithStack(types.NewDetailedErr(types.ErrInsufficientRes,
fmt.Sprintf("node len %d < limit, cannot alloc an average node plan", scheduleInfosLength)))
}
strategyInfos := make([]Info, scheduleInfosLength)
copy(strategyInfos, infos)
sort.Slice(strategyInfos, func(i, j int) bool { return strategyInfos[i].Capacity > strategyInfos[j].Capacity })
p := sort.Search(scheduleInfosLength, func(i int) bool { return strategyInfos[i].Capacity < need })
sort.Slice(infos, func(i, j int) bool { return infos[i].Capacity > infos[j].Capacity })
p := sort.Search(scheduleInfosLength, func(i int) bool { return infos[i].Capacity < need })
if p == 0 {
return nil, errors.WithStack(types.NewDetailedErr(types.ErrInsufficientCap, "insufficient nodes, at least 1 needed"))
}
if p < limit {
return nil, types.NewDetailedErr(types.ErrInsufficientRes, fmt.Sprintf("insufficient nodes, %d more needed", limit-p))
}
deployMap := map[string]int{}
for _, strategyInfo := range strategyInfos[:limit] {
for _, strategyInfo := range infos[:limit] {
deployMap[strategyInfo.Nodename] += need
}

Expand Down
2 changes: 1 addition & 1 deletion strategy/fill.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// FillPlan deploy workload each node
// 根据之前部署的策略每一台补充到 N 个,已经超过 N 个的节点视为已满足
// need 是每台上限, limit 是限制节点数, 保证最终状态至少有 limit*need 个实例
// limit=0 代表对所有节点进行填充
// limit = 0 代表对所有节点进行填充
func FillPlan(infos []Info, need, _, limit int) (_ map[string]int, err error) {
log.Debugf("[FillPlan] need %d limit %d infos %+v", need, limit, infos)
scheduleInfosLength := len(infos)
Expand Down

0 comments on commit 0a6e110

Please sign in to comment.