Bug #2578 in failover, connectorJ always connect to last server specified in the URL
Submitted: 30 Jan 2004 6:14 Modified: 6 Feb 2004 9:01
Reporter: [ name withheld ] Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S1 (Critical)
Version:3.0.10 OS:Linux (Linux)
Assigned to: Mark Matthews CPU Architecture:Any

[30 Jan 2004 6:14] [ name withheld ]
Description:
In HighAvailability
The method createNewIO in Connection always return a MysqlIO linked with the last server of the list specified in the URL.

So it makes troubles when the server stop.

How to repeat:
need 2 Mysql servers and a client doing always the same request (a simple SELECT) with a URL containing the 2 servers addresses.

You can verify on the second server with show processlist, that connections are made on this server and not on the other one.

Suggested fix:
The problem is in the big else part of the method createNewIO of Connection.

There is only a break for the second "for" loop (which is inside the first). When we break, we continue with the first "for" loop that tries the next servers.

Before the block (call it block 1)
if (!connectionGood) {
    // We've really failed!
    throw new SQLException(
       "Server connection failure during transaction. Due to underlying ... "+ SQLError.SQL_STATE_UNABLE_TO_CONNECT_TO_DATASOURCE);
}
which is at the end of the first "for" loop
add (block 2)
if (connectionGood) {
    break;
}
so it will liver the first loop as soon as a connection is valid.

The block 2, must move out of the first loop: An exception must be thrown only if we cannot connect to no server.
Put it just after the } of the loop.
[6 Feb 2004 9:01] Mark Matthews
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html