-
Notifications
You must be signed in to change notification settings - Fork 51
/
sync.go
75 lines (62 loc) · 1.38 KB
/
sync.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
package main
import "github.com/reconquest/hierr-go"
func runSyncProtocol(
cluster *distributedLock,
runner *remoteExecutionRunner,
) error {
protocol := newSyncProtocol()
execution, err := runner.run(
cluster,
func(remoteNode *remoteExecutionNode) {
remoteNode.stdout = newProtocolNodeWriter(remoteNode, protocol)
},
)
if err != nil {
return hierr.Errorf(
err,
`can't run sync tool command`,
)
}
tracef(`starting sync protocol with %d nodes`, len(execution.nodes))
err = protocol.Init(execution.stdin)
if err != nil {
return hierr.Errorf(
err,
`can't init protocol with sync tool`,
)
}
tracef(`sending information about %d nodes to each`, len(execution.nodes))
nodes := []*remoteExecutionNode{}
for _, node := range execution.nodes {
nodes = append(nodes, node)
}
for _, node := range execution.nodes {
for _, neighbor := range nodes {
err := protocol.SendNode(node, neighbor)
if err != nil {
return hierr.Errorf(
err,
`can't send node to sync tool: '%s'`,
node.String(),
)
}
}
}
tracef(`sending start message to sync tools`)
err = protocol.SendStart()
if err != nil {
return hierr.Errorf(
err,
`can't start sync tool`,
)
}
debugf(`waiting sync tool to finish`)
err = execution.wait()
if err != nil {
return hierr.Errorf(
err,
`failed to finish sync tool command`,
)
}
return nil
}