You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2019/01/22 09:09:27 UTC
[GitHub] neil4dong opened a new issue #1795: wrong sharding-value make wrong
route
neil4dong opened a new issue #1795: wrong sharding-value make wrong route
URL: https://github.com/apache/incubator-shardingsphere/issues/1795
## Bug Report
**For English only**, other languages will not accept.
Before report a bug, make sure you have:
- Searched open and closed [GitHub issues](https://github.com/sharding-sphere/sharding-sphere/issues).
- Read documentation: [ShardingSphere Doc](http://shardingsphere.io/document/current/en/overview/).
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?
1.5.4.1 the last version of 1.x
### Which project did you use?
Sharding-JDBC
### Expected behavior
route to order_03 ,because of user_id = 3
### Actual behavior
route to order_07, and debug in the code below, the shardingValue is 7, It seems the store_id has been wrongly used。
```
public final class SingleKeyModuloTableShardingAlgorithm implements SingleKeyTableShardingAlgorithm<Long> {
private int tableCount = 100;
@Override
public String doEqualSharding(final Collection<String> availableTargetNames, final ShardingValue<Long> shardingValue) {
for (String each : availableTargetNames) {
if (each.endsWith(String.format("%02d", shardingValue.getValue() % tableCount))) {
return each;
}
}
throw new UnsupportedOperationException();
}
@Override
public Collection<String> doInSharding(final Collection<String> availableTargetNames, final ShardingValue<Long> shardingValue) {
Collection<String> result = new LinkedHashSet<>(availableTargetNames.size());
Collection<Long> values = shardingValue.getValues();
for (Long value : values) {
for (String each : availableTargetNames) {
if (each.endsWith(String.format("%02d", value % tableCount))) {
result.add(each);
}
}
}
return result;
}
@Override
public Collection<String> doBetweenSharding(final Collection<String> availableTargetNames, final ShardingValue<Long> shardingValue) {
Collection<String> result = new LinkedHashSet<>(availableTargetNames.size());
Range<Long> range = shardingValue.getValueRange();
for (Long i = range.lowerEndpoint(); i <= range.upperEndpoint(); i++) {
for (String each : availableTargetNames) {
if (each.endsWith(String.format("%02d", i % tableCount))) {
result.add(each);
}
}
}
return result;
}
/**
* @param tableCount
*/
public void setTableCount(int tableCount) {
this.tableCount = tableCount;
}
public int getTableCount() {
return tableCount;
}
}
```
### Reason analyze (If you can)
something going wrong in the process of finding sharding-value
### 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).
This is the generated sql with param:
```
UPDATE order_07
SET external_store_code =
CASE
WHEN external_store_code IS NULL OR external_store_code = ''
THEN
?
ELSE external_store_code
END,
store_id =
CASE
WHEN store_id IS NULL
THEN
?
ELSE store_id
END,
store_name =
CASE
WHEN store_name IS NULL
THEN
?
ELSE store_name
END
WHERE
id = ?
AND user_id = ?;
```
::: [1012, **7**, 门店名称, 11111111, 3]
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services