Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shardingsphere-jdbc 5.1.2 SnowflakeKeyGenerateAlgorithm workerId not work #30457

Closed
hapenguc opened this issue Mar 11, 2024 · 3 comments
Closed

Comments

@hapenguc
Copy link

  • dependency:
    shardingsphere-jdbc-core-spring-boot-starter
    5.1.2

  • configuration:
    config.txt

  • debug :

    @Bean
    @Conditional({LocalRulesCondition.class})
    @Autowired(
        required = false
    )
    public DataSource shardingSphereDataSource(ObjectProvider<List<RuleConfiguration>> rules, ObjectProvider<ModeConfiguration> modeConfig) throws SQLException {
        Collection<RuleConfiguration> ruleConfigs = (Collection)Optional.ofNullable((List)rules.getIfAvailable()).orElseGet(Collections::emptyList);
        return ShardingSphereDataSourceFactory.createDataSource(this.databaseName, (ModeConfiguration)modeConfig.getIfAvailable(), this.dataSourceMap, ruleConfigs, this.props.getProps());
    }

the breakPoint pause here seems Good because I can find: ruleConfigs -> keyGenerators -> SnowflakeKeyGenerateAlgorithm -> props -> “worker-id” : 21,
which is exactly in the above configuration.

but after "ShardingSphereDataSourceFactory.createDataSource(this.databaseName, (ModeConfiguration)modeConfig.getIfAvailable(), this.dataSourceMap, ruleConfigs, this.props.getProps())" ,
the returned ShardingSphereDataSource -> contextManager -> InstanceContext -> ComputeNodeInstance -> workerId is always 0. When I tested(tried to insert the table which was using snowflake as keyGenerateAlgorithm), in the breakpoint
pause I could find SnowFlakeKeyGenerateAlgorithm has props: worker-id: 20. but when generating Long key, it was using the InstanceContext-> getWorkerId(0), rather than props->worker-id(21)。

so "Is there any way to solve this problem?

@zhaojinchao95
Copy link
Contributor

The problem are fixed in 5.4.1. you can try it

@hapenguc
Copy link
Author

The problem are fixed in 5.4.1. you can try it

thx, I tried updating to 5.4.1, now I got Application run failed error:

bad SQL grammar []; nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "T_XXX" not found (this database is empty); SQL statement: select xxx from t_xxx [42104-214] at org.h2.message.DbException.getJdbcSQLException(DbException.java:502) at org.h2.message.DbException.getJdbcSQLException(DbException.java:477) at org.h2.message.DbException.get(DbException.java:223) at org.h2.message.DbException.get(DbException.java:199) at org.h2.command.Parser.getTableOrViewNotFoundDbException(Parser.java:8385) at org.h2.command.Parser.getTableOrViewNotFoundDbException(Parser.java:8369) at org.h2.command.Parser.readTableOrView(Parser.java:8358) at org.h2.command.Parser.readTablePrimary(Parser.java:1863) at org.h2.command.Parser.readTableReference(Parser.java:2334) at org.h2.command.Parser.parseSelectFromPart(Parser.java:2772) at org.h2.command.Parser.parseSelect(Parser.java:2878) at org.h2.command.Parser.parseQueryPrimary(Parser.java:2762) at org.h2.command.Parser.parseQueryTerm(Parser.java:2633) at org.h2.command.Parser.parseQueryExpressionBody(Parser.java:2612) at org.h2.command.Parser.parseQueryExpressionBodyAndEndOfQuery(Parser.java:2605) at org.h2.command.Parser.parseQueryExpression(Parser.java:2598) at org.h2.command.Parser.parseQuery(Parser.java:2567) at org.h2.command.Parser.parsePrepared(Parser.java:724) at org.h2.command.Parser.parse(Parser.java:689) at org.h2.command.Parser.parse(Parser.java:661) at org.h2.command.Parser.prepareCommand(Parser.java:569) at org.h2.engine.SessionLocal.prepareLocal(SessionLocal.java:631) at org.h2.engine.SessionLocal.prepareCommand(SessionLocal.java:554) at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1116) at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:92) at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:288) at com.zaxxer.hikari.pool.ProxyConnection.prepareStatement(ProxyConnection.java:337) at com.zaxxer.hikari.pool.HikariProxyConnection.prepareStatement(HikariProxyConnection.java) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.ibatis.logging.jdbc.ConnectionLogger.invoke(ConnectionLogger.java:55) at com.sun.proxy.$Proxy181.prepareStatement(Unknown Source) at org.apache.ibatis.executor.statement.PreparedStatementHandler.instantiateStatement(PreparedStatementHandler.java:86) at org.apache.ibatis.executor.statement.BaseStatementHandler.prepare(BaseStatementHandler.java:88) at org.apache.ibatis.executor.statement.RoutingStatementHandler.prepare(RoutingStatementHandler.java:59) at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:87) at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49) at com.huawei.consumer.it.huaweistore.orm.interceptor.PageInterceptor.intercept(PageInterceptor.java:88) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:62) at com.sun.proxy.$Proxy180.query(Unknown Source) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:145) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:425)

I tried the answer of this question but didnt work
#25954 (comment)

something wrong with h2database(2.1.214) or snakeyaml(2.0) version or my configuration?

@totalo totalo linked a pull request Mar 17, 2024 that will close this issue
@totalo totalo removed a link to a pull request Mar 17, 2024
@hapenguc
Copy link
Author

Hi guys I solved this problem by following :https://shardingsphere.apache.org/document/current/en/user-manual/shardingsphere-jdbc/yaml-config/jdbc-driver/spring-boot/

This is actually about the configarution, previously we used application-xxx.properties, now we should use sharding.yaml and ShardingSphereDriver.

Thanks anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants