You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/12/29 04:40:43 UTC
[GitHub] [shardingsphere] setamv opened a new issue #14401: SingleTableDataNodeLoader will load sharding table by mistake when sharding table names are lowercase in db and uppercase in sharding rule config
setamv opened a new issue #14401:
URL: https://github.com/apache/shardingsphere/issues/14401
## Bug Report
**For English only**, other languages will not accept.
### Which version of ShardingSphere did you use?
5.0.0
### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
ShardingSphere-JDBC
### Expected behavior
sharding tables are not loaded into single org.apache.shardingsphere.singletable.rule.SingleTableRule#singleTableDataNodes
### Actual behavior
SingleTableDataNodeLoader will load sharding table by mistake when sharding table names are lowercase in db and uppercase in sharding rule config
### Reason analyze (If you can)
1. `SingleTableDataNodeLoader#load()` will accept `excludedTables` argument to excelude sharding tables while loading single tables. The value passed to `excludedTables` argument is the result of `SingleTableRule#getExcludedTables()`
2. `SingleTableRule#getExcludedTables()` will invoke `ShardingRule#getAllTables()` to get sharding table names from sharding rule config, which will kept case the same with config.
for example, when the table `order`'s `actual-data-nodes` is configed as `ds0.ORDER_$->{0..1},ds1.ORDER_$->{2..3}`, the result of `ShardingRule#getAllTables()` will be ["ORDER_0", "ORDER_1", "ORDER_2", "ORDER_3"]. the test cases as follows:

3. when table names in database are lower case, the `excludeTables` can not actual exclude the lower case sharding table names as follows, and the sharding table names from database will be added to `SingleTableRule#singleTableDataNodes`:

### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
### Example codes for reproduce this issue (such as a github link).
1. test case in `org.apache.shardingsphere.sharding.rule.ShardingRuleTest`:
```
@Test
public void assertGetAllTables() {
ShardingTableRuleConfiguration tableRuleConfig = new ShardingTableRuleConfiguration("LOGIC_TABLE", "ds0.ORDER_$->{0..1},ds1.ORDER_$->{2..3}");
tableRuleConfig.setDatabaseShardingStrategy(new NoneShardingStrategyConfiguration());
tableRuleConfig.setTableShardingStrategy(new NoneShardingStrategyConfiguration());
tableRuleConfig.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("col_1", "increment"));
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.setTables(Arrays.asList(tableRuleConfig));
ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, Arrays.asList("ds0", "ds1"));
Collection<String> allTables = shardingRule.getAllTables();
assertTrue(allTables.contains("ORDER_0"));
assertTrue(allTables.contains("ORDER_1"));
assertTrue(allTables.contains("ORDER_2"));
assertTrue(allTables.contains("ORDER_3"));
assertTrue(!allTables.contains("order_0"));
assertTrue(!allTables.contains("order_1"));
}
```
2. test case in `org.apache.shardingsphere.singletable.rule.SingleTableDataNodeLoaderTest`
```
@Before
public void setUp() throws SQLException {
dataSourceMap = new LinkedHashMap<>(2, 1);
// assume the table "order" is sharding by order_id, and the "actual-data-nodes" in sharding rule config is: ds0.ORDER_$->{0..1},ds1.ORDER_$->{2..3}(attention the table name is uppercase)
dataSourceMap.put("ds0", mockDataSource("ds0", Arrays.asList("employee", "dept", "salary", "order_0", "order_1")));
dataSourceMap.put("ds1", mockDataSource("ds1", Arrays.asList("student", "teacher", "class", "salary", "order_2", "order_3")));
}
@Test
public void assertLoad() {
ConfigurationProperties props = new ConfigurationProperties(new Properties());
Map<String, SingleTableDataNode> dataNodeMap = SingleTableDataNodeLoader.load(mock(DatabaseType.class), dataSourceMap, getExcludedTablesFromShardingRule(), props);
assertTrue(dataNodeMap.containsKey("employee"));
assertTrue(dataNodeMap.containsKey("dept"));
assertTrue(dataNodeMap.containsKey("salary"));
assertTrue(dataNodeMap.containsKey("student"));
assertTrue(dataNodeMap.containsKey("teacher"));
assertTrue(dataNodeMap.containsKey("class"));
// wrong result, it shouldn't contain sharding table in single table data nodes.
assertTrue(dataNodeMap.containsKey("order_0"));
assertTrue(dataNodeMap.containsKey("order_1"));
assertTrue(dataNodeMap.containsKey("order_2"));
assertTrue(dataNodeMap.containsKey("order_3"));
assertThat(dataNodeMap.get("employee").getDataSourceName(), is("ds0"));
assertThat(dataNodeMap.get("dept").getDataSourceName(), is("ds0"));
assertThat(dataNodeMap.get("salary").getDataSourceName(), is("ds0"));
assertThat(dataNodeMap.get("student").getDataSourceName(), is("ds1"));
assertThat(dataNodeMap.get("teacher").getDataSourceName(), is("ds1"));
assertThat(dataNodeMap.get("class").getDataSourceName(), is("ds1"));
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] setamv closed issue #14401: SingleTableDataNodeLoader will load sharding table by mistake when sharding table names are lowercase in db and uppercase in sharding rule config
Posted by GitBox <gi...@apache.org>.
setamv closed issue #14401:
URL: https://github.com/apache/shardingsphere/issues/14401
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] setamv commented on issue #14401: SingleTableDataNodeLoader will load sharding table by mistake when sharding table names are lowercase in db and uppercase in sharding rule config
Posted by GitBox <gi...@apache.org>.
setamv commented on issue #14401:
URL: https://github.com/apache/shardingsphere/issues/14401#issuecomment-1002408432
> 1. SingleTableDataNodeLoader
yes, the master branch has fixed the problem. thank you.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] setamv commented on issue #14401: SingleTableDataNodeLoader will load sharding table by mistake when sharding table names are lowercase in db and uppercase in sharding rule config
Posted by GitBox <gi...@apache.org>.
setamv commented on issue #14401:
URL: https://github.com/apache/shardingsphere/issues/14401#issuecomment-1002407107
> Hi @setamv thank you for your feedback. Can you try the master branch? I think this bug has been fixed.
ok, i'll try it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] setamv commented on issue #14401: SingleTableDataNodeLoader will load sharding table by mistake when sharding table names are lowercase in db and uppercase in sharding rule config
Posted by GitBox <gi...@apache.org>.
setamv commented on issue #14401:
URL: https://github.com/apache/shardingsphere/issues/14401#issuecomment-1002408946
> Hi @setamv thank you for your feedback. Can you try the master branch? I think this bug has been fixed.
My i ask when the version 5.0.1 will released? Is there a release plan?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] strongduanmu commented on issue #14401: SingleTableDataNodeLoader will load sharding table by mistake when sharding table names are lowercase in db and uppercase in sharding rule config
Posted by GitBox <gi...@apache.org>.
strongduanmu commented on issue #14401:
URL: https://github.com/apache/shardingsphere/issues/14401#issuecomment-1002403708
Hi @setamv thank you for your feedback. Can you try the master branch? I think this bug has been fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] strongduanmu commented on issue #14401: SingleTableDataNodeLoader will load sharding table by mistake when sharding table names are lowercase in db and uppercase in sharding rule config
Posted by GitBox <gi...@apache.org>.
strongduanmu commented on issue #14401:
URL: https://github.com/apache/shardingsphere/issues/14401#issuecomment-1002414151
@setamv The 5.1.0 release is currently in progress, you can focus on the mailing list.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org