mysql-binlog-connector-java icon indicating copy to clipboard operation
mysql-binlog-connector-java copied to clipboard

Make BinaryLogClient#connect() more intuitive

Open mrkamel opened this issue 9 years ago • 2 comments

Hi,

i'm wondering: BinaryLogClient#connect() should be blocking and usually is at first, but when i restart mysql after connect() is called, connect() no longer blocks, but is returning, and mysql-binlog-connector seems to then reconnect in a new thread:

BinaryLogClient client = new BinaryLogClient(...)
client.registerEventListener(...)
client.connect() // blocking

// now restart mysql

System.out.println("huh?"); // gets printed, but after some time mysql-binlog-connector reconnects

I think this behaviour is somewhat counter-intuitive and is causing issues for my use case where i'm using zookeeper (via apache curator) for leader election, because due to client.connect() returning after disconnects, such that the leader thread returns and is shut down, ... then a new leader is elected, but mysql-binlog-connector reconnects after some in the old-leader such that i'm having 2 binlog listeners in the end.

question 1) how do i (can i?) disable automatic reconnects and get an exception raised for disconnects instead?

question 2) what is the (your) recommended way to get blocking behaviour even for disconnects? something like:

BinaryLogClient client = new BinaryLogClient(...)
client.registerEventListener(...)
client.connect()

while(true)
  Thread.sleep(10000); // to "fake" blocking behaviour

Thanks in advance

mrkamel avatar Jul 01 '16 20:07 mrkamel

Found out all myself.

Still think it's somewhat counter-intuitive when client.connect() is returning, though it shouldn't, especially because the docs say it's blocking, but i understand the intention and relationship to keepalive.

Thanks

mrkamel avatar Jul 01 '16 21:07 mrkamel

@mrkamel I think you're right. I'm reopening issue as a reminder that this needs to be addressed as part of 1.0.0. Thanks!

shyiko avatar Jul 02 '16 18:07 shyiko