-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcfg.go
164 lines (134 loc) · 4.1 KB
/
cfg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package prophet
import (
"math"
"time"
)
var (
replicaBaseScore = float64(100)
)
// Cfg prophet cfg
type Cfg struct {
// RPCAddr prophet rpc addr
RPCAddr string
// MaxScheduleRetries maximum retry times for schedule
MaxScheduleRetries int
// MaxScheduleInterval maximum schedule interval per scheduler
MaxScheduleInterval time.Duration
// MinScheduleInterval minimum schedule interval per scheduler
MinScheduleInterval time.Duration
// TimeoutWaitOperatorComplete timeout for waitting teh operator complete
TimeoutWaitOperatorComplete time.Duration
// MaxFreezeScheduleInterval freeze the container for a while if shouldSchedule is returns false
MaxFreezeScheduleInterval time.Duration
// MaxAllowContainerDownDuration maximum down time of removed from replicas
MaxAllowContainerDownDuration time.Duration
// MaxRebalanceLeader maximum count of transfer leader operator
MaxRebalanceLeader uint64
// MaxRebalanceReplica maximum count of remove|add replica operator
MaxRebalanceReplica uint64
// MaxScheduleReplica maximum count of schedule replica operator
MaxScheduleReplica uint64
// MaxLimitSnapshotsCount maximum count of node about snapshot
MaxLimitSnapshotsCount uint64
// CountResourceReplicas replica number per resource
CountResourceReplicas int
// MinAvailableStorageUsedRate minimum storage used rate of container, if the rate is over this value, skip the container
MinAvailableStorageUsedRate int
// LocationLabels the label used for location
LocationLabels []string
// MaxRPCCons rpc conns
MaxRPCCons int
// MaxRPCConnIdle rpc conn max idle time
MaxRPCConnIdle time.Duration
// MaxRPCTimeout rpc max timeout
MaxRPCTimeout time.Duration
StorageNode bool
LeaseTTL int64
Schedulers []Scheduler
Handler RoleChangeHandler
ResourceSortCompareFunc func(Resource, Resource) int
EnableScaleOnNewStore bool
}
func (c *Cfg) adujst() {
if c.LeaseTTL == 0 {
c.LeaseTTL = 5
}
if c.MaxScheduleRetries == 0 {
c.MaxScheduleRetries = 3
}
if c.MaxScheduleInterval == 0 {
c.MaxScheduleInterval = time.Minute
}
if c.MinScheduleInterval == 0 {
c.MinScheduleInterval = time.Millisecond * 10
}
if c.TimeoutWaitOperatorComplete == 0 {
c.TimeoutWaitOperatorComplete = 5 * time.Minute
}
if c.MaxFreezeScheduleInterval == 0 {
c.MaxFreezeScheduleInterval = 30 * time.Second
}
if c.MaxAllowContainerDownDuration == 0 {
c.MaxAllowContainerDownDuration = time.Hour
}
if c.MaxRebalanceReplica == 0 {
c.MaxRebalanceReplica = 12
}
if c.CountResourceReplicas == 0 {
c.CountResourceReplicas = 3
}
if c.MaxScheduleReplica == 0 {
c.MaxScheduleReplica = 16
}
if c.MinAvailableStorageUsedRate == 0 {
c.MinAvailableStorageUsedRate = 80
}
if c.MaxRebalanceLeader == 0 {
c.MaxRebalanceLeader = 16
}
if c.MaxLimitSnapshotsCount == 0 {
c.MaxLimitSnapshotsCount = 3
}
if c.MaxRPCCons == 0 {
c.MaxRPCCons = 10
}
if c.MaxRPCConnIdle == 0 {
c.MaxRPCConnIdle = time.Hour
}
if c.MaxRPCTimeout == 0 {
c.MaxRPCTimeout = time.Second * 10
}
if len(c.Schedulers) == 0 {
c.Schedulers = append(c.Schedulers, newBalanceReplicaScheduler(c))
c.Schedulers = append(c.Schedulers, newBalanceResourceLeaderScheduler(c))
}
if c.Handler == nil {
c.Handler = &emprtyHandler{}
}
}
func (c *Cfg) getLocationLabels() []string {
var value []string
for _, v := range c.LocationLabels {
value = append(value, v)
}
return value
}
// getDistinctScore returns the score that the other is distinct from the containers.
// A higher score means the other container is more different from the existed containers.
func (c *Cfg) getDistinctScore(containers []*ContainerRuntime, other *ContainerRuntime) float64 {
score := float64(0)
locationLabels := c.LocationLabels
for _, s := range containers {
if s.meta.ID() == other.meta.ID() {
continue
}
if index := s.compareLocation(other, locationLabels); index != -1 {
score += math.Pow(replicaBaseScore, float64(len(locationLabels)-index-1))
}
}
return score
}
type emprtyHandler struct {
}
func (h *emprtyHandler) ProphetBecomeLeader() {}
func (h *emprtyHandler) ProphetBecomeFollower() {}