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:
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
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);
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.

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://,,", props);

conn.createStatement().executeUpdate("update ,,,");

then check 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();