|
7 | 7 | package mysql |
8 | 8 |
|
9 | 9 | import ( |
10 | | - "errors" |
11 | 10 | "fmt" |
12 | | - "regexp" |
13 | 11 | "strconv" |
14 | 12 | "strings" |
15 | 13 | ) |
16 | 14 |
|
17 | | -var detachPattern *regexp.Regexp |
18 | | - |
19 | | -func init() { |
20 | | - detachPattern, _ = regexp.Compile(`//([^/:]+):([\d]+)`) // e.g. `//binlog.01234:567890` |
21 | | -} |
22 | | - |
23 | 15 | // FileBinlogCoordinates described binary log coordinates in the form of a binlog file & log position. |
24 | 16 | type FileBinlogCoordinates struct { |
25 | 17 | LogFile string |
@@ -120,51 +112,6 @@ func (this *FileBinlogCoordinates) FileNumber() (int, int) { |
120 | 112 | return fileNum, numLen |
121 | 113 | } |
122 | 114 |
|
123 | | -// PreviousFileCoordinatesBy guesses the filename of the previous binlog/relaylog, by given offset (number of files back) |
124 | | -func (this *FileBinlogCoordinates) PreviousFileCoordinatesBy(offset int) (BinlogCoordinates, error) { |
125 | | - result := &FileBinlogCoordinates{} |
126 | | - |
127 | | - fileNum, numLen := this.FileNumber() |
128 | | - if fileNum == 0 { |
129 | | - return result, errors.New("Log file number is zero, cannot detect previous file") |
130 | | - } |
131 | | - newNumStr := fmt.Sprintf("%d", (fileNum - offset)) |
132 | | - newNumStr = strings.Repeat("0", numLen-len(newNumStr)) + newNumStr |
133 | | - |
134 | | - tokens := strings.Split(this.LogFile, ".") |
135 | | - tokens[len(tokens)-1] = newNumStr |
136 | | - result.LogFile = strings.Join(tokens, ".") |
137 | | - return result, nil |
138 | | -} |
139 | | - |
140 | | -// PreviousFileCoordinates guesses the filename of the previous binlog/relaylog |
141 | | -func (this *FileBinlogCoordinates) PreviousFileCoordinates() (BinlogCoordinates, error) { |
142 | | - return this.PreviousFileCoordinatesBy(1) |
143 | | -} |
144 | | - |
145 | | -// PreviousFileCoordinates guesses the filename of the previous binlog/relaylog |
146 | | -func (this *FileBinlogCoordinates) NextFileCoordinates() (BinlogCoordinates, error) { |
147 | | - result := &FileBinlogCoordinates{} |
148 | | - |
149 | | - fileNum, numLen := this.FileNumber() |
150 | | - newNumStr := fmt.Sprintf("%d", (fileNum + 1)) |
151 | | - newNumStr = strings.Repeat("0", numLen-len(newNumStr)) + newNumStr |
152 | | - |
153 | | - tokens := strings.Split(this.LogFile, ".") |
154 | | - tokens[len(tokens)-1] = newNumStr |
155 | | - result.LogFile = strings.Join(tokens, ".") |
156 | | - return result, nil |
157 | | -} |
158 | | - |
159 | | -// FileSmallerThan returns true if this coordinate's file is strictly smaller than the other's. |
160 | | -func (this *FileBinlogCoordinates) DetachedCoordinates() (isDetached bool, detachedLogFile string, detachedLogPos string) { |
161 | | - detachedCoordinatesSubmatch := detachPattern.FindStringSubmatch(this.LogFile) |
162 | | - if len(detachedCoordinatesSubmatch) == 0 { |
163 | | - return false, "", "" |
164 | | - } |
165 | | - return true, detachedCoordinatesSubmatch[1], detachedCoordinatesSubmatch[2] |
166 | | -} |
167 | | - |
168 | 115 | func (this *FileBinlogCoordinates) Clone() BinlogCoordinates { |
169 | 116 | return &FileBinlogCoordinates{ |
170 | 117 | LogPos: this.LogPos, |
|
0 commit comments