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 2022/10/10 06:30:29 UTC

[GitHub] [shardingsphere] liruhui opened a new issue, #15706: Insert statement does not support sharding table routing to multiple data nodes.

liruhui opened a new issue, #15706:
URL: https://github.com/apache/shardingsphere/issues/15706

   ## CODE
   
   ```java
       public static void main(String[] args) throws SQLException {
           Map<String, DataSource> dataSourceMap = Demo1DatasourceUtils.createDataSourceMap();
           ShardingRuleConfiguration configuration  = new ShardingRuleConfiguration();
   
           //设置分片规则
           ShardingTableRuleConfiguration shardingTableRuleConfiguration = new ShardingTableRuleConfiguration("abc", "sharding4.brand${1..2}}");
           Properties properties  = new Properties();
           properties.setProperty("sharding-count","2");
           configuration.getShardingAlgorithms().put("mod",new ShardingSphereAlgorithmConfiguration("MOD",properties));
   
           //定义分表策略
           StandardShardingStrategyConfiguration standardShardingStrategyConfiguration  = new StandardShardingStrategyConfiguration("id","mod");
   
           configuration.getTables().add(shardingTableRuleConfiguration);
           shardingTableRuleConfiguration.setTableShardingStrategy(standardShardingStrategyConfiguration);
           DataSource dataSource = ShardingSphereDataSourceFactory.createDataSource(dataSourceMap, Collections.singleton(configuration), new Properties());
           dataSource.getConnection().prepareStatement("insert into abc(`id`,brand_name) values(2,'xxxxxx')").execute();
           dataSource.getConnection().prepareStatement("insert into abc(`id`,brand_name) values(3,'xxxxx')").execute();
       }
   ```
   ## ERROR INFO  
   
   ```java
   Exception in thread "main" java.lang.IllegalStateException: Insert statement does not support sharding table routing to multiple data nodes.
   	at com.google.common.base.Preconditions.checkState(Preconditions.java:508)
   	at org.apache.shardingsphere.sharding.route.engine.validator.dml.impl.ShardingInsertStatementValidator.postValidate(ShardingInsertStatementValidator.java:101)
   	at org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter.lambda$createRouteContext$1(ShardingSQLRouter.java:57)
   	at java.base/java.util.Optional.ifPresent(Optional.java:183)
   	at org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter.createRouteContext(ShardingSQLRouter.java:57)
   	at org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter.createRouteContext(ShardingSQLRouter.java:44)
   	at org.apache.shardingsphere.infra.route.engine.impl.PartialSQLRouteExecutor.route(PartialSQLRouteExecutor.java:73)
   	at org.apache.shardingsphere.infra.route.engine.SQLRouteEngine.route(SQLRouteEngine.java:53)
   	at org.apache.shardingsphere.infra.context.kernel.KernelProcessor.route(KernelProcessor.java:54)
   	at org.apache.shardingsphere.infra.context.kernel.KernelProcessor.generateExecutionContext(KernelProcessor.java:46)
   	at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.createExecutionContext(ShardingSpherePreparedStatement.java:431)
   	at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.execute(ShardingSpherePreparedStatement.java:337)
   	at com.huige.cn.demo1.example.Example1.main(Example1.java:38)
   
   Process finished with exit code 1
   ````


-- 
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.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] wuweiit commented on issue #15706: Insert statement does not support sharding table routing to multiple data nodes.

Posted by GitBox <gi...@apache.org>.
wuweiit commented on issue #15706:
URL: https://github.com/apache/shardingsphere/issues/15706#issuecomment-1095024919

   @RaigorJiang 5.1.0  use mybatis plus generate insert SQL:
   
   ```
   insert into order_payment_log(id, create_at, ...) values(?,?, .....)
   ```
   
   In the verification phase of insert SQL, an exception is thrown. Then I use debug to modify the variable `isSingleDataNode` to true. After releasing the execution, the SQL is output normally
   ```
   insert into order_payment_log_2022(id, create_at, ...) values(?,?, .....)
   ```
   So I guess it's whether the judgment of that code is reversed.
   
   


-- 
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] wuweiit commented on issue #15706: Insert statement does not support sharding table routing to multiple data nodes.

Posted by GitBox <gi...@apache.org>.
wuweiit commented on issue #15706:
URL: https://github.com/apache/shardingsphere/issues/15706#issuecomment-1095832011

   @RaigorJiang In today's test, it was found that the level of yaml configuration file was wrong, resulting in the incorrect reading of segmentation algorithm, which was embarrassing. However, this exception can be optimized. If the multi node fragmentation algorithm is configured and the error log with clear points is not configured, it is convenient to analyze the problem


-- 
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] github-actions[bot] closed issue #15706: Insert statement does not support sharding table routing to multiple data nodes.

Posted by GitBox <gi...@apache.org>.
github-actions[bot] closed issue #15706: Insert statement does not support sharding table routing to multiple data nodes.
URL: https://github.com/apache/shardingsphere/issues/15706


-- 
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] wuweiit commented on issue #15706: Insert statement does not support sharding table routing to multiple data nodes.

Posted by GitBox <gi...@apache.org>.
wuweiit commented on issue #15706:
URL: https://github.com/apache/shardingsphere/issues/15706#issuecomment-1094707683

   ```
   Caused by: java.lang.IllegalStateException: Insert statement does not support sharding table routing to multiple data nodes.
   	at com.google.common.base.Preconditions.checkState(Preconditions.java:508)
   	at org.apache.shardingsphere.sharding.route.engine.validator.dml.impl.ShardingInsertStatementValidator.postValidate(ShardingInsertStatementValidator.java:101)
   	at org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter.lambda$createRouteContext$1(ShardingSQLRouter.java:57)
   	at org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter$$Lambda$2434/3146819.accept(Unknown Source)
   ```
   I have the same problem,By looking at the source code, I found that there seems to be a problem with this judgment,this code 
   
   
   ShardingInsertStatementValidator.class 99 lines
   ```
    if (!routeContext.isSingleRouting() && !shardingRule.isBroadcastTable(tableName)) {
               boolean isSingleDataNode = routeContext.getOriginalDataNodes().stream().allMatch(dataNodes -> dataNodes.size() == 1);
               Preconditions.checkState(isSingleDataNode, "Insert statement does not support sharding table routing to multiple data nodes.");
           }
   ```
   
   `!routeContext.isSingleRouting()` this is mulitRouting
   `isSingleDataNode` is false
   so throw exception "Insert statement does not support sharding table routing to multiple data nodes."
   
   my config:
   ```
       rules:
         sharding: 
           tables:
             order_payment_log: # 指定的数据库名
               actualDataNodes: hallservice.order_payment_log_$->{2022..2050}
               tableStrategy:
                 standard: # 指定t_student表的分片策略,分片策略包括分片键和分片算法
                   shardingColumn: created_at
                   shardingAlgorithmName: my-time
               keyGenerator: # 指定 表的主键生成策略为SNOWFLAKE
                 type: SNOWFLAKE  #主键生成策略为SNOWFLAKE
                 column: id  #指定主键 
         shardingAlgorithms:
           my-time:
             type: interval
             props:
               datetime-lower: '2022-01-01 00:00:00'
               datetime-upper: '2050-12-01 00:00:00'
               datetime-pattern: "yyyy-MM-dd HH:mm:ss"
               sharding-suffix-pattern: "yyyy"
               datetime-interval-amount: 1
               datetime-interval-unit: years
   ```
   
   
   


-- 
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] RaigorJiang commented on issue #15706: Insert statement does not support sharding table routing to multiple data nodes.

Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on issue #15706:
URL: https://github.com/apache/shardingsphere/issues/15706#issuecomment-1095138590

   @wuweiit 
   OK, thanks for your feedback. 
   
   Hi @tuichenchuxin , could you help investigate?


-- 
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] RaigorJiang commented on issue #15706: Insert statement does not support sharding table routing to multiple data nodes.

Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on issue #15706:
URL: https://github.com/apache/shardingsphere/issues/15706#issuecomment-1095888291

   @wuweiit 
   OK, thanks for your feedback. The exception prompt is a very important suggestion, and you are also welcome to submit a PR to participate together.


-- 
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] github-actions[bot] commented on issue #15706: Insert statement does not support sharding table routing to multiple data nodes.

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on issue #15706:
URL: https://github.com/apache/shardingsphere/issues/15706#issuecomment-1272350286

   Hello , this issue has not received a reply for several days.
   This issue is supposed to be closed.


-- 
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] RaigorJiang commented on issue #15706: Insert statement does not support sharding table routing to multiple data nodes.

Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on issue #15706:
URL: https://github.com/apache/shardingsphere/issues/15706#issuecomment-1094922522

   Hi @wuweiit 
   What's your version and insert SQL?


-- 
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] RaigorJiang commented on issue #15706: Insert statement does not support sharding table routing to multiple data nodes.

Posted by "RaigorJiang (via GitHub)" <gi...@apache.org>.
RaigorJiang commented on issue #15706:
URL: https://github.com/apache/shardingsphere/issues/15706#issuecomment-1407580589

   This issue has been inactive for a long time, so I will close it.
   If this problem persists, please reopen it or submit a new one.


-- 
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] RaigorJiang closed issue #15706: Insert statement does not support sharding table routing to multiple data nodes.

Posted by "RaigorJiang (via GitHub)" <gi...@apache.org>.
RaigorJiang closed issue #15706: Insert statement does not support sharding table routing to multiple data nodes.
URL: https://github.com/apache/shardingsphere/issues/15706


-- 
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