-
Notifications
You must be signed in to change notification settings - Fork 0
/
agent_option.go
140 lines (122 loc) · 3.46 KB
/
agent_option.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
package zongzi
import (
"fmt"
"strings"
"github.com/lni/dragonboat/v4/config"
)
type AgentOption func(*Agent) error
func WithApiAddress(advertiseAddress string, bindAddress ...string) AgentOption {
return func(a *Agent) error {
a.advertiseAddress = advertiseAddress
if len(bindAddress) > 0 {
a.bindAddress = bindAddress[0]
} else {
a.bindAddress = fmt.Sprintf("0.0.0.0:%s", strings.Split(advertiseAddress, ":")[1])
}
return nil
}
}
func WithGossipAddress(advertiseAddress string, bindAddress ...string) AgentOption {
return func(a *Agent) error {
a.hostConfig.Gossip.AdvertiseAddress = advertiseAddress
if len(bindAddress) > 0 {
a.hostConfig.Gossip.BindAddress = bindAddress[0]
} else {
a.hostConfig.Gossip.BindAddress = fmt.Sprintf("0.0.0.0:%s", strings.Split(advertiseAddress, ":")[1])
}
return nil
}
}
func WithRaftAddress(raftAddress string) AgentOption {
return func(a *Agent) error {
a.hostConfig.RaftAddress = raftAddress
return nil
}
}
func WithRaftDir(dir string) AgentOption {
return func(a *Agent) error {
a.hostConfig.NodeHostDir = dir
return nil
}
}
func WithWALDir(dir string) AgentOption {
return func(a *Agent) error {
a.hostConfig.WALDir = dir
return nil
}
}
func WithHostConfig(cfg HostConfig) AgentOption {
return func(a *Agent) error {
if len(cfg.Gossip.AdvertiseAddress) == 0 && len(a.hostConfig.Gossip.AdvertiseAddress) > 0 {
cfg.Gossip.AdvertiseAddress = a.hostConfig.Gossip.AdvertiseAddress
}
if len(cfg.Gossip.BindAddress) == 0 && len(a.hostConfig.Gossip.BindAddress) > 0 {
cfg.Gossip.BindAddress = a.hostConfig.Gossip.BindAddress
}
if len(cfg.RaftAddress) == 0 && len(a.hostConfig.RaftAddress) > 0 {
cfg.RaftAddress = a.hostConfig.RaftAddress
}
cfg.Expert.LogDBFactory = DefaultHostConfig.Expert.LogDBFactory
cfg.Expert.LogDB = DefaultHostConfig.Expert.LogDB
a.hostConfig = cfg
return nil
}
}
// WithHostMemLimit256 tunes the raft logger to use 256MB of ram
func WithHostMemLimit256(cfg HostConfig) AgentOption {
return func(a *Agent) error {
cfg.Expert.LogDB = config.GetTinyMemLogDBConfig()
return nil
}
}
// WithHostMemLimit1024 tunes the raft logger to use 1GB of ram
func WithHostMemLimit1024(cfg HostConfig) AgentOption {
return func(a *Agent) error {
cfg.Expert.LogDB = config.GetSmallMemLogDBConfig()
return nil
}
}
// WithHostMemLimit4096 tunes the raft logger to use 4GB of ram
func WithHostMemLimit4096(cfg HostConfig) AgentOption {
return func(a *Agent) error {
cfg.Expert.LogDB = config.GetMediumMemLogDBConfig()
return nil
}
}
// WithHostMemLimit8192 tunes the raft logger to use 8GB of ram
func WithHostMemLimit8192(cfg HostConfig) AgentOption {
return func(a *Agent) error {
cfg.Expert.LogDB = config.GetMediumMemLogDBConfig()
return nil
}
}
func WithRaftEventListener(listener RaftEventListener) AgentOption {
return func(a *Agent) error {
a.hostConfig.RaftEventListener = listener
return nil
}
}
func WithSystemEventListener(listener SystemEventListener) AgentOption {
return func(a *Agent) error {
a.hostConfig.SystemEventListener = listener
return nil
}
}
func WithHostTags(tags ...string) AgentOption {
return func(a *Agent) error {
a.hostTags = tags
return nil
}
}
func WithReplicaConfig(cfg ReplicaConfig) AgentOption {
return func(a *Agent) error {
a.replicaConfig = cfg
return nil
}
}
func WithShardController(c ShardController) AgentOption {
return func(a *Agent) error {
a.shardControllerManager.shardController = c
return nil
}
}