apache / shardingsphere

Distributed SQL transaction & query engine for data sharding, scaling, encryption, and more - on any database.
Apache License 2.0
19.88k stars 6.73k forks source link

Database type inconsistent #28949

Closed Zhiqiang-Wu closed 3 months ago

Zhiqiang-Wu commented 11 months ago

Bug Report

For English only, other languages will not accept.

Before report a bug, make sure you have:

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

Please answer these questions before submitting your issue. Thanks!

Which version of ShardingSphere did you use?

org.apache.shardingsphere:shardingsphere-jdbc-core-spring-boot-starter:5.2.1

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-JDBC

Expected behavior

Actual behavior

Caused by: java.lang.IllegalStateException: Database type inconsistent with 'org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType@c2e33' and 'org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType@31183ee2'
    at com.google.common.base.Preconditions.checkState(Preconditions.java:835) ~[guava-32.0.0-jre.jar:na]
    at org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine.getDatabaseType(DatabaseTypeEngine.java:110) ~[shardingsphere-infra-common-5.2.1.jar:5.2.1]
    at org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine.lambda$getProtocolType$1(DatabaseTypeEngine.java:69) ~[shardingsphere-infra-common-5.2.1.jar:5.2.1]
    at java.base/java.util.Optional.orElseGet(Optional.java:364) ~[na:na]
    at org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine.getProtocolType(DatabaseTypeEngine.java:69) ~[shardingsphere-infra-common-5.2.1.jar:5.2.1]
    at org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabasesFactory.create(ShardingSphereDatabasesFactory.java:66) ~[shardingsphere-infra-common-5.2.1.jar:5.2.1]
    at org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory.create(MetaDataContextsFactory.java:91) ~[shardingsphere-mode-core-5.2.1.jar:5.2.1]
    at org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory.create(MetaDataContextsFactory.java:69) ~[shardingsphere-mode-core-5.2.1.jar:5.2.1]
    at org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder.build(StandaloneContextManagerBuilder.java:49) ~[shardingsphere-standalone-mode-core-5.2.1.jar:5.2.1]
    at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.createContextManager(ShardingSphereDataSource.java:76) ~[shardingsphere-jdbc-core-5.2.1.jar:5.2.1]
    at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.<init>(ShardingSphereDataSource.java:64) ~[shardingsphere-jdbc-core-5.2.1.jar:5.2.1]
    at org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory.createDataSource(ShardingSphereDataSourceFactory.java:93) ~[shardingsphere-jdbc-core-5.2.1.jar:5.2.1]
    at org.apache.shardingsphere.spring.boot.ShardingSphereAutoConfiguration.shardingSphereDataSource(ShardingSphereAutoConfiguration.java:91) ~[shardingsphere-jdbc-core-spring-boot-starter-5.2.1.jar:5.2.1]
    at org.apache.shardingsphere.spring.boot.ShardingSphereAutoConfiguration$$SpringCGLIB$$0.CGLIB$shardingSphereDataSource$3(<generated>) ~[shardingsphere-jdbc-core-spring-boot-starter-5.2.1.jar:5.2.1]
    at org.apache.shardingsphere.spring.boot.ShardingSphereAutoConfiguration$$SpringCGLIB$$2.invoke(<generated>) ~[shardingsphere-jdbc-core-spring-boot-starter-5.2.1.jar:5.2.1]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:258) ~[spring-core-6.0.9.jar:6.0.9]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-6.0.9.jar:6.0.9]
    at org.apache.shardingsphere.spring.boot.ShardingSphereAutoConfiguration$$SpringCGLIB$$0.shardingSphereDataSource(<generated>) ~[shardingsphere-jdbc-core-spring-boot-starter-5.2.1.jar:5.2.1]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:139) ~[spring-beans-6.0.9.jar:6.0.9]
    ... 20 common frames omitted

Reason analyze (If you can)

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

spring:
    config:
        import: optional:file:.env[.properties]
    shardingsphere:
        datasource:
            names: my_mysql,my_postgres
            my_mysql:
                url: ${MYSQL_DATABASE_URL}
                username: ${MYSQL_DATABASE_USERNAME}
                password: ${MYSQL_DATABASE_PASSWORD}
                driver-class-name: com.mysql.cj.jdbc.Driver
                type: com.zaxxer.hikari.HikariDataSource
            my_postgres:
                url: ${POSTGRES_DATABASE_URL}
                username: ${POSTGRES_DATABASE_USERNAME}
                password: ${POSTGRES_DATABASE_PASSWORD}
                driver-class-name: org.postgresql.Driver
                type: com.zaxxer.hikari.HikariDataSource
        rules:
            sharding:
                tables:
                    left_right_tree_node:
                        actual-data-nodes: my_mysql.left_right_tree_node
                    left_right_tree_node_layer_view:
                        actual-data-nodes: my_mysql.left_right_tree_node_layer_view
                    ltree_node:
                        actual-data-nodes: my_postgres.ltree_node

Example codes for reproduce this issue (such as a github link).

strongduanmu commented 11 months ago

Hi @Zhiqiang-Wu, why would you want to add mysql and postgresql data sources to a logical database?

Zhiqiang-Wu commented 11 months ago

The default is to use MySQL. I would like to try the special data type of PostgreSQL.

 

------------------ 原始邮件 ------------------ 发件人: "apache/shardingsphere" @.>; 发送时间: 2023年11月6日(星期一) 上午7:58 @.>; @.**@.>; 主题: Re: [apache/shardingsphere] Database type inconsistent (Issue #28949)

Hi @Zhiqiang-Wu, why would you want to add mysql and postgresql data sources to a logical database?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

github-actions[bot] commented 10 months ago

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.

terrymanu commented 3 months ago

shardingsphere-jdbc-core-spring-boot-starter is deprecated, please try new version and use ShardingSphere Driver.

uk403 commented 3 months ago

shardingsphere-jdbc-core-spring-boot-starter is deprecated, please try new version and use ShardingSphere Driver. Have implemented different types of data source connections? For example, using mysql and pg @terrymanu