TongRuii opened a new issue #4276: No available sharding rule configuration in 
`logic_db` for orchestration.
URL: https://github.com/apache/incubator-shardingsphere/issues/4276
 
 
   ## Question
   
   **I just want to :**
   - sharding database with hit
   -  Dynamic configuration
   so i use orchestration 
   ```
           <dependency>
               <groupId>org.apache.shardingsphere</groupId>
               
<artifactId>sharding-jdbc-orchestration-spring-boot-starter</artifactId>
               <version>4.0.0</version>
           </dependency>
   
           <dependency>
               <groupId>org.apache.shardingsphere</groupId>
               
<artifactId>sharding-orchestration-reg-zookeeper-curator</artifactId>
               <version>4.0.0</version>
           </dependency>
   ```
   ```
   spring.shardingsphere.datasource.names=db0,db1,db2
   
   spring.shardingsphere.datasource.db0.driver-class-name=com.mysql.jdbc.Driver
   
spring.shardingsphere.datasource.db0.url=jdbc:mysql://127.0.0.1:3306/db0?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
   spring.shardingsphere.datasource.db0.username=root
   spring.shardingsphere.datasource.db0.password=root
   
spring.shardingsphere.datasource.db0.type=com.alibaba.druid.pool.DruidDataSource
   
   spring.shardingsphere.datasource.db1.driver-class-name=com.mysql.jdbc.Driver
   
spring.shardingsphere.datasource.db1.url=jdbc:mysql://127.0.0.1:3306/db1?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
   spring.shardingsphere.datasource.db1.username=root
   spring.shardingsphere.datasource.db1.password=root
   
spring.shardingsphere.datasource.db1.type=com.alibaba.druid.pool.DruidDataSource
   
   spring.shardingsphere.datasource.db2.driver-class-name=com.mysql.jdbc.Driver
   
spring.shardingsphere.datasource.db2.url=jdbc:mysql://127.0.0.1:3306/db2?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
   spring.shardingsphere.datasource.db2.username=root
   spring.shardingsphere.datasource.db2.password=root
   
spring.shardingsphere.datasource.db2.type=com.alibaba.druid.pool.DruidDataSource
   
   # 数据库的hit 策略
   
spring.shardingsphere.sharding.default-database-strategy.hint.algorithm-class-name=com.springboot.config.DbAlgorithm
   
   spring.shardingsphere.props.sql.show=true
   spring.shardingsphere.orchestration.name=sharding4
   spring.shardingsphere.orchestration.overwrite=true
   spring.shardingsphere.orchestration.registry.type=zookeeper
   spring.shardingsphere.orchestration.registry.server-lists=localhost:2181
   spring.shardingsphere.orchestration.registry.namespace=sharding-jdbc-user
   ```
   These configurations take effect locally, but when I configure to the 
