-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Conversation
When registering as a slave we are using the wrong hostname. It should be our hostname, not the hostname name of the server we are connecting to. Fixed issue with using the wrong variable.
user string | ||
password string | ||
// LocalHost is the name of you want to present to the MySQL master. If it is not set it will default to os.Hostname() | ||
LocalHost string |
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.
I think we should name it localHost or local?
lower case first.
btw, where to set this?
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.
We can change that. I was going to leave this as public, so that people can set this if they wanted. If they don't set it, it would default to os.Hostname(). If they set it, that's what we would send.
Here is where the check is done.
https://github.com/gdey/go-mysql/blob/2818d7e7c262a2307607238300e79c9033a3d027/replication/binlogsyncer.go#L68-L75
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.
I think supplying SetLocalHostname()
function to do this, not export struct member may be better. :-)
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.
Hi @gdey, how do you think?
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.
Sounds good. I'll make the change.
In #35 (comment) @siddontang said:
I'm not sure what you mean? I know I need register slave for what I'm doing. I do want to register as a slave; and receive the events. (Not just look at the binlog files.) However, what I discovered was that the name in the show slaves tables was wrong. It was showing the hostname of the master instead of the hostname of the slave. This is because we are sending the wrong hostname. This pull request fixes that. I not very good at naming things. And there were two ways I could have gone with this pull request. I took the more complicated route.
I went with option two just because it offers a bit more flexibility without too much added complexity. But willing to change it. |
@@ -62,6 +65,15 @@ func NewBinlogSyncer(serverID uint32, flavor string) *BinlogSyncer { | |||
return b | |||
} | |||
|
|||
func (b *BinlogSyncer) LocalHostname() string { |
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.
we should not export this function.
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.
Okay, I'll make this lower cases. I'll change the name to localhostName()
.
Hi @gdey What I mean is that we can sync mysql binlog too even we don't send register slave command. |
Well, the current implementation of register slave is wrong according to the docs. As it should be sending the slave's hostname, and not the hostname of the server it's connecting to. (or empty if we don't want to register as a slave). For me; I'm connecting as a slave, and so it's useful to have it register properly. from https://dev.mysql.com/doc/internals/en/com-register-slave.html:
https://dev.mysql.com/doc/refman/5.7/en/replication-options-slave.html#option_mysqld_report-host |
Made the LocalHost variable private and changed it's name to localhost. Added additional funciton SetLocalHostname to set the hostname to register as. Change getter methods name to match setter. Change it to LocalHostname().
This fixes issue #34. Using the wrong hostname.
LGTM |
请问一下,LocalHost可以不设置吗?默认的也不设置 |
@lwfofgit 我用google translation来翻译,所以不清楚。 |
BTW there is no function SetHostName. So how can I set LocalHostname? |
Seems it have been moved into a public config item go-mysql/replication/binlogsyncer.go Line 46 in c4a17aa
|
I use this config implicitly when creating syncer in Canal, here: https://github.com/go-mysql-org/go-mysql/blob/master/canal/canal.go#L435 Smth like: |
Hi @lance6716 , i opened related pull request #777 |
When registering as a slave we are using the wrong hostname. It should
be our hostname, not the hostname name of the server we are connecting
to.
Fixed issue with using the wrong variable.