Shardingsphere: MasterSlave can not work well

Created on 27 Aug 2019  ·  24Comments  ·  Source: apache/shardingsphere

Bug Report

For English only, other languages will not accept.

Before report a bug, make sure you have:

Please pay attention on issues you submitted, because we maybe need more details.
If no response more than 7 days and we cannot reproduce it on current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

Which version of ShardingSphere did you use?

dev branch

Which project did you use? Sharding-JDBC or Sharding-Proxy?

Sharding-JDBC

Expected behavior

can work and no exception

Actual behavior

throw an exception

Reason analyze (If you can)

My code can work well few days ago.But today It can not work.I saw there is some commits
in nearly days. The key change is from the class TableMetaDataLoader. It seems something
between logicTable and actualTable was mess up.

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

bugfile

Example codes for reproduce this issue (such as a github link).

bugdetailnow

invalid

All 24 comments

@terrymanu My code can work well before I merged new changes from dev branch to local, so I think maybe it is a problem made by nearly refactor,but I am not sure about it.

Can you open sql.show and show me the log?
And check the database to find out whether admin.user_0 exists?

@tuohai666 This is no relationship between admin and user. I open sql.show,but nothings change in log.
image

If I turn it to old version,it can work well.
image

Here is the sql for craete table.
CREATE TABLE user_0 (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
name varchar(100) DEFAULT NULL,
ex_id int(11) DEFAULT NULL,
pre_name varchar(100) DEFAULT NULL,
name_assisted varchar(100) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE user_1 (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
name varchar(100) DEFAULT NULL,
ex_id int(11) DEFAULT NULL,
pre_name varchar(100) DEFAULT NULL,
name_assisted varchar(100) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE DATABASE IF NOT EXISTS demo_ds_master_0 default charset utf8 COLLATE utf8_general_ci;
CREATE DATABASE IF NOT EXISTS demo_ds_master_0_slave_0 default charset utf8 COLLATE utf8_general_ci;
CREATE DATABASE IF NOT EXISTS demo_ds_master_0_slave_1 default charset utf8 COLLATE utf8_general_ci;
CREATE DATABASE IF NOT EXISTS demo_ds_master_1 default charset utf8 COLLATE utf8_general_ci;
CREATE DATABASE IF NOT EXISTS demo_ds_master_1_slave_0 default charset utf8 COLLATE utf8_general_ci;
CREATE DATABASE IF NOT EXISTS demo_ds_master_1_slave_1 default charset utf8 COLLATE utf8_general_ci;

You don't need to know whether there's relationship between admin and user. If you just answer my question instead of think what I think, things may become easier.

I want to see logical SQL and actual SQL by open sql.show, is it the full log in the picture?

Can you point out which version is the "old version"?

Yes,it is the full log. And the "old version" is 4.0.0-RC2-release.

Can you check the database to find out whether admin.user_0 exists? Is 'admin' your database?

admin is in my database but admin.user_0 not exists.

Can you show me your url in datasource config? For example:
jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false

image

datasourceName is the key. I guess the datasourceName will be "admin" under certain condition. Can you debug to find all datasourceNames?

OK I will try.

I think I found the reason of this problem. Let me show my analysis.
TableMetaDataLoader.java in dev branch:

image

TableMetaDataLoader.java in 4.0.0-RC2-release:

image

In the dev branch,the masterSlave DataSourceName can not match the original DataSourceName in dataSourceMetaDataMap of DataSourceMetas.java. Some logic of masterSlave was removed in DataSourceMetas.

If that can not match, catalog will be null. If catalog will be null then the mysql will find the first datasource to search table,in my mysql,the first datasource is admin.

Nice analysis! Thanks. I'll check it.

@betterjava What's the version of your connector/j?

8.0.13

I have tried 5.1.47 & 8.0.17 but can't reproduce this Exception although the catalog is null.

8.0.13

As expected, this version throws Exception. I think this is a bug of connector/j. I will try to find it in release notes later.

I want to say the change in TableMetaDataLoader is right. This change will not cause issues if we use a proper version of connector/j

You can have a try with 8.0.17.

I tried 8.0.17 and it is work well. I will debug for find something different between 8.0.17 and 8.0.13.

I think you are right.
But in my opinion It is very strange for using masterSlave DatasourceName to match original DatasourceName in DataSourceMetas.
I test it for mysql-connector-java:8.0.11、8.0.12、8.0.13、8.0.14、8.0.15、8.0.16. It is all failed in dev version and all works well in 4.0.0-RC2-release.
Thanks for your help again.

This bug does not exist in the release notes:
https://dev.mysql.com/doc/relnotes/connector-j/8.0/en/news-8-0-17.html
Any way, they have already fixed it.
Thanks for your report.

Was this page helpful?
0 / 5 - 0 ratings