Skip to content

Commit

Permalink
replication: Improve COM_REGISTER_SLAVE (#967)
Browse files Browse the repository at this point in the history
* replication: Improve COM_REGISTER_SLAVE

* replication: Fix replica UUID registration

If we send `SET @replica_uuid=` after `COM_REGISTER_SLAVE` it won't be
picked up in `SHOW REPLICAS`.
  • Loading branch information
dveeden authored Jan 10, 2025
1 parent dc262fe commit 14069d3
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions replication/binlogsyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,6 @@ func (b *BinlogSyncer) registerSlave() error {
}
}

if err = b.writeRegisterSlaveCommand(); err != nil {
return errors.Trace(err)
}

if _, err = b.c.ReadOKPacket(); err != nil {
return errors.Trace(err)
}

serverUUID, err := uuid.NewUUID()
if err != nil {
b.cfg.Logger.Errorf("failed to get new uuid %v", err)
Expand All @@ -366,6 +358,14 @@ func (b *BinlogSyncer) registerSlave() error {
return errors.Trace(err)
}

if err = b.writeRegisterSlaveCommand(); err != nil {
return errors.Trace(err)
}

if _, err = b.c.ReadOKPacket(); err != nil {
return errors.Trace(err)
}

return nil
}

Expand Down Expand Up @@ -596,7 +596,7 @@ func (b *BinlogSyncer) writeRegisterSlaveCommand() error {
hostname := b.localHostname()

// This should be the name of slave host not the host we are connecting to.
data := make([]byte, 4+1+4+1+len(hostname)+1+len(b.cfg.User)+1+len(b.cfg.Password)+2+4+4)
data := make([]byte, 4+1+4+1+len(hostname)+1+len(b.cfg.User)+1+2+4+4)
pos := 4

data[pos] = COM_REGISTER_SLAVE
Expand All @@ -616,10 +616,8 @@ func (b *BinlogSyncer) writeRegisterSlaveCommand() error {
n = copy(data[pos:], b.cfg.User)
pos += n

data[pos] = uint8(len(b.cfg.Password))
data[pos] = uint8(0)
pos++
n = copy(data[pos:], b.cfg.Password)
pos += n

binary.LittleEndian.PutUint16(data[pos:], b.cfg.Port)
pos += 2
Expand Down

0 comments on commit 14069d3

Please sign in to comment.