Bug #81108 FabricMySQLConnectionProxy.setShardTable method logic miss
Submitted: 17 Apr 2016 1:42 Modified: 11 Jan 2020 16:59
Reporter: sea gh Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:5.1.38 OS:Any
Assigned to: CPU Architecture:Any
Tags: FabricMySQLConnectionProxy setShardTable

[17 Apr 2016 1:42] sea gh
Description:
I created shard mapping by the folowing command:
mysqlfabric sharding add_table 1 mysql_fabric.employees emp_no,
---------------------------
but when I use connector/J to operate db like this:
ds.setFabricShardTable("mysql_fabric.employees");
--------------------------
An exception occured:
Exception in thread "main" java.sql.SQLException: Shard mapping not found for table `mysql_fabric.employees'
	at com.mysql.fabric.jdbc.FabricMySQLDriver.connect(FabricMySQLDriver.java:80)
	at com.mysql.fabric.jdbc.FabricMySQLDataSource.getConnection(FabricMySQLDataSource.java:125)
	at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:134)

How to repeat:
Rerun the demo named EmployeesDataSource.java distributed in the src of mysql-connector-java-5.1.38,it will fail at the  85th line:
ds.setFabricShardTable("employee.employees");

Suggested fix:

Following code is copied from com.mysql.fabric.jdbc.FabricMySQLConnectionProxy.java
public void setShardTable(String shardTable) throws SQLException {
           //.....
           if (shardTable.contains(".")) {
                String pair[] = shardTable.split("\\.");
                table = pair[0];
                db = pair[1];
            }
           //.....
}
------
Generally we define shard table like this format:db_name.tbl_name,so maybe the following logic is more reasonable?
 if (shardTable.contains(".")) {
                String pair[] = shardTable.split("\\.");
                db = pair[0];
                table = pair[1]; 
            }
[11 May 2016 6:41] Chiranjeevi Battula
Hello sea gh,

Thank you for the bug report.
Verified based on internal discussion with dev's.

Thanks,
Chiranjeevi.
[18 Jul 2016 13:00] Chiranjeevi Battula
http://bugs.mysql.com/bug.php?id=82245 marked as duplicate of this one.