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/27 04:44:37 UTC
[GitHub] [shardingsphere] happypleasure opened a new issue #14335: Route table ** does not exist, available actual table
happypleasure opened a new issue #14335:
URL: https://github.com/apache/shardingsphere/issues/14335
## Exception message
Cause: org.apache.shardingsphere.infra.exception.ShardingSphereException: Route table t_test_66 does not exist, available actual table: [t_test_00, t_test_01, t_test_02, t_test_03, t_test_04, t_test_05, t_test_06, t_test_07, t_test_08, t_test_09]] with root cause
## Dependent jar
```
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core</artifactId>
<version>5.0.0</version>
</dependency>
```
## YAML Configuration
```
tables:
t_test:
actualDataNodes: write_ds0.t_test_0${0..9},write_ds1.t_test_1${0..9},write_ds2.t_test_2${0..9},write_ds3.t_test_3${0..9},write_ds4.t_test_4${0..9},write_ds5.t_test_5${0..9},write_ds6.t_test_6${0..9},write_ds7.t_test_7${0..9},write_ds8.t_test_8${0..9},write_ds9.t_test_9${0..9}
databaseStrategy:
standard:
shardingColumn: user_id
shardingAlgorithmName: t_test_db_inline
tableStrategy:
standard:
shardingColumn: user_id
shardingAlgorithmName: t_test_table_inline
shardingAlgorithms:
t_test_db_inline:
type: INLINE
props:
algorithm-expression: "write_ds${Math.abs(user_id.hashCode() % 100) / 10}"
t_test_table_inline:
type: INLINE
props:
algorithm-expression: "t_test_${def num = Math.abs(user_id.hashCode() % 100); return num > 9 ? num : '0' + num}"
```
## Execute SQL
```
select * from t_test where user_id = #{userId}
```
## Reason analyze
- use shardingsphere-jdbc-core.5.0.0-alpha version can be executed correctly
- debug error location
- shardingsphere-jdbc-core.5.0.0
- org.apache.shardingsphere.sharding.route.strategy.type.standard.StandardShardingStrategy#doSharding
```
private Collection<String> doSharding(final Collection<String> availableTargetNames, final ListShardingConditionValue<?> shardingValue) {
Collection<String> result = new LinkedList<>();
for (Comparable<?> each : shardingValue.getValues()) {
String target;
target = shardingAlgorithm.doSharding(availableTargetNames, new PreciseShardingValue(shardingValue.getTableName(), shardingValue.getColumnName(), each));
if (null != target && availableTargetNames.contains(target)) {
result.add(target);
} else if (null != target && !availableTargetNames.contains(target)) {
throw new ShardingSphereException(String.format("Route table %s does not exist, available actual table: %s", target, availableTargetNames));
}
}
return result;
}
```
- shardingsphere-jdbc-core.5.0.0-alpha
- org.apache.shardingsphere.sharding.route.strategy.type.standard.StandardShardingStrategy#doSharding
```
private Collection<String> doSharding(final Collection<String> availableTargetNames, final ListShardingConditionValue<?> shardingValue) {
Collection<String> result = new LinkedList<>();
for (Comparable<?> each : shardingValue.getValues()) {
String target;
target = shardingAlgorithm.doSharding(availableTargetNames, new PreciseShardingValue(shardingValue.getTableName(), shardingValue.getColumnName(), each));
if (null != target && availableTargetNames.contains(target)) {
result.add(target);
}
}
return result;
}
```
--
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] zjcnb commented on issue #14335: Route table ** does not exist, available actual table
Posted by GitBox <gi...@apache.org>.
zjcnb commented on issue #14335:
URL: https://github.com/apache/shardingsphere/issues/14335#issuecomment-1001455537
@happypleasure Hi, i will check 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] zjcnb edited a comment on issue #14335: Route table ** does not exist, available actual table
Posted by GitBox <gi...@apache.org>.
zjcnb edited a comment on issue #14335:
URL: https://github.com/apache/shardingsphere/issues/14335#issuecomment-1002093901
You can try to change `algorithm-expression: "t_test_${def num = Math.abs(user_id.hashCode() % 100); return num > 9 ? num : '0' + num}"` to `algorithm-expression: "t_test_${def num = Math.abs(user_id.hashCode() % 10); return num > 9 ? num : '0' + num}"`.
--
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] zjcnb edited a comment on issue #14335: Route table ** does not exist, available actual table
Posted by GitBox <gi...@apache.org>.
zjcnb edited a comment on issue #14335:
URL: https://github.com/apache/shardingsphere/issues/14335#issuecomment-1002139891
@happypleasure Can you provider a demo?
--
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] zjcnb commented on issue #14335: Route table ** does not exist, available actual table
Posted by GitBox <gi...@apache.org>.
zjcnb commented on issue #14335:
URL: https://github.com/apache/shardingsphere/issues/14335#issuecomment-1002139891
@happypleasure You can provider your demo?
--
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] happypleasure commented on issue #14335: Route table ** does not exist, available actual table
Posted by GitBox <gi...@apache.org>.
happypleasure commented on issue #14335:
URL: https://github.com/apache/shardingsphere/issues/14335#issuecomment-1005684197
The reason has been found.
My project uses Java API to configure the sharding rules. The shardingColumn in database routing expression is incorrectly configured, resulting database routing errors
Sorry to trouble, Thank you @zjcnb
--
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] happypleasure closed issue #14335: Route table ** does not exist, available actual table
Posted by GitBox <gi...@apache.org>.
happypleasure closed issue #14335:
URL: https://github.com/apache/shardingsphere/issues/14335
--
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] zjcnb commented on issue #14335: Route table ** does not exist, available actual table
Posted by GitBox <gi...@apache.org>.
zjcnb commented on issue #14335:
URL: https://github.com/apache/shardingsphere/issues/14335#issuecomment-1002093901
You can try to change `algorithm-expression: "t_test_${def num = Math.abs(user_id.hashCode() % 100); return num > 9 ? num : '0' + num}"` to algorithm-expression: "t_test_${def num = Math.abs(user_id.hashCode() % 10); return num > 9 ? num : '0' + num}".
--
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] happypleasure commented on issue #14335: Route table ** does not exist, available actual table
Posted by GitBox <gi...@apache.org>.
happypleasure commented on issue #14335:
URL: https://github.com/apache/shardingsphere/issues/14335#issuecomment-1002134657
The expression (“t_test_${def num = Math.abs(user_id.hashCode() % 10); return num > 9 ? num : '0' + num}” ) can not match sharding rule.
actualDataNodes: write_ds0.t_test_0${0..9},write_ds1.t_test_1${0..9},write_ds2.t_test_2${0..9},write_ds3.t_test_3${0..9},write_ds4.t_test_4${0..9},write_ds5.t_test_5${0..9},write_ds6.t_test_6${0..9},write_ds7.t_test_7${0..9},write_ds8.t_test_8${0..9},write_ds9.t_test_9${0..9}
database table relation
```
database : tables
write_ds0 : t_test_00, t_test_01, ... t_test_09
write_ds1 : t_test_10, t_test_11, ... t_test_19
write_ds6 : t_test_60, t_test_61, ... t_test_69
. .
. .
write_ds9 : t_test_90, t_test_91, ... t_test_99
```
if (user_id.hashCode() % 100) equal 66 , it should route to database “write_ds6" table "t_test_66"
@zjcnb
--
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] happypleasure commented on issue #14335: Route table ** does not exist, available actual table
Posted by GitBox <gi...@apache.org>.
happypleasure commented on issue #14335:
URL: https://github.com/apache/shardingsphere/issues/14335#issuecomment-1001516215
Waiting the reply @zjcnb
--
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