This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 188
*: use dumpling's finish building connection location to leave safe mode #915
Merged
Merged
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
620adbb
*: use dump unit exit location to leave safe mode
lance6716 3e5a0d8
Merge branch 'master' of https://github.com/pingcap/dm into safe-mode
lance6716 d615be5
add test
lance6716 186e8c3
rename
lance6716 5b4c848
fix test
lance6716 3a2c9ce
Merge branch 'master' of https://github.com/pingcap/dm into safe-mode
lance6716 c8fcb5b
Merge branch 'master' of https://github.com/pingcap/dm into safe-mode
lance6716 0aeef4c
refine parseMetadata
lance6716 8ce7cf9
fix test
lance6716 07488d0
Merge branch 'master' into safe-mode
lance6716 618cdef
add test
lance6716 c13db8a
add it
lance6716 5e6b0e0
Merge branch 'master' of https://github.com/pingcap/dm into safe-mode
lance6716 3aa0d9b
fix shadow
lance6716 16270b5
address comments
lance6716 5dc4394
Merge branch 'master' into safe-mode
lance6716 f3317f9
Merge branch 'master' into safe-mode
GMHDBJD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
// Copyright 2019 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package dumpling | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io" | ||
"os" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/siddontang/go-mysql/mysql" | ||
|
||
"github.com/pingcap/dm/pkg/binlog" | ||
"github.com/pingcap/dm/pkg/gtid" | ||
"github.com/pingcap/dm/pkg/terror" | ||
) | ||
|
||
// ParseMetaData parses mydumper's output meta file and returns binlog location. | ||
// since v2.0.0, dumpling maybe configured to output master status after connection pool is established, | ||
// we return this location as well. | ||
func ParseMetaData(filename, flavor string) (*binlog.Location, *binlog.Location, error) { | ||
fd, err := os.Open(filename) | ||
if err != nil { | ||
return nil, nil, terror.ErrParseMydumperMeta.Generate(err) | ||
} | ||
defer fd.Close() | ||
|
||
var ( | ||
pos mysql.Position | ||
gtidStr string | ||
useLocation2 = false | ||
pos2 mysql.Position | ||
gtidStr2 string | ||
|
||
loc *binlog.Location | ||
loc2 *binlog.Location | ||
) | ||
|
||
br := bufio.NewReader(fd) | ||
|
||
parsePosAndGTID := func(pos *mysql.Position, gtid *string) error { | ||
for { | ||
line, err2 := br.ReadString('\n') | ||
if err2 != nil { | ||
return err2 | ||
} | ||
parts := strings.SplitN(line, ":", 2) | ||
if len(parts) != 2 { | ||
continue | ||
} | ||
key := strings.TrimSpace(parts[0]) | ||
value := strings.TrimSpace(parts[1]) | ||
switch key { | ||
case "Log": | ||
pos.Name = value | ||
case "Pos": | ||
pos64, err3 := strconv.ParseUint(value, 10, 32) | ||
if err3 != nil { | ||
return err3 | ||
} | ||
pos.Pos = uint32(pos64) | ||
case "GTID": | ||
// multiple GTID sets may cross multiple lines, continue to read them. | ||
following, err3 := readFollowingGTIDs(br, flavor) | ||
if err3 != nil { | ||
return err3 | ||
} | ||
*gtid = value + following | ||
return nil | ||
} | ||
} | ||
} | ||
|
||
for { | ||
line, err2 := br.ReadString('\n') | ||
if err2 == io.EOF { | ||
break | ||
} else if err2 != nil { | ||
return nil, nil, terror.ErrParseMydumperMeta.Generate(err2) | ||
} | ||
line = strings.TrimSpace(line) | ||
if len(line) == 0 { | ||
continue | ||
} | ||
|
||
switch line { | ||
case "SHOW MASTER STATUS:": | ||
if err3 := parsePosAndGTID(&pos, >idStr); err3 != nil { | ||
return nil, nil, terror.ErrParseMydumperMeta.Generate(err3) | ||
} | ||
case "SHOW SLAVE STATUS:": | ||
// ref: https://github.com/maxbube/mydumper/blob/master/mydumper.c#L434 | ||
for { | ||
line, err3 := br.ReadString('\n') | ||
if err3 != nil { | ||
return nil, nil, terror.ErrParseMydumperMeta.Generate(err3) | ||
} | ||
line = strings.TrimSpace(line) | ||
if len(line) == 0 { | ||
break | ||
} | ||
} | ||
case "SHOW MASTER STATUS: /* AFTER CONNECTION POOL ESTABLISHED */": | ||
useLocation2 = true | ||
if err3 := parsePosAndGTID(&pos2, >idStr2); err3 != nil { | ||
return nil, nil, terror.ErrParseMydumperMeta.Generate(err3) | ||
} | ||
default: | ||
// do nothing for Started dump, Finished dump... | ||
} | ||
} | ||
|
||
if len(pos.Name) == 0 || pos.Pos == uint32(0) { | ||
return nil, nil, terror.ErrParseMydumperMeta.Generate(fmt.Sprintf("file %s invalid format", filename)) | ||
} | ||
|
||
gset, err := gtid.ParserGTID(flavor, gtidStr) | ||
if err != nil { | ||
return nil, nil, terror.ErrParseMydumperMeta.Generate(fmt.Sprintf("file %s invalid format", filename)) | ||
} | ||
loc = &binlog.Location{ | ||
Position: pos, | ||
GTIDSet: gset, | ||
} | ||
|
||
if useLocation2 { | ||
if len(pos2.Name) == 0 || pos2.Pos == uint32(0) { | ||
return nil, nil, terror.ErrParseMydumperMeta.Generate(fmt.Sprintf("file %s invalid format", filename)) | ||
} | ||
gset2, err := gtid.ParserGTID(flavor, gtidStr2) | ||
if err != nil { | ||
return nil, nil, terror.ErrParseMydumperMeta.Generate(fmt.Sprintf("file %s invalid format", filename)) | ||
} | ||
loc2 = &binlog.Location{ | ||
Position: pos2, | ||
GTIDSet: gset2, | ||
} | ||
} | ||
|
||
return loc, loc2, nil | ||
} | ||
|
||
func readFollowingGTIDs(br *bufio.Reader, flavor string) (string, error) { | ||
var following strings.Builder | ||
for { | ||
line, err := br.ReadString('\n') | ||
if err == io.EOF { | ||
return following.String(), nil // return the previous, not including the last line. | ||
} else if err != nil { | ||
return "", err | ||
} | ||
|
||
line = strings.TrimSpace(line) | ||
if len(line) == 0 { | ||
return following.String(), nil // end with empty line. | ||
} | ||
|
||
end := len(line) | ||
if strings.HasSuffix(line, ",") { | ||
end = len(line) - 1 | ||
} | ||
|
||
// try parse to verify it | ||
_, err = gtid.ParserGTID(flavor, line[:end]) | ||
if err != nil { | ||
return following.String(), nil // return the previous, not including this non-GTID line. | ||
} | ||
|
||
following.WriteString(line) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed from
pkg/utils/mydumper.go
to avoid importing cycle