Skip to content

Commit 0a6e110

Browse files
committed
remove useless copy in strategy
1 parent c927f5d commit 0a6e110

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

client/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func dial(ctx context.Context, addr string, authConfig types.AuthConfig) (*grpc.
4444
opts := []grpc.DialOption{
4545
grpc.WithInsecure(),
4646
grpc.WithKeepaliveParams(keepalive.ClientParameters{Time: 6 * 60 * time.Second, Timeout: time.Second}),
47-
grpc.WithBalancerName("round_robin"), // nolint:staticcheck
47+
grpc.WithBalancerName("round_robin"), // nolintlint
4848
grpc.WithUnaryInterceptor(interceptor.NewUnaryRetry(interceptor.RetryOptions{Max: 1})),
4949
grpc.WithStreamInterceptor(interceptor.NewStreamRetry(interceptor.RetryOptions{Max: 1})),
5050
}

strategy/average.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,16 @@ func AveragePlan(infos []Info, need, total, limit int) (map[string]int, error) {
2323
return nil, errors.WithStack(types.NewDetailedErr(types.ErrInsufficientRes,
2424
fmt.Sprintf("node len %d < limit, cannot alloc an average node plan", scheduleInfosLength)))
2525
}
26-
strategyInfos := make([]Info, scheduleInfosLength)
27-
copy(strategyInfos, infos)
28-
sort.Slice(strategyInfos, func(i, j int) bool { return strategyInfos[i].Capacity > strategyInfos[j].Capacity })
29-
p := sort.Search(scheduleInfosLength, func(i int) bool { return strategyInfos[i].Capacity < need })
26+
sort.Slice(infos, func(i, j int) bool { return infos[i].Capacity > infos[j].Capacity })
27+
p := sort.Search(scheduleInfosLength, func(i int) bool { return infos[i].Capacity < need })
3028
if p == 0 {
3129
return nil, errors.WithStack(types.NewDetailedErr(types.ErrInsufficientCap, "insufficient nodes, at least 1 needed"))
3230
}
3331
if p < limit {
3432
return nil, types.NewDetailedErr(types.ErrInsufficientRes, fmt.Sprintf("insufficient nodes, %d more needed", limit-p))
3533
}
3634
deployMap := map[string]int{}
37-
for _, strategyInfo := range strategyInfos[:limit] {
35+
for _, strategyInfo := range infos[:limit] {
3836
deployMap[strategyInfo.Nodename] += need
3937
}
4038

strategy/fill.go

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

0 commit comments

Comments
 (0)