configuration center, the program starts incorrectly:
   ```
   Caused by: java.lang.IllegalStateException: No available sharding rule 
configuration in `logic_db` for orchestration.
        at 
com.google.common.base.Preconditions.checkState(Preconditions.java:197) 
~[guava-18.0.jar:na]
        at 
org.apache.shardingsphere.orchestration.internal.registry.config.service.ConfigurationService.persistShardingRuleConfiguration(ConfigurationService.java:133)
 ~[sharding-orchestration-core-4.0.0.jar:4.0.0]
        at 
org.apache.shardingsphere.orchestration.internal.registry.config.service.ConfigurationService.persistRuleConfiguration(ConfigurationService.java:113)
 ~[sharding-orchestration-core-4.0.0.jar:4.0.0]
        at 
org.apache.shardingsphere.orchestration.internal.registry.config.service.ConfigurationService.persistConfiguration(ConfigurationService.java:79)
 ~[sharding-orchestration-core-4.0.0.jar:4.0.0]
        at 
org.apache.shardingsphere.orchestration.internal.registry.ShardingOrchestrationFacade.init(ShardingOrchestrationFacade.java:77)
 ~[sharding-orchestration-core-4.0.0.jar:4.0.0]
        at 
org.apache.shardingsphere.shardingjdbc.orchestration.internal.datasource.AbstractOrchestrationDataSource.initShardingOrchestrationFacade(AbstractOrchestrationDataSource.java:114)
 ~[sharding-jdbc-orchestration-4.0.0.jar:4.0.0]
        at 
org.apache.shardingsphere.shardingjdbc.orchestration.internal.datasource.OrchestrationShardingDataSource.<init>(OrchestrationShardingDataSource.java:73)
 ~[sharding-jdbc-orchestration-4.0.0.jar:4.0.0]
        at 
org.apache.shardingsphere.shardingjdbc.orchestration.spring.boot.OrchestrationSpringBootConfiguration.shardingDataSourceByLocal(OrchestrationSpringBootConfiguration.java:130)
 ~[sharding-jdbc-orchestration-spring-boot-starter-4.0.0.jar:4.0.0]
        at 
org.apache.shardingsphere.shardingjdbc.orchestration.spring.boot.OrchestrationSpringBootConfiguration$$EnhancerBySpringCGLIB$$f0ac3f5a.CGLIB$shardingDataSourceByLocal$2(<generated>)
 ~[sharding-jdbc-orchestration-spring-boot-starter-4.0.0.jar:4.0.0]
        at 
org.apache.shardingsphere.shardingjdbc.orchestration.spring.boot.OrchestrationSpringBootConfiguration$$EnhancerBySpringCGLIB$$f0ac3f5a$$FastClassBySpringCGLIB$$48fdf05e.invoke(<generated>)
 ~[sharding-jdbc-orchestration-spring-boot-starter-4.0.0.jar:4.0.0]
        at 
org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) 
~[spring-core-5.0.11.RELEASE.jar:5.0.11.RELEASE]
        at 
org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:365)
 ~[spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]
        at 
org.apache.shardingsphere.shardingjdbc.orchestration.spring.boot.OrchestrationSpringBootConfiguration$$EnhancerBySpringCGLIB$$f0ac3f5a.shardingDataSourceByLocal(<generated>)
 ~[sharding-jdbc-orchestration-spring-boot-starter-4.0.0.jar:4.0.0]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
~[na:1.8.0_191]
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
~[na:1.8.0_191]
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 ~[na:1.8.0_191]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
        at 
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
 ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
        ... 70 common frames omitted
   ```
   I tried this configuration again, and it was successful。
   ```
   # 数据库
   spring.shardingsphere.datasource.names=db0,db1
   
   # 对于未配置分片规则的表默认的数据库
   spring.shardingsphere.sharding.default-data-source-name=db0
   
   # 数据源配置
   
spring.shardingsphere.datasource.db0.type=com.alibaba.druid.pool.DruidDataSource
   spring.shardingsphere.datasource.db0.driver-class-name=com.mysql.jdbc.Driver
   
spring.shardingsphere.datasource.db0.url=jdbc:mysql://127.0.0.1:3306/db0?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
   spring.shardingsphere.datasource.db0.username=root
   spring.shardingsphere.datasource.db0.password=root
   
   
spring.shardingsphere.datasource.db1.type=com.alibaba.druid.pool.DruidDataSource
   spring.shardingsphere.datasource.db1.driver-class-name=com.mysql.jdbc.Driver
   
spring.shardingsphere.datasource.db1.url=jdbc:mysql://127.0.0.1:3306/db1?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
   spring.shardingsphere.datasource.db1.username=root
   spring.shardingsphere.datasource.db1.password=root
   
   # 分表策略
   
spring.shardingsphere.sharding.tables.goods.actual-data-nodes=db$->{0..1}.goods_$->{0..1}
   
spring.shardingsphere.sharding.tables.goods.table-strategy.inline.sharding-column=id
   
spring.shardingsphere.sharding.tables.goods.table-strategy.inline.algorithm-expression=goods_$->{id
 % 2}
   # 分库策略
   
spring.shardingsphere.sharding.default-database-strategy.hint.algorithm-class-name=com.springboot.config.DbAlgorithm
   
   spring.shardingsphere.props.sql.show=true
   spring.shardingsphere.orchestration.name=sharding
   spring.shardingsphere.orchestration.overwrite=true
   spring.shardingsphere.orchestration.registry.type=zookeeper
   spring.shardingsphere.orchestration.registry.server-lists=localhost:2181
   spring.shardingsphere.orchestration.registry.namespace=sharding-jdbc-user
   ```
   The difference between the above two configurations is that the second 
configuration adds the table sharding strategy
   
   Anyone can tell me what to do!
   
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to