You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shardingsphere.apache.org by Myth <xi...@qq.com> on 2020/05/21 11:56:09 UTC

Optimize datasource config in sharding-jdbc and sharding-proxy。

Hi All community friends:
now,There are a lot of the same datasource  config when we use sharding,master-slave datasource.

In springboot project we can configruation like this :
-------------------------------------------------------------------------------------------------------------
spring.shardingsphere.datasource.ds_master_0.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds_master_0.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.ds_master_0.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_master_0
spring.shardingsphere.datasource.ds_master_0.username=root
spring.shardingsphere.datasource.ds_master_0.password=

spring.shardingsphere.datasource.ds_master_0_slave_0.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds_master_0_slave_0.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.ds_master_0_slave_0.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_master_0_slave_0
spring.shardingsphere.datasource.ds_master_0_slave_0.username=root
spring.shardingsphere.datasource.ds_master_0_slave_0.password=

spring.shardingsphere.datasource.ds_master_0_slave_1.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds_master_0_slave_1.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.ds_master_0_slave_1.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_master_0_slave_1?
spring.shardingsphere.datasource.ds_master_0_slave_1.username=root
spring.shardingsphere.datasource.ds_master_0_slave_1.password=
-----------------------------------------------------------------------------------------------------------------------------------------------------

We're will optimize after like this:

--------------------------------------------------------------------------------------------------------------------------------------------------
spring.shardingsphere.datasource.common.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.common.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.common.username=root
spring.shardingsphere.datasource.common.password=

spring.shardingsphere.datasource.ds_master_0.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_master_0

spring.shardingsphere.datasource.ds_master_0_slave_0.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_master_0_slave_0

spring.shardingsphere.datasource.ds_master_0_slave_1.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_master_0_slave_1
-----------------------------------------------------------------------------------------------------------------------------------------------


In yaml we configruation like this:

---------------------------------------------------------------------------------------------------
dataSources:
  ds_0:
    url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
    username: root
    password:
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
  ds_1:
    url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
    username: root
    password:
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
   maxPoolSize: 50
---------------------------------------------------------------------------------------------------------

We're will optimize after like this:

------------------------------------------------------------------------------------------------------------
dataSourceCommon:
  username: root
  password:
  connectionTimeoutMilliseconds: 30000
  idleTimeoutMilliseconds: 60000
  maxLifetimeMilliseconds: 1800000
  maxPoolSize: 50
  minPoolSize: 1
  maintenanceIntervalMilliseconds: 30000

dataSources:
  ds_0:
    url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
  ds_1:
    url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
------------------------------------------------------------------------------------------------------

After the optimization , User configuration will be greatly simplified, especially when users need to configure multiple datasources.

Thanks ,Looking forward to your reply。
 
Kind regards,
xiaoyu

Re:Optimize datasource config in sharding-jdbc and sharding-proxy。

Posted by Juan Pan <pa...@apache.org>.
Hi,




I can feel the pain at the tedious work of DataSource configuration. 

Thanks for your effort in this issue.

Considering configuration format, currently, I have no satisfying solution, 

here[1] is just some of my daft idea for discussion, which is inspired by `defaultDatabaseStrategy` of `Sharding rule`.




[1] https://github.com/apache/shardingsphere/pull/5732#issuecomment-632463802


Best,
Trista


 Juan Pan (Trista)
                         
Senior DBA & PPMC of Apache ShardingSphere(Incubating)
E-mail: panjuan@apache.org




On 05/21/2020 19:56,Myth<xi...@qq.com> wrote:
Hi All community friends:
now,There are a lot of the same datasource  config when we use sharding,master-slave datasource.

In springboot project we can configruation like this :
-------------------------------------------------------------------------------------------------------------
spring.shardingsphere.datasource.ds_master_0.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds_master_0.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.ds_master_0.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_master_0
spring.shardingsphere.datasource.ds_master_0.username=root
spring.shardingsphere.datasource.ds_master_0.password=

spring.shardingsphere.datasource.ds_master_0_slave_0.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds_master_0_slave_0.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.ds_master_0_slave_0.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_master_0_slave_0
spring.shardingsphere.datasource.ds_master_0_slave_0.username=root
spring.shardingsphere.datasource.ds_master_0_slave_0.password=

spring.shardingsphere.datasource.ds_master_0_slave_1.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds_master_0_slave_1.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.ds_master_0_slave_1.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_master_0_slave_1?
spring.shardingsphere.datasource.ds_master_0_slave_1.username=root
spring.shardingsphere.datasource.ds_master_0_slave_1.password=
-----------------------------------------------------------------------------------------------------------------------------------------------------

We're will optimize after like this:

--------------------------------------------------------------------------------------------------------------------------------------------------
spring.shardingsphere.datasource.common.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.common.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.common.username=root
spring.shardingsphere.datasource.common.password=

spring.shardingsphere.datasource.ds_master_0.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_master_0

spring.shardingsphere.datasource.ds_master_0_slave_0.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_master_0_slave_0

spring.shardingsphere.datasource.ds_master_0_slave_1.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_master_0_slave_1
-----------------------------------------------------------------------------------------------------------------------------------------------


In yaml we configruation like this:

---------------------------------------------------------------------------------------------------
dataSources:
ds_0:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
username: root
password:
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
ds_1:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
username: root
password:
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
---------------------------------------------------------------------------------------------------------

We're will optimize after like this:

------------------------------------------------------------------------------------------------------------
dataSourceCommon:
username: root
password:
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
maintenanceIntervalMilliseconds: 30000

dataSources:
ds_0:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
ds_1:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
------------------------------------------------------------------------------------------------------

After the optimization , User configuration will be greatly simplified, especially when users need to configure multiple datasources.

Thanks ,Looking forward to your reply。

Kind regards,
xiaoyu