bruce-pang opened a new issue, #32382:
URL: https://github.com/apache/shardingsphere/issues/32382
## Bug Report
Now I am using sharding-jdbc5.4.0 to implement sharding. When using the
snowflake algorithm to generate the primary key, the following error is
reported:
```
Caused by: com.zaxxer.hikari.pool.HikariPool$PoolInitializationException:
Failed to initialize pool: `snowflake` algorithm does not exist in database
`logic_db`.
at
com.zaxxer.hikari.pool.HikariPool.throwPoolInitializationException(HikariPool.java:596)
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:582)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:100)
at
com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
at
org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:159)
at
org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:117)
at
org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
at
org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:80)
at
org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:67)
at
org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:348)
at
org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:89)
at
org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:49)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
at
org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
at
org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)
... 45 more
Caused by:
org.apache.shardingsphere.sharding.exception.metadata.MissingRequiredShardingAlgorithmException:
`snowflake` algorithm does not exist in database `logic_db`.
at
org.apache.shardingsphere.sharding.checker.ShardingRuleConfigurationChecker.lambda$checkKeyGenerateStrategy$2(ShardingRuleConfigurationChecker.java:85)
at
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions.checkState(ShardingSpherePreconditions.java:41)
at
org.apache.shardingsphere.sharding.checker.ShardingRuleConfigurationChecker.checkKeyGenerateStrategy(ShardingRuleConfigurationChecker.java:84)
at
org.apache.shardingsphere.sharding.checker.ShardingRuleConfigurationChecker.checkTableConfiguration(ShardingRuleConfigurationChecker.java:62)
at
org.apache.shardingsphere.sharding.checker.ShardingRuleConfigurationChecker.check(ShardingRuleConfigurationChecker.java:51)
at
org.apache.shardingsphere.sharding.checker.ShardingRuleConfigurationChecker.check(ShardingRuleConfigurationChecker.java:44)
at
org.apache.shardingsphere.infra.rule.builder.database.DatabaseRulesBuilder.build(DatabaseRulesBuilder.java:63)
at
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase.create(ShardingSphereDatabase.java:87)
at
org.apache.shardingsphere.metadata.factory.ExternalMetaDataFactory.createGenericDatabases(ExternalMetaDataFactory.java:84)
at
org.apache.shardingsphere.metadata.factory.ExternalMetaDataFactory.create(ExternalMetaDataFactory.java:71)
at
org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory.create(MetaDataContextsFactory.java:95)
at
org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory.create(MetaDataContextsFactory.java:69)
at
org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder.build(StandaloneContextManagerBuilder.java:52)
at
org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.createContextManager(ShardingSphereDataSource.java:82)
at
org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.<init>(ShardingSphereDataSource.java:69)
at
org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory.createDataSource(ShardingSphereDataSourceFactory.java:95)
at
org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory.createDataSource(YamlShardingSphereDataSourceFactory.java:167)
at
org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory.createDataSource(YamlShardingSphereDataSourceFactory.java:102)
at
org.apache.shardingsphere.driver.jdbc.core.driver.DriverDataSourceCache.createDataSource(DriverDataSourceCache.java:51)
at
java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)
at
org.apache.shardingsphere.driver.jdbc.core.driver.DriverDataSourceCache.get(DriverDataSourceCache.java:45)
at
org.apache.shardingsphere.driver.ShardingSphereDriver.connect(ShardingSphereDriver.java:51)
at
com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:121)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:359)
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201)
at
com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:470)
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561)
... 58 more
```
The following is my sharding-jdc configuration file:
```
dataSources:
ds_0:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.jdbc.Driver
url:
jdbc:mysql://127.0.0.1:3306/demo_ds?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root
ds_1:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.jdbc.Driver
jdbcUrl:
jdbc:mysql://127.0.0.1:3306/demo_ds_1?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root
rules:
- !SHARDING
tables:
test01:
actualDataNodes: ds_0.test01_$->{0..9} # [test01_0, test01_1,
test01_2, test01_3, test01_4, test01_5, test01_6, test01_7, test01_8, test01_9]
tableStrategy:
standard:
shardingColumn: account_no
shardingAlgorithmName: t_test01_inline
# ID generation policy (the built-in ID generation policy has been
removed after version 5.0.0)
keyGenerateStrategy:
column: id
keyGeneratorName: snowflake
shardingAlgorithms:
database_inline:
type: INLINE
props:
algorithm-expression: test01_$->{account_no % 8}
t_test01_inline:
type: INLINE
props:
algorithm-expression: test01_$->{account_no % 8}
props:
sql-show: true
```
### Which version of ShardingSphere did you use?
5.4.0
### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
ShardingSphere-JDBC
### Expected behavior
Generate ID using snowflake algorithm
### Actual behavior
Caused by:
org.apache.shardingsphere.sharding.exception.metadata.MissingRequiredShardingAlgorithmException:
`snowflake` algorithm does not exist in database `logic_db`.
### Reason analyze (If you can)
### Steps to reproduce the behavior, such as: SQL to execute, sharding rule
configuration, when exception occur etc.
Step 1: Introduce the above configuration in application.yml of JDK17,
SpringBoot3.0.2 environment:
```
spring:
datasource:
driver-class-name: org.apache.shardingsphere.driver.ShardingSphereDriver
url: jdbc:shardingsphere:classpath:sharding.yaml
```
Step 2: Hand over SimpleDriverDataSource to the spring container for
management:
```
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="shardingDataSource"
class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<property name="driverClass"
value="org.apache.shardingsphere.driver.ShardingSphereDriver" />
<property name="url"
value="jdbc:shardingsphere:classpath:sharding.yaml" />
</bean>
</beans>
```
Step 3: Write a batch insert to verify the Junit generated by the table
partitioning strategy
```
@RunWith(SpringRunner.class)
@SpringBootTest(classes = AccountApplication.class)
@Slf4j
public class Test01Test {
@Resource
private Test01Mapper test01Mapper;
@Test
public void testSaveTest01() {
Random random = new Random();
for (int i = 0; i < 10; i++) {
Test01DO test01DO = new Test01DO();
test01DO.setCardNo(Long.valueOf(random.nextInt(100)));
test01Mapper.insert(test01DO);
}
}
}
```
Step 4: Run it
### 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]