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

Add example that implements the Metadata SPI for third-party JDBC pools #15507

Closed
linghengqian opened this issue Feb 18, 2022 · 7 comments
Closed

Comments

@linghengqian
Copy link
Member

linghengqian commented Feb 18, 2022

Feature Request

For English only, other languages will not accept.

Please pay attention on issues you submitted, because we maybe need more details.
If no response anymore and we cannot make decision by current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

Is your feature request related to a problem?

No.

Describe the feature you would like.

In ShardingSphere 5.1.0, using the JDBC pool is required to have multiple classes that implements its corresponding metadata SPI. This is available at https://shardingsphere.apache.org/document/current/en/dev-manual/data-source/ manifested, but not obvious.

Under the org.apache.shardingsphere.infra.datasource.pool.metadata.type package, three JDBC pools such as DBCP, HikariCP, Tomcat DBCP (Not Tomcat JDBC Pool) are integrated by default, and implements the corresponding org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaData and org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourceJdbcUrlMetaData interfaces. In addition, for HikariCP, it also implements the org.apache.shardingsphere.infra.datasource.pool.destroyer.DataSourcePoolDestroyer interface.

image

In the case of using a third-party JDBC pool that does not implement the metadata SPI (using Alibaba Druid as an example), the information the user gets is not clear. The user is likely to get something like this.

Caused by: java.lang.NoClassDefFoundError: org/apache/tomcat/dbcp/dbcp2/BasicDataSource
	at org.apache.shardingsphere.infra.datasource.pool.metadata.type.dbcp.TomcatDBCPDataSourcePoolMetaData.getType(TomcatDBCPDataSourcePoolMetaData.java:67) ~[shardingsphere-infra-common-5.1.0.jar:5.1.0]
	at org.apache.shardingsphere.spi.typed.TypedSPIRegistry.lambda$findRegisteredService$0(TypedSPIRegistry.java:44) ~[shardingsphere-spi-5.1.0.jar:5.1.0]
	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:174) ~[na:1.8.0_312]
	at java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1361) ~[na:1.8.0_312]
	at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126) ~[na:1.8.0_312]
	at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:499) ~[na:1.8.0_312]
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:486) ~[na:1.8.0_312]
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) ~[na:1.8.0_312]
	at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152) ~[na:1.8.0_312]
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_312]
	at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:531) ~[na:1.8.0_312]
	at org.apache.shardingsphere.spi.typed.TypedSPIRegistry.findRegisteredService(TypedSPIRegistry.java:44) ~[shardingsphere-spi-5.1.0.jar:5.1.0]
	at org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaDataFactory.newInstance(DataSourcePoolMetaDataFactory.java:46) ~[shardingsphere-infra-common-5.1.0.jar:5.1.0]
	at org.apache.shardingsphere.infra.datasource.props.DataSourceProperties.<init>(DataSourceProperties.java:53) ~[shardingsphere-infra-common-5.1.0.jar:5.1.0]
	at org.apache.shardingsphere.spring.boot.datasource.DataSourceMapSetter.getDataSource(DataSourceMapSetter.java:92) ~[shardingsphere-jdbc-spring-boot-starter-infra-5.1.0.jar:5.1.0]
	at org.apache.shardingsphere.spring.boot.datasource.DataSourceMapSetter.getDataSourceMap(DataSourceMapSetter.java:65) ~[shardingsphere-jdbc-spring-boot-starter-infra-5.1.0.jar:5.1.0]
	at org.apache.shardingsphere.spring.boot.ShardingSphereAutoConfiguration.setEnvironment(ShardingSphereAutoConfiguration.java:122) ~[shardingsphere-jdbc-core-spring-boot-starter-5.1.0.jar:5.1.0]
	at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:110) ~[spring-context-5.3.15.jar:5.3.15]
	at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:102) ~[spring-context-5.3.15.jar:5.3.15]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:440) ~[spring-beans-5.3.15.jar:5.3.15]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) ~[spring-beans-5.3.15.jar:5.3.15]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.15.jar:5.3.15]
	... 29 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp2.BasicDataSource
	at java.net.URLClassLoader.findClass(URLClassLoader.java:387) ~[na:1.8.0_312]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[na:1.8.0_312]
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352) ~[na:1.8.0_312]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[na:1.8.0_312]
	... 51 common frames omitted

I think an example can be added at https://github.com/apache/shardingsphere/tree/master/examples to provide users with reference. I believe this is also helpful to users of C3P0 and BeeCP.

@linghengqian
Copy link
Member Author

Because the Example module looks like it's being refactored, and a number of related issues are being addressed. Therefore, I think this issue should be postponed. (Uncertain about the placement and format of the integration content related to the JDBC Pools)

@linghengqian
Copy link
Member Author

I created a simple test case to help locate this situation. It's at https://github.com/linghengqian/shardingsphere-jdbc-pools-test

@zhaojinchao95
Copy link
Contributor

I created a simple test case to help locate this situation. It's at https://github.com/linghengqian/shardingsphere-jdbc-pools-test

Thx.

@linghengqian
Copy link
Member Author

linghengqian commented Feb 24, 2022

Maybe the content description on the first floor is wrong. After referring to the operation of the website #15563 , I noticed that import org.apache.commons:commons-dbcp2:2.9.0 still reported an error , you must import org.apache.tomcat:tomcat-dbcp to be normal (regardless of the version of this component is 9.0.58 or 10.0.16 ), which seems strange.

@linghengqian
Copy link
Member Author

linghengqian commented Feb 25, 2022

@ZjcNB

@linghengqian
Copy link
Member Author

@ZjcNB

  • The bugs involved in this issue have been fixed for a long time, and the description does not point to a discussion. Adding an example of the required SPI doesn't make much sense for consumers at this point.

  • I think closing this issue is a good choice?

@linghengqian
Copy link
Member Author

I think #19607 would provide a reasonable example for the c3p0 JDBC pool. So I don't think there's more to do with this issue.

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