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

ShardingSphereAlgorithmPostProcessor.init() not called #18093

Closed
vincentlbh opened this issue May 31, 2022 · 16 comments
Closed

ShardingSphereAlgorithmPostProcessor.init() not called #18093

vincentlbh opened this issue May 31, 2022 · 16 comments
Labels

Comments

@vincentlbh
Copy link

Question

I was using Shardingsphere-jdbc(5.1.1).
图片

图片

but ShardingSphereAlgorithmPostProcessor.init() was never called! is there something wrong?

@vincentlbh
Copy link
Author

图片

@zhaojinchao95
Copy link
Contributor

Can you provide your configuration with text format?

@vincentlbh
Copy link
Author

Can you provide your configuration with text format?

spring:
shardingsphere:
datasource:
names: orderdemo0,orderdemo1
orderdemo0:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: jdbc:mysql://10.126.124.51:3306/order_demo0?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8
username: root
password: root
hikari:
auto-commit: true
connection-test-query: SELECT 1
connection-timeout: 9000
idle-timeout: 600000
max-lifetime: 1800000
maximum-pool-size: 15
minimum-idle: 10
pool-name: ${spring.application.name}1
orderdemo1:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: jdbc:mysql://10.126.124.51:3306/order_demo1?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8
username: root
password: root
hikari:
auto-commit: true
connection-test-query: SELECT 1
connection-timeout: 9000
idle-timeout: 600000
max-lifetime: 1800000
maximum-pool-size: 15
minimum-idle: 10
pool-name: ${spring.application.name}2
rules:
sharding:
tables:
order_info:
actual-data-nodes: orderdemo$->{0..1}.order_info$->{0..1}
database-strategy:
standard:
sharding-column: order_id
sharding-algorithm-name: db-algorithm
table-strategy:
standard:
sharding-column: user_id
sharding-algorithm-name: tb-algorithm
sharding-algorithms:
db-algorithm:
type: INLINE
props:
algorithm-expression: orderdemo$->{order_id % 2}
tb-algorithm:
# type: INLINE
# props:
# algorithm-expression: order_info$->{user_id % 2}
type: CLASS_BASED
props:
strategy: standard
algorithmClassName: com.tcl.sharding.order.infrastructure.algorithm.OrderAlgorithm

@RaigorJiang
Copy link
Contributor

I have also encountered a similar problem, which may be affected by the loading order of different beans in the project. You can observe whether there is a similar log:

is not eligible for getting processed by all BeanPostProcessors.

@zhaojinchao95
Copy link
Contributor

I can't reproduce this problem, Maybe you can provide a demo project?

spring.shardingsphere.datasource.names=ds-0,ds-1

spring.shardingsphere.datasource.ds-0.jdbc-url=jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
spring.shardingsphere.datasource.ds-0.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds-0.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.ds-0.username=root
spring.shardingsphere.datasource.ds-0.password=123456

spring.shardingsphere.datasource.ds-1.jdbc-url=jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
spring.shardingsphere.datasource.ds-1.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds-1.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.ds-1.username=root
spring.shardingsphere.datasource.ds-1.password=123456

spring.shardingsphere.rules.sharding.database-strategy.standard.sharding-column=user_id
spring.shardingsphere.rules.sharding.database-strategy.standard.sharding-algorithm-name=database-inline
spring.shardingsphere.rules.sharding.binding-tables[0]=t_order,t_order_item
spring.shardingsphere.rules.sharding.broadcast-tables=t_address

spring.shardingsphere.rules.sharding.tables.t_order.actual-data-nodes=ds-$->{0..1}.t_order_$->{0..1}
spring.shardingsphere.rules.sharding.tables.t_order.table-strategy.standard.sharding-column=order_id
spring.shardingsphere.rules.sharding.tables.t_order.table-strategy.standard.sharding-algorithm-name=t-order-class-based

spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.column=order_id
spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.key-generator-name=snowflake

