-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgtid_op.go
77 lines (71 loc) · 1.74 KB
/
gtid_op.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
package gtid
func GtidAdd(gtidDesc0, gtidDesc1 string) (string, error) {
gtid, err := parseGtid(gtidDesc0 + "," + gtidDesc1)
if nil != err {
return "", err
}
return gtid.String(), nil
}
func GtidContain(gtidDesc0, gtidDesc1 string) (bool, error) {
gtidMerged, err := parseGtid(gtidDesc0 + "," + gtidDesc1)
if nil != err {
return false, err
}
gtid0, err := parseGtid(gtidDesc0)
if nil != err {
return false, err
}
return gtidMerged.String() == gtid0.String(), nil
}
func GtidOverlap(gtidDesc0 string, gtidDesc1 string) (bool, error) {
gtid0, err := parseGtid(gtidDesc0)
if nil != err {
return false, err
}
gtid1, err := parseGtid(gtidDesc1)
if nil != err {
return false, err
}
if "" == gtid0.String() && "" == gtid1.String() {
return true, nil
}
sub, err := GtidSub(gtidDesc0, gtidDesc1)
if nil != err {
return false, err
}
return gtid0.String() != sub, nil
}
func GtidSub(gtidDesc0, gtidDesc1 string) (string, error) {
gtid0, err := parseGtid(gtidDesc0)
if nil != err {
return "", err
}
gtid1, err := parseGtid(gtidDesc1)
if nil != err {
return "", err
}
ret := Gtid{}
for _, uuidNumber0 := range gtid0.uuidNumbers {
intv := uuidNumber0.intervals
for _, uuidNumber1 := range gtid1.uuidNumbers {
if uuidNumber0.uuid == uuidNumber1.uuid {
intv = subIntervals(uuidNumber0.intervals, uuidNumber1.intervals)
}
}
if len(intv) > 0 {
ret.uuidNumbers = append(ret.uuidNumbers, tUuidNumber{uuidNumber0.uuid, intv})
}
}
return ret.String(), nil
}
func GtidEqual(gtidDesc0 string, gtidDesc1 string) (bool, error) {
gtid0, err := parseGtid(gtidDesc0)
if nil != err {
return false, err
}
gtid1, err := parseGtid(gtidDesc1)
if nil != err {
return false, err
}
return gtid0.String() == gtid1.String(), nil
}