Skip to content

Commit

Permalink
config(dm): limit the length of hostname in binlog replication to 60 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lance6716 authored Mar 10, 2023
1 parent 855e4e1 commit 3bee675
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dm/relay/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,12 @@ func (r *Relay) setSyncConfig() error {
}
}

h, _ := os.Hostname()
h = "dm-relay-" + h
// https://github.com/mysql/mysql-server/blob/1bfe02bdad6604d54913c62614bde57a055c8332/include/my_hostname.h#L33-L42
if len(h) > 60 {
h = h[:60]
}
syncerCfg := replication.BinlogSyncerConfig{
ServerID: r.cfg.ServerID,
Flavor: r.cfg.Flavor,
Expand All @@ -1160,6 +1166,7 @@ func (r *Relay) setSyncConfig() error {
Password: r.cfg.From.Password,
Charset: r.cfg.Charset,
TLSConfig: tlsConfig,
Localhost: h,
}
common.SetDefaultReplicationCfg(&syncerCfg, common.MaxBinlogSyncerReconnect)

Expand Down
6 changes: 6 additions & 0 deletions dm/syncer/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ func subtaskCfg2BinlogSyncerCfg(cfg *config.SubTaskConfig, timezone *time.Locati
}
}

h := cfg.WorkerName
// https://github.com/mysql/mysql-server/blob/1bfe02bdad6604d54913c62614bde57a055c8332/include/my_hostname.h#L33-L42
if len(h) > 60 {
h = h[:60]
}
syncCfg := replication.BinlogSyncerConfig{
ServerID: cfg.ServerID,
Flavor: cfg.Flavor,
Expand All @@ -206,6 +211,7 @@ func subtaskCfg2BinlogSyncerCfg(cfg *config.SubTaskConfig, timezone *time.Locati
TimestampStringLocation: timezone,
TLSConfig: tlsConfig,
RowsEventDecodeFunc: rowsEventDecodeFunc,
Localhost: h,
}
// when retry count > 1, go-mysql will retry sync from the previous GTID set in GTID mode,
// which may get duplicate binlog event after retry success. so just set retry count = 1, and task
Expand Down

0 comments on commit 3bee675

Please sign in to comment.