Bug #12218 ReplicationDriver: wrong master connection is created
Submitted: 27 Jul 2005 17:28 Modified: 17 Oct 2005 19:42
Reporter: Keita Kitamura Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:3.1.10 OS:Any (any)
Assigned to: Mark Matthews CPU Architecture:Any

[27 Jul 2005 17:28] Keita Kitamura
Description:
It seems that there is incorrect code in com.mysql.jdbc.NonRegisteringReplicationDriver at line 53.

50:  public Connection connect(String url, Properties info) throws SQLException {
51:    Properties parsedProps = parseURL(url, info);
52:
53:    Properties masterProps = parsedProps;
54:    Properties slavesProps = parsedProps;

In this case, masterProps and slavesProps object will be totally same instance since parsedProps object is passed by reference, which means if you put some properties on masterProps object, it also affects slavesProps object. I mean that slavesProps refer the exactly same memory address as masterProps is. This wrong assigned value causes a problem at line 104 that the masterHost string is put on masterProps object but next line, it will be overwroted by slaveHosts string, so there will be no "real" master connection at all.
Actually, a master connection that connected to one of the slave servers will be created so you can execute CRUD statement to the matser connection but it affects only one slave server instead of master server and will not replicate to any servers.

By the way, I think here is also serious issue in ReplicationDriver.
http://bugs.mysql.com/bug.php?id=11879

As far as I know, as of version 3.1.10, ReplicationDriver does not work at all unless fix thoese issues.

How to repeat:
Connection conn = new ReplicationDriver().connect(
    "jdbc:mysql://127.0.0.1:3306,127.0.0.1:3307,127.0.0.1:3308/test", props);

conn.setReadOnly(false);
conn.setAutoCommit(false);
conn.createStatement().executeUpdate("update ,,,");
conn.commit();
conn.close();

then check 127.0.0.1:3306/test database.
It should be that the update statement wan't affected.

Suggested fix:
At line 53 and 54, there should be passed by a copy object.

53:    Properties masterProps = (Properties)parsedProps.clone();
54:    Properties slavesProps = (Properties)parsedProps.clone();