spring.shardingsphere.rules.sharding.tables.t_order_item.actual-data-nodes=ds-$->{0..1}.t_order_item_$->{0..1}
spring.shardingsphere.rules.sharding.tables.t_order_item.table-strategy.standard.sharding-column=order_id
spring.shardingsphere.rules.sharding.tables.t_order_item.table-strategy.standard.sharding-algorithm-name=t-order-item-class-based

spring.shardingsphere.rules.sharding.tables.t_order_item.key-generate-strategy.column=order_item_id
spring.shardingsphere.rules.sharding.tables.t_order_item.key-generate-strategy.key-generator-name=snowflake

#spring.shardingsphere.rules.sharding.sharding-algorithms.datasource-class-based.type=CLASS_BASED
#spring.shardingsphere.rules.sharding.sharding-algorithms.datasource-class-based.props.strategy=standard
#spring.shardingsphere.rules.sharding.sharding-algorithms.datasource-class-based.props.algorithmClassName=org.apache.shardingsphere.example.extension.classbased.sharding.spring.boot.mybatis.fixture.ClassBasedDatasourceStandardShardingAlgorithmFixture
spring.shardingsphere.rules.sharding.sharding-algorithms.database-inline.type=INLINE
spring.shardingsphere.rules.sharding.sharding-algorithms.database-inline.props.algorithm-expression=ds-$->{user_id % 2}
spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-class-based.type=CLASS_BASED
spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-class-based.props.strategy=standard
spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-class-based.props.algorithmClassName=com.lingh.service.ClassBasedOrderStandardShardingAlgorithmFixture
spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-class-based.props.sharding-count=2
spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-item-class-based.type=CLASS_BASED

spring.shardingsphere.rules.sharding.key-generators.snowflake.type=SNOWFLAKE

spring.shardingsphere.props.sql-show=true

image

@vincentlbh
Copy link
Author

I have also encountered a similar problem, which may be affected by the loading order of different beans in the project. You can observe whether there is a similar log:

is not eligible for getting processed by all BeanPostProcessors.

yeah,i got this

trationDelegate$BeanPostProcessorChecker : Bean 'tb-algorithm' of type [org.apache.shardingsphere.sharding.algorithm.sharding.classbased.ClassBasedShardingAlgorithm] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

@vincentlbh
Copy link
Author

I can't reproduce this problem, Maybe you can provide a demo project?

please take it!
order-demo.zip

@zhaojinchao95
Copy link
Contributor

Thx, i will see

@zhaojinchao95
Copy link
Contributor

order-demo.zip

@vincentlbh Can you use this project try it again?

@vincentlbh
Copy link
Author

order-demo.zip

@vincentlbh Can you use this project try it again?

oh, sorry, i forgot something, earlier i had to add this class to solve that problem.

图片

@zhaojinchao95
Copy link
Contributor

order-demo.zip
@vincentlbh Can you use this project try it again?

oh, sorry, i forgot something, earlier i had to add this class to solve that problem.

图片

I found it, and i commented it out

@terrymanu
Copy link
Member

The class ShardingSphereAlgorithmPostProcessor is renamed in 5.1.3, is the problem still existed?

@vincentlbh
Copy link
Author

The class ShardingSphereAlgorithmPostProcessor is renamed in 5.1.3, is the problem still existed?

When will 5.1.3 be released?

@mumutu66
Copy link

I think the datasource bean may not use the beanPostProcessor to init。。In some case other lib will use a beanPostProcessor which depends on the datasource will trigger the bean initialize during the org.springframework.context.support.PostProcessorRegistrationDelegate#registerBeanPostProcessors(org.springframework.beans.factory.config.ConfigurableListableBeanFactory, org.springframework.context.support.AbstractApplicationContext) and the datasource bean will missing the init phase . maybe use the SmartInitializingSingleton instead。。or just init right on the BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ShardingSphereAlgorithmFactory.createAlgorithm(algorithmConfig, algorithmClass).getClass());

@github-actions
Copy link

github-actions bot commented Oct 8, 2022

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

@TeslaCN
Copy link
Member

TeslaCN commented Dec 26, 2022

@TeslaCN TeslaCN closed this as completed Dec 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants