github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/relay/util.go (about) 1 // Copyright 2019 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package relay 15 16 import ( 17 "context" 18 "io" 19 "strings" 20 21 "github.com/pingcap/errors" 22 "github.com/pingcap/tiflow/dm/pkg/conn" 23 tcontext "github.com/pingcap/tiflow/dm/pkg/context" 24 "github.com/pingcap/tiflow/dm/pkg/log" 25 "github.com/pingcap/tiflow/dm/pkg/terror" 26 "github.com/pingcap/tiflow/dm/pkg/utils" 27 ) 28 29 // isNewServer checks whether is connecting to a new server. 30 func isNewServer(ctx context.Context, prevUUID string, db *conn.BaseDB, flavor string) (bool, error) { 31 if len(prevUUID) == 0 { 32 // no sub dir exists before 33 return true, nil 34 } 35 uuid, err := conn.GetServerUUID(tcontext.NewContext(ctx, log.L()), db, flavor) 36 if err != nil { 37 return false, err 38 } 39 if strings.HasPrefix(prevUUID, uuid) { 40 // same server as before 41 return false, nil 42 } 43 return true, nil 44 } 45 46 // getNextRelaySubDir gets next relay log subdirectory after the current subdirectory. 47 func getNextRelaySubDir(currSubDir string, subDirs []string) (string, string, error) { 48 for i := len(subDirs) - 2; i >= 0; i-- { 49 if subDirs[i] == currSubDir { 50 nextSubDir := subDirs[i+1] 51 _, suffixInt, err := utils.ParseRelaySubDir(nextSubDir) 52 if err != nil { 53 return "", "", terror.Annotatef(err, "UUID %s", nextSubDir) 54 } 55 return nextSubDir, utils.SuffixIntToStr(suffixInt), nil 56 } 57 } 58 return "", "", nil 59 } 60 61 // isIgnorableParseError checks whether is a ignorable error for `BinlogParser.ParseFile`. 62 func isIgnorableParseError(err error) bool { 63 if err == nil { 64 return false 65 } 66 67 if strings.Contains(err.Error(), "err EOF") { 68 // NOTE: go-mysql returned err not includes caused err, but as message, ref: parser.go `parseSingleEvent` 69 return true 70 } else if errors.Cause(err) == io.EOF { 71 return true 72 } 73 74 return false 75 }