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
gtid, relay: use gtid_purged
to handle gap in Previous_gtids event
#1430
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4dc30f3
relay: use `gtid_purged` to handle gap in Previous_gtids event
lance6716 1493950
update test
lance6716 b80492c
add code change
lance6716 58f46bf
fix CI
lance6716 ecc4700
try fix CI
lance6716 112f1d8
keep old behaviour
lance6716 2718ca9
fix CI
lance6716 cc02004
remove debug printing
lance6716 ad6c30e
fix CI
lance6716 0515ffc
Merge branch 'master' of https://github.com/pingcap/dm into use-gtid-…
lance6716 0a89bb8
fix connection not closed
lance6716 bec582d
fix CI
lance6716 3a66bd6
Merge branch 'master' into use-gtid-purged
lance6716 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
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 |
---|---|---|
|
@@ -379,20 +379,18 @@ func (r *Relay) tryRecoverLatestFile(ctx context.Context, parser2 *parser.Parser | |
zap.Stringer("from position", latestPos), zap.Stringer("to position", result.LatestPos), log.WrapStringerField("from GTID set", latestGTID), log.WrapStringerField("to GTID set", result.LatestGTIDs)) | ||
|
||
if result.LatestGTIDs != nil { | ||
gs := result.LatestGTIDs | ||
oldGs1 := gs.Clone() | ||
// in MySQL, we expect `PreviousGTIDsEvent` contains ALL previous GTID sets, but in fact it may lack a part of them sometimes, | ||
// e.g we expect `00c04543-f584-11e9-a765-0242ac120002:1-100,03fc0263-28c7-11e7-a653-6c0b84d59f30:1-100`, | ||
// but may be `00c04543-f584-11e9-a765-0242ac120002:50-100,03fc0263-28c7-11e7-a653-6c0b84d59f30:60-100`. | ||
// and when DM requesting MySQL to send binlog events with this EXCLUDED GTID sets, some errors like | ||
// `ERROR 1236 (HY000): The slave is connecting using CHANGE MASTER TO MASTER_AUTO_POSITION = 1, but the master has purged binary logs containing GTIDs that the slave requires.` | ||
// may occur, so we force to reset the START part of any GTID set. | ||
if gs.ResetStart() { | ||
r.logger.Warn("force to reset the start part of recovered GTID sets", zap.Stringer("from GTID set", oldGs1), zap.Stringer("to GTID set", gs)) | ||
oldGs2 := latestGTID.Clone() | ||
if latestGTID.ResetStart() { | ||
r.logger.Warn("force to reset the start part of latest GTID sets", zap.Stringer("from GTID set", oldGs2), zap.Stringer("to GTID set", latestGTID)) | ||
} | ||
dbConn, err2 := r.db.Conn(ctx) | ||
if err2 != nil { | ||
return err2 | ||
} | ||
defer dbConn.Close() | ||
result.LatestGTIDs, err2 = utils.AddGSetWithPurged(ctx, result.LatestGTIDs, dbConn) | ||
if err2 != nil { | ||
return err2 | ||
} | ||
latestGTID, err2 = utils.AddGSetWithPurged(ctx, latestGTID, dbConn) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we don't add purged gtid to |
||
if err2 != nil { | ||
return err2 | ||
} | ||
} | ||
|
||
|
@@ -965,7 +963,7 @@ func (r *Relay) setSyncConfig() error { | |
} | ||
|
||
syncerCfg := replication.BinlogSyncerConfig{ | ||
ServerID: uint32(r.cfg.ServerID), | ||
ServerID: r.cfg.ServerID, | ||
Flavor: r.cfg.Flavor, | ||
Host: r.cfg.From.Host, | ||
Port: uint16(r.cfg.From.Port), | ||
|
@@ -990,7 +988,6 @@ func (r *Relay) setSyncConfig() error { | |
|
||
// AdjustGTID implements Relay.AdjustGTID | ||
// starting sync at returned gset will wholly fetch a binlog from beginning of the file. | ||
// TODO: check if starting fetch at the middle of binlog is also acceptable | ||
func (r *Relay) adjustGTID(ctx context.Context, gset gtid.Set) (gtid.Set, error) { | ||
// setup a TCP binlog reader (because no relay can be used when upgrading). | ||
syncCfg := r.syncerCfg | ||
|
@@ -1006,15 +1003,10 @@ func (r *Relay) adjustGTID(ctx context.Context, gset gtid.Set) (gtid.Set, error) | |
return nil, err | ||
} | ||
|
||
// in MySQL, we expect `PreviousGTIDsEvent` contains ALL previous GTID sets, but in fact it may lack a part of them sometimes, | ||
// e.g we expect `00c04543-f584-11e9-a765-0242ac120002:1-100,03fc0263-28c7-11e7-a653-6c0b84d59f30:1-100`, | ||
// but may be `00c04543-f584-11e9-a765-0242ac120002:50-100,03fc0263-28c7-11e7-a653-6c0b84d59f30:60-100`. | ||
// and when DM requesting MySQL to send binlog events with this EXCLUDED GTID sets, some errors like | ||
// `ERROR 1236 (HY000): The slave is connecting using CHANGE MASTER TO MASTER_AUTO_POSITION = 1, but the master has purged binary logs containing GTIDs that the slave requires.` | ||
// may occur, so we force to reset the START part of any GTID set. | ||
oldGs := resultGs.Clone() | ||
if resultGs.ResetStart() { | ||
r.logger.Warn("force to reset the start part of GTID sets", zap.Stringer("from GTID set", oldGs), zap.Stringer("to GTID set", resultGs)) | ||
dbConn, err2 := r.db.Conn(ctx) | ||
if err2 != nil { | ||
return nil, err2 | ||
} | ||
return resultGs, nil | ||
defer dbConn.Close() | ||
return utils.AddGSetWithPurged(ctx, resultGs, dbConn) | ||
} |
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,56 @@ | ||
# diff Configuration. | ||
|
||
log-level = "info" | ||
|
||
chunk-size = 1000 | ||
|
||
check-thread-count = 4 | ||
|
||
sample-percent = 100 | ||
|
||
use-checksum = true | ||
|
||
fix-sql-file = "fix.sql" | ||
|
||
# tables need to check. | ||
[[check-tables]] | ||
schema = "gtid" | ||
tables = ["~t.*"] | ||
|
||
[[table-config]] | ||
schema = "gtid" | ||
table = "t1" | ||
|
||
[[table-config.source-tables]] | ||
instance-id = "source-1" | ||
schema = "gtid" | ||
table = "t1" | ||
|
||
[[table-config]] | ||
schema = "gtid" | ||
table = "t2" | ||
|
||
[[table-config.source-tables]] | ||
instance-id = "source-2" | ||
schema = "gtid" | ||
table = "t2" | ||
|
||
[[source-db]] | ||
host = "127.0.0.1" | ||
port = 3306 | ||
user = "root" | ||
password = "123456" | ||
instance-id = "source-1" | ||
|
||
[[source-db]] | ||
host = "127.0.0.1" | ||
port = 3307 | ||
user = "root" | ||
password = "123456" | ||
instance-id = "source-2" | ||
|
||
[target-db] | ||
host = "127.0.0.1" | ||
port = 4000 | ||
user = "test" | ||
password = "123456" |
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,5 @@ | ||
# Master Configuration. | ||
master-addr = ":8261" | ||
advertise-addr = "127.0.0.1:8261" | ||
|
||
rpc-timeout = "30s" |
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,23 @@ | ||
--- | ||
name: test | ||
task-mode: all | ||
is-sharding: false | ||
clean-dump-file: false | ||
|
||
target-database: | ||
host: "127.0.0.1" | ||
port: 4000 | ||
user: "root" | ||
password: "" | ||
|
||
mysql-instances: | ||
- source-id: "mysql-replica-01" | ||
block-allow-list: "instance" | ||
|
||
- source-id: "mysql-replica-02" | ||
block-allow-list: "instance" | ||
|
||
black-white-list: # compatible with deprecated config | ||
instance: | ||
do-dbs: ["gtid"] | ||
|
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,2 @@ | ||
name = "worker1" | ||
join = "127.0.0.1:8261" |
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,2 @@ | ||
name = "worker2" | ||
join = "127.0.0.1:8261" |
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.
Why do we use
sql.Conn
instead ofsql.DB
here?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.
some callers only hold sql.Conn not sql.DB
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.
in line 108 of pkg/v1dbschema/schema.go (below file). I'll close connection in next commit