This repository was archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconflicts.go
More file actions
72 lines (61 loc) · 1.76 KB
/
conflicts.go
File metadata and controls
72 lines (61 loc) · 1.76 KB
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
package main
import (
"encoding/json"
"fmt"
"github.com/ylacancellera/galera-log-explainer/regex"
"github.com/ylacancellera/galera-log-explainer/utils"
"gopkg.in/yaml.v2"
)
type conflicts struct {
Paths []string `arg:"" name:"paths" help:"paths of the log to use"`
Yaml bool `xor:"format"`
Json bool `xor:"format"`
}
func (c *conflicts) Help() string {
return "Summarize every replication conflicts, from every node's point of view"
}
func (c *conflicts) Run() error {
regexes := regex.IdentsMap.Merge(regex.ApplicativeMap)
timeline, err := timelineFromPaths(c.Paths, regexes)
if err != nil {
return err
}
ctxs := timeline.GetLatestUpdatedContextsByNodes()
for _, ctx := range ctxs {
if len(ctx.Conflicts) == 0 {
continue
}
var out string
if c.Yaml {
tmp, err := yaml.Marshal(ctx.Conflicts)
if err != nil {
return err
}
out = string(tmp)
} else if c.Json {
tmp, err := json.Marshal(ctx.Conflicts)
if err != nil {
return err
}
out = string(tmp)
} else {
for _, conflict := range ctx.Conflicts {
out += "\n"
out += "\n" + utils.Paint(utils.BlueText, "seqno: ") + conflict.Seqno
out += "\n\t" + utils.Paint(utils.BlueText, "winner: ") + conflict.Winner
out += "\n\t" + utils.Paint(utils.BlueText, "votes per nodes:")
for node, vote := range conflict.VotePerNode {
displayVote := utils.Paint(utils.RedText, vote.MD5)
if vote.MD5 == conflict.Winner {
displayVote = utils.Paint(utils.GreenText, vote.MD5)
}
out += "\n\t\t" + utils.Paint(utils.BlueText, node) + ": (" + displayVote + ") " + vote.Error
}
out += "\n\t" + utils.Paint(utils.BlueText, "initiated by: ") + fmt.Sprintf("%v", conflict.InitiatedBy)
}
}
fmt.Println(out)
return nil
}
return nil
}