forked from tikv/pd
/
config.go
66 lines (55 loc) · 1.62 KB
/
config.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
package simulator
import (
"time"
"github.com/pingcap/pd/pkg/typeutil"
)
const (
defaultSimTickInterval = 100 * time.Millisecond
defaultNormTickInterval = 1 * time.Second
defaultStoreCapacityGB = 1024
defaultStoreAvailableGB = 1024
defaultStoreIOMBPerSecond = 40
defaultStoreVersion = "2.1.0"
)
// SimConfig is the simulator configuration.
type SimConfig struct {
SimTickInterval typeutil.Duration `toml:"sim-tick-interval"`
NormTickInterval typeutil.Duration `toml:"norm-tick-interval"`
StoreCapacityGB uint64 `toml:"store-capacity"`
StoreAvailableGB uint64 `toml:"store-available"`
StoreIOMBPerSecond int64 `toml:"store-io-per-second"`
StoreVersion string `toml:"store-version"`
}
// NewSimConfig create a new configuration of the simulator.
func NewSimConfig() *SimConfig {
return &SimConfig{}
}
func adjustDuration(v *typeutil.Duration, defValue time.Duration) {
if v.Duration == 0 {
v.Duration = defValue
}
}
func adjustString(v *string, defValue string) {
if len(*v) == 0 {
*v = defValue
}
}
func adjustUint64(v *uint64, defValue uint64) {
if *v == 0 {
*v = defValue
}
}
func adjustInt64(v *int64, defValue int64) {
if *v == 0 {
*v = defValue
}
}
// Adjust is used to adjust configurations
func (sc *SimConfig) Adjust() {
adjustDuration(&sc.SimTickInterval, defaultSimTickInterval)
adjustDuration(&sc.NormTickInterval, defaultNormTickInterval)
adjustUint64(&sc.StoreCapacityGB, defaultStoreCapacityGB)
adjustUint64(&sc.StoreAvailableGB, defaultStoreAvailableGB)
adjustInt64(&sc.StoreIOMBPerSecond, defaultStoreIOMBPerSecond)
adjustString(&sc.StoreVersion, defaultStoreVersion)
}