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

How to abstrct common rule config for sharding-jdbc:5.5.0 #32957

Open
774886347 opened this issue Sep 23, 2024 · 4 comments
Open

How to abstrct common rule config for sharding-jdbc:5.5.0 #32957

774886347 opened this issue Sep 23, 2024 · 4 comments

Comments

@774886347
Copy link

I have 50 project module and each of them using sharding-jdbc now, and I have to config all tables for dev,sit,uat,prod env:

spring:
    datasource:
        url: jdbc:shardingsphere:classpath:config/sharding-uat.yaml
        driver-class-name: org.apache.shardingsphere.driver.ShardingSphereDriver
        type: com.alibaba.druid.pool.DruidDataSource
        druid:
            filters: stat
            max-active: 50
            initial-size: 5
            max-wait: 60000
            min-idle: 5
            time-between-eviction-runs-millis: 60000
            min-evictable-idle-time-millis: 300000
            max-evictable-idle-time-millis: 1800000
            filter:
                config:
                    enabled: false
            web-stat-filter:
                enabled: false
            stat-view-servlet:
                enabled: false
            keep-alive: true
            validation-query: select 1
            remove-abandoned: true
            test-while-idle: true
            test-on-borrow: false
            test-on-return: false
            pool-prepared-statements: true
            max-open-prepared-statements: 50
            remove-abandoned-timeout: 300
            log-abandoned: true

Here is the sharding-uat.yaml:

dataSources:
 m1:
   dataSourceClassName: com.alibaba.druid.pool.DruidDataSource
   driverClassName: com.mysql.cj.jdbc.Driver
   url: 
   username: 
   password: 
 m2:
   dataSourceClassName: com.alibaba.druid.pool.DruidDataSource
   driverClassName: com.mysql.cj.jdbc.Driver
   url: 
   username: 
   password: 
rules:
- !SINGLE
 tables:
   - m2.my_table_without_sharding
        ...**<422 items>**
- !SHARDING
 tables: 
   here is the sharding config
 shardingAlgorithms:
   here is the sharding config
 keyGenerators:
   snowflake:
     type: custom_snowflake_id
props:
 sql-show: true

When I adding a new "- !SINGLE" table for sharding, I hava to add this config for 4 environment(dev,sit,uat,prod) and all project modules (50 odules) have to adding these table config, and they are all the same!
So how to config common rule config for sharding-jdbc:5.5.0?

@terrymanu
Copy link
Member

DistSQL should be used instead of YAML configuration.
DistSQL is more flexible and can be generated by the program for batch processing.

@774886347
Copy link
Author

dataSources:
  m1:
    dataSourceClassName: com.alibaba.druid.pool.DruidDataSource
    driverClassName: com.mysql.cj.jdbc.Driver
    url: 
    username: 
    password: 
  m2:
    dataSourceClassName: com.alibaba.druid.pool.DruidDataSource
    driverClassName: com.mysql.cj.jdbc.Driver
    url: 
    username: 
    password: 

Here is the datasource config, rules must use same dataSource when I try to config "- !SINGLE" m1.my_single_table and "- !SHARDING" m2.my_sharding_table, I got Exception: all tables must be in the same compute node
So how to make sure both m1 and m2 work together?
m1 for single and m2 for sharding?

@774886347
Copy link
Author

If m1 and m2 work together, single table can use m1.* to replace 422 table items...for more single table in future

@terrymanu
Copy link
Member

Is it the same question with title?

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