MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / CompareBinlogFileName

Function CompareBinlogFileName

IceFireDB-SQLProxy/pkg/mysql/mysql/position.go:35–80  ·  view source on GitHub ↗
(a, b string)

Source from the content-addressed store, hash-verified

33}
34
35func CompareBinlogFileName(a, b string) int {
36 // sometimes it's convenient to construct a `Position` literal with no `Name`
37 if a == "" && b == "" {
38 return 0
39 } else if a == "" {
40 return -1
41 } else if b == "" {
42 return 1
43 }
44
45 splitBinlogName := func(n string) (string, int) {
46 // mysqld appends a numeric extension to the binary log base name to generate binary log file names
47 // ...
48 // If you supply an extension in the log name (for example, --log-bin=base_name.extension),
49 // the extension is silently removed and ignored.
50 // ref: https://dev.mysql.com/doc/refman/8.0/en/binary-log.html
51 i := strings.LastIndexByte(n, '.')
52 if i == -1 {
53 // try keeping backward compatibility
54 return n, 0
55 }
56
57 seq, err := strconv.Atoi(n[i+1:])
58 if err != nil {
59 panic(fmt.Sprintf("binlog file %s doesn't contain numeric extension", err))
60 }
61 return n[:i], seq
62 }
63
64 aBase, aSeq := splitBinlogName(a)
65 bBase, bSeq := splitBinlogName(b)
66
67 if aBase > bBase {
68 return 1
69 } else if aBase < bBase {
70 return -1
71 }
72
73 if aSeq > bSeq {
74 return 1
75 } else if aSeq < bSeq {
76 return -1
77 } else {
78 return 0
79 }
80}

Callers 1

CompareMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected