-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathversion.go
64 lines (58 loc) · 1.26 KB
/
version.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
package binlog
import (
"fmt"
"strconv"
"strings"
)
type serverVersion []int
func newServerVersion(str string) (serverVersion, error) {
s := str
if i := strings.IndexByte(s, '-'); i != -1 {
s = s[:i]
}
if i := strings.IndexByte(s, '+'); i != -1 {
s = s[:i]
}
var sv serverVersion
for _, v := range strings.Split(s, ".") {
n, err := strconv.Atoi(v)
if err != nil {
return nil, fmt.Errorf("binlog: invalid serverVersion %q", str)
}
sv = append(sv, n)
}
if len(sv) != 3 {
return nil, fmt.Errorf("binlog: invalid serverVersion %q", str)
}
return sv, nil
}
func (sv serverVersion) eq(v serverVersion) bool {
return sv[0] == v[0] && sv[1] == v[1] && sv[2] == v[2]
}
func (sv serverVersion) lt(v serverVersion) bool {
for i := range sv {
if sv[i] < v[i] {
return true
}
if sv[i] == v[i] {
continue
}
return false
}
return false
}
// binlogVersion created by this mysql version
//
// https://dev.mysql.com/doc/internals/en/binlog-version.html
func (sv serverVersion) binlogVersion() uint16 {
switch {
case sv.lt([]int{4, 0, 0}):
return 1 // supported statement based replication events
case sv.lt([]int{4, 0, 2}):
return 2
case sv.lt([]int{5, 0, 0}):
return 3
default:
return 4 // the row based replication events were added
}
}