Skip to content

This fixes issue #34. Using the wrong hostname. #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 26, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions replication/binlogsyncer.go
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package replication
import (
"encoding/binary"
"fmt"
"os"
"sync"
"time"

@@ -25,10 +26,11 @@ type BinlogSyncer struct {
c *client.Conn
serverID uint32

host string
port uint16
user string
password string
localhost string
host string
port uint16
user string
password string

masterID uint32

@@ -62,6 +64,21 @@ func NewBinlogSyncer(serverID uint32, flavor string) *BinlogSyncer {
return b
}

// LocalHostname returns the hostname that register slave would register as.
func (b *BinlogSyncer) LocalHostname() string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should not export this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll make this lower cases. I'll change the name to localhostName().


if b.localhost == "" {
h, _ := os.Hostname()
return h
}
return b.localhost
}

// SetLocalHostname set's the hostname that register salve would register as.
func (b *NewBinlogSyncer) SetLocalHostname(name string) {
b.localhost = name
}

func (b *BinlogSyncer) Close() {
b.m.Lock()
defer b.m.Unlock()
@@ -222,11 +239,9 @@ func (b *BinlogSyncer) EnableSemiSync() error {
}

_, err := b.c.Execute(`SET @rpl_semi_sync_slave = 1;`)

if err != nil {
b.semiSyncEnabled = true
}

return errors.Trace(err)
}

@@ -402,7 +417,10 @@ func (b *BinlogSyncer) writeBinlogDumpMariadbGTIDCommand(gset GTIDSet) error {
func (b *BinlogSyncer) writeRegisterSlaveCommand() error {
b.c.ResetSequence()

data := make([]byte, 4+1+4+1+len(b.host)+1+len(b.user)+1+len(b.password)+2+4+4)
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.user)+1+len(b.password)+2+4+4)
pos := 4

data[pos] = COM_REGISTER_SLAVE
@@ -411,9 +429,10 @@ func (b *BinlogSyncer) writeRegisterSlaveCommand() error {
binary.LittleEndian.PutUint32(data[pos:], b.serverID)
pos += 4

data[pos] = uint8(len(b.host))
// This should be the name of slave hostname not the host we are connecting to.
data[pos] = uint8(len(hostname))
pos++
n := copy(data[pos:], b.host)
n := copy(data[pos:], hostname)
pos += n

data[pos] = uint8(len(b.user))