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.
42 lines
895 B
Go
42 lines
895 B
Go
package binlog
|
|
|
|
import (
|
|
"b612.me/mysql/gtid"
|
|
"io/ioutil"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
func GetAllGtidOfBinlogDir(binlogDir, binlogBaseName string) (gtidDesc string, err error) {
|
|
files, err := ioutil.ReadDir(binlogDir)
|
|
if nil != err {
|
|
return "", 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 "", nil
|
|
}
|
|
|
|
lastFile := filepath.Join(binlogDir, binlogFiles[len(binlogFiles)-1])
|
|
lastPreviousGtid, err := GetPreviousGtids(lastFile)
|
|
if nil != err {
|
|
return "", err
|
|
}
|
|
lastBinlogGtid, err := GetGtidOfBinlog(lastFile)
|
|
if nil != err {
|
|
return "", err
|
|
}
|
|
sum, err := gtid.Add(lastPreviousGtid, lastBinlogGtid)
|
|
if nil != err {
|
|
return "", err
|
|
}
|
|
return sum, nil
|
|
}
|