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

ComboPooledDataSource not compatible with apache shardingsphere #19607

Closed
silversteak opened this issue Jul 27, 2022 · 6 comments · Fixed by #19947
Closed

ComboPooledDataSource not compatible with apache shardingsphere #19607

silversteak opened this issue Jul 27, 2022 · 6 comments · Fixed by #19947

Comments

@silversteak
Copy link
Contributor

ComboPooledDataSource not compatible with apache shardingsphere.

I am currently trying to implement shardingshpere in my current company's codebase. Previously created an example project using HikariDataSource and it worked fine.

Now in companies code base uses c3p0.ComboPooledDataSource as datasource. So when am trying to create shardingshphere datasource using this datasource its failing.

In HikariDatasource, the standardProps are coming correct.
image

But in c3p0.ComboPooledDataSource, the standardProps are giving just password only.
image

The main cause of the issue is that in c3p0.ComboPooledDataSource, the properties are stored in different format. Like username as user and url as jdbcUrl.
image

Thats why am getting a nullpointer exception here since both the keys are username and url
image

I was under the assumption that apache shardingsphere is compatible with all kinds of datasource. I am stuck here.

Please help me out if possible.

Datasource Config

dataSources:
  ds:
    dataSourceClassName: com.mchange.v2.c3p0.ComboPooledDataSource
    driverClassName: com.mysql.jdbc.Driver
    jdbcUrl: jdbc:mysql://localhost:3306/demo_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
    user: root
    username: root
    password: password
    max-active: 16

pom.xml

<dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>shardingsphere-jdbc-core</artifactId>
            <version>5.1.2</version>
</dependency>
<dependency>
                <groupId>com.mchange</groupId>
                <artifactId>c3p0</artifactId>
                <version>0.9.5.1</version>
</dependency>

@TeslaCN TeslaCN self-assigned this Jul 29, 2022
@TeslaCN
Copy link
Member

TeslaCN commented Jul 29, 2022

Hi @silversteak
Thanks for your feedback. I'm going to check this.

@TeslaCN
Copy link
Member

TeslaCN commented Jul 29, 2022

I've reproduced this issue.

[INFO ] 2022-07-29 13:15:56,294 --main-- [com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource] Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> z8kfsxaqk30d5911hdcsh|47d9a273, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> null, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> z8kfsxaqk30d5911hdcsh|47d9a273, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, preferredTestQuery -> null, privilegeSpawnedThreads -> false, properties -> {password=******, user=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ] 
[INFO ] 2022-07-29 13:15:56,319 --main-- [com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource] Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> z8kfsxaqk30d5911hdcsh|68dc098b, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> null, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> z8kfsxaqk30d5911hdcsh|68dc098b, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, preferredTestQuery -> null, privilegeSpawnedThreads -> false, properties -> {password=******, user=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ] 
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "Object.toString()" because the return value of "java.util.Map.get(Object)" is null
	at org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResource.createDataSourceMetaDataMap(ShardingSphereResource.java:63)
	at org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResource.<init>(ShardingSphereResource.java:52)
	at org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase.createResource(ShardingSphereDatabase.java:115)
	at org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase.create(ShardingSphereDatabase.java:109)
	at org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase.create(ShardingSphereDatabase.java:91)
	at org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabasesFactory.createGenericDatabases(ShardingSphereDatabasesFactory.java:80)
	at org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabasesFactory.create(ShardingSphereDatabasesFactory.java:68)
	at org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory.create(MetaDataContextsFactory.java:66)
	at org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder.build(StandaloneContextManagerBuilder.java:51)
	at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.createContextManager(ShardingSphereDataSource.java:74)
	at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.<init>(ShardingSphereDataSource.java:64)
	at org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory.createDataSource(ShardingSphereDataSourceFactory.java:93)
	at org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory.createDataSource(YamlShardingSphereDataSourceFactory.java:133)
	at org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory.createDataSource(YamlShardingSphereDataSourceFactory.java:62)
	at org.apache.shardingsphere.example.sharding.raw.jdbc.factory.YamlDataSourceFactory.newInstance(YamlDataSourceFactory.java:33)
	at org.apache.shardingsphere.example.sharding.raw.jdbc.ShardingRawYamlConfigurationExample.main(ShardingRawYamlConfigurationExample.java:41)

@TeslaCN
Copy link
Member

TeslaCN commented Jul 29, 2022

This could be fixed by implementing DataSourcePoolMetaData for c3p0, just like what we did for HikariCP and DBCP.

https://github.com/apache/shardingsphere/tree/master/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/metadata/type

@TeslaCN
Copy link
Member

TeslaCN commented Jul 29, 2022

Hi @silversteak
Are you interested in fixing this?

@silversteak
Copy link
Contributor Author

Hi @TeslaCN Yes am interested in fixing it. I will provide it soon

@silversteak
Copy link
Contributor Author

#19947

@TeslaCN Please review the PR.

@terrymanu terrymanu added this to the 5.1.3 milestone Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants