You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
2 years ago
|
package binlog
|
||
|
|
||
|
import (
|
||
|
"b612.me/mysql/gtid"
|
||
|
"fmt"
|
||
|
"io/ioutil"
|
||
|
"path/filepath"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
func GetUnexecutedBinlogFilesByGtid(binlogDir string, binlogBaseName string, executedGtidDesc string, includeEventBeforeFirst bool) (
|
||
|
ret []string, err error) {
|
||
|
files, err := ioutil.ReadDir(binlogDir)
|
||
|
if nil != err {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
var binlogFiles []string
|
||
|
for _, file := range files {
|
||
|
if strings.HasPrefix(file.Name(), binlogBaseName+".") && binlogFileSuffixPattern.MatchString(file.Name()) {
|
||
|
binlogFiles = append(binlogFiles, file.Name())
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if 0 == len(binlogFiles) {
|
||
|
return make([]string, 0), nil
|
||
|
}
|
||
|
executedGtid, err := gtid.Parse(executedGtidDesc)
|
||
|
if nil != err {
|
||
|
return nil, err
|
||
|
}
|
||
|
for i := len(binlogFiles) - 1; i >= 0; i-- {
|
||
|
binlogFile := binlogFiles[i]
|
||
|
previousGtids, err := GetPreviousGtids(filepath.Join(binlogDir, binlogFile))
|
||
|
if nil != err {
|
||
|
return nil, err
|
||
|
}
|
||
|
contain, err := executedGtid.Contain(previousGtids)
|
||
|
if nil != err {
|
||
|
return nil, err
|
||
|
}
|
||
|
eql, err := executedGtid.Equal(previousGtids)
|
||
|
if nil != err {
|
||
|
return nil, err
|
||
|
}
|
||
|
if contain && !(includeEventBeforeFirst && eql && "" != executedGtidDesc) {
|
||
|
for j := i; j < len(binlogFiles); j++ {
|
||
|
ret = append(ret, binlogFiles[j])
|
||
|
}
|
||
|
return ret, nil
|
||
|
}
|
||
|
}
|
||
|
return nil, fmt.Errorf("Found unexecuted gtid comparing with previousGtids of even first binlog")
|
||
|
}
|