forked from willbryant/verm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplication_targets.go
65 lines (55 loc) · 1.51 KB
/
replication_targets.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
package main
import "fmt"
import "strings"
type ReplicationTargets struct {
targets []*ReplicationTarget
}
func parseTarget(value string) (string, string) {
parts := strings.Split(value, ":")
if len(parts) > 1 {
return parts[0], parts[1]
} else {
return parts[0], DefaultPort
}
}
func (targets *ReplicationTargets) Set(value string) error {
for _, s := range strings.Split(value, ",") {
hostname, port := parseTarget(s)
target := NewReplicationTarget(hostname, port)
targets.targets = append(targets.targets, &target)
}
return nil
}
func (targets *ReplicationTargets) String() string {
// shown as the default in the help text
return "<hostname> or <hostname>:<port>"
}
func (targets *ReplicationTargets) Start(rootDataDirectory string, statistics *LogStatistics, workers int) {
for _, target := range targets.targets {
target.Start(rootDataDirectory, statistics, workers)
}
}
func (targets *ReplicationTargets) EnqueueFile(location string, replicating bool) {
for _, target := range targets.targets {
if replicating {
target.enqueueReplicatedFile(location)
} else {
target.enqueueNewFile(location)
}
}
}
func (targets *ReplicationTargets) EnqueueResync() {
for _, target := range targets.targets {
target.enqueueResync()
}
}
func (targets *ReplicationTargets) StatisticsString() string {
result := ""
for _, target := range targets.targets {
result = fmt.Sprintf(
"%sreplication_%s_%s_queue_length %d\n",
result,
target.hostname, target.port, target.queueLength())
}
return result
}