sandynz opened a new issue #13408:
URL: https://github.com/apache/shardingsphere/issues/13408
## Bug Report
### Which version of ShardingSphere did you use?
5.0.0.
Commit: bf143245090a3b18589402d81ccddc68eab2e5c7
### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
ShardingSphere Proxy.
`scaling` is enabled in `server.yaml`.
### Expected behavior
Changed `actualDataNodes` of `tables` should be persited in rule cache.
### Actual behavior
Changes is not cached in rule cache
### Reason analyze (If you can)
Looks `AlterShardingTableRuleStatementPreprocessor` doesn't handle `tables`,
only `autoTables` is handled.
```
private void dropRuleConfiguration(final ShardingRuleConfiguration
preAlteredRuleConfig, final ShardingRuleConfiguration toBeAlteredRuleConfig) {
for (ShardingAutoTableRuleConfiguration each :
toBeAlteredRuleConfig.getAutoTables()) {
Optional<ShardingAutoTableRuleConfiguration>
shardingAutoTableRuleConfig
=
preAlteredRuleConfig.getAutoTables().stream().filter(tableRule ->
each.getLogicTable().equals(tableRule.getLogicTable())).findAny();
Preconditions.checkState(shardingAutoTableRuleConfig.isPresent());
preAlteredRuleConfig.getAutoTables().remove(shardingAutoTableRuleConfig.get());
preAlteredRuleConfig.getShardingAlgorithms().remove(shardingAutoTableRuleConfig.get().getShardingStrategy().getShardingAlgorithmName());
if (null !=
shardingAutoTableRuleConfig.get().getKeyGenerateStrategy()) {
preAlteredRuleConfig.getKeyGenerators().remove(shardingAutoTableRuleConfig.get().getKeyGenerateStrategy().getKeyGeneratorName());
}
}
}
private void addRuleConfiguration(final ShardingRuleConfiguration
currentRuleConfig, final ShardingRuleConfiguration toBeAlteredRuleConfig) {
currentRuleConfig.getAutoTables().addAll(toBeAlteredRuleConfig.getAutoTables());
currentRuleConfig.getShardingAlgorithms().putAll(toBeAlteredRuleConfig.getShardingAlgorithms());
currentRuleConfig.getKeyGenerators().putAll(toBeAlteredRuleConfig.getKeyGenerators());
}
```
### Steps to reproduce the behavior, such as: SQL to execute, sharding rule
configuration, when exception occur etc.
Register center (ZooKeeper) path `/metadata/sharding_db/rules` value:
```
- !SHARDING
bindingTables:
- t_order,t_order_item
defaultDatabaseStrategy:
standard:
shardingAlgorithmName: database_inline
shardingColumn: user_id
defaultTableStrategy:
none: ''
keyGenerators:
snowflake:
props:
worker-id: 123
type: SNOWFLAKE
shardingAlgorithms:
database_inline:
props:
algorithm-expression: ds_${user_id % 2}
type: INLINE
t_order_inline:
props:
algorithm-expression: t_order_${order_id % 2}
type: INLINE
t_order_item_inline:
props:
algorithm-expression: t_order_item_${order_id % 2}
type: INLINE
tables:
t_order:
actualDataNodes: ds_${0..1}.t_order_${0..1}
keyGenerateStrategy:
column: order_id
keyGeneratorName: snowflake
logicTable: t_order
tableStrategy:
standard:
shardingAlgorithmName: t_order_inline
shardingColumn: order_id
t_order_item:
actualDataNodes: ds_${0..1}.t_order_item_${0..1}
keyGenerateStrategy:
column: order_item_id
keyGeneratorName: snowflake
logicTable: t_order_item
tableStrategy:
standard:
shardingAlgorithmName: t_order_item_inline
shardingColumn: order_id
```
Run following DistSQL to update `actualDataNodes` of `t_order` and
`t_order_item`:
```
mysql> DROP SHARDING ALGORITHM database_inline;
Query OK, 0 rows affected (0.19 sec)
mysql> CREATE SHARDING ALGORITHM database_inline (
-> TYPE(NAME=INLINE,PROPERTIES("algorithm-expression"="ds_${user_id % 3
+ 2}"))
-> );
Query OK, 0 rows affected (0.03 sec)
mysql> ALTER SHARDING TABLE RULE t_order (
-> DATANODES("ds_${2..4}.t_order_${0..1}"),
->
DATABASE_STRATEGY(TYPE=standard,SHARDING_COLUMN=user_id,SHARDING_ALGORITHM=database_inline),
->
TABLE_STRATEGY(TYPE=standard,SHARDING_COLUMN=order_id,SHARDING_ALGORITHM=t_order_inline),
->
GENERATED_KEY(COLUMN=order_id,TYPE(NAME=snowflake,PROPERTIES("worker-id"=123)))
-> ), t_order_item (
-> DATANODES("ds_${2..4}.t_order_item_${0..1}"),
->
DATABASE_STRATEGY(TYPE=standard,SHARDING_COLUMN=user_id,SHARDING_ALGORITHM=database_inline),
->
TABLE_STRATEGY(TYPE=standard,SHARDING_COLUMN=order_id,SHARDING_ALGORITHM=t_order_item_inline),
->
GENERATED_KEY(COLUMN=order_item_id,TYPE(NAME=snowflake,PROPERTIES("worker-id"=123)))
-> );
Query OK, 0 rows affected (0.07 sec)
```
### Example codes for reproduce this issue (such as a github link).
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]