今天项目里用ShardingSphere进行表分区,但发现缺省的分表策略配置一直不生效,经仔细调试发现,必须要配置一个“actual-data-nodes”才能生效。
具体配置如下:
spring:
profiles:
active: cache, global-route
shardingsphere:
datasource:
names: db-001
db-001:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/postgres?useSSL=false
username: postgres
password: postgres
sharding:
# default-database-strategy:
# complex:
# sharding-columns: db_sharding_id
# algorithm-class-name: com.psbc.corebanking.core.data.sharding.CustomerNoShardingDBAlgorithm
default-table-strategy: (缺省表分区策略)
complex:
sharding-columns: db_sharding_id
algorithm-class-name: com.xxx.XxxClass
tables:
ops_account_info: (必须要配置这个,才能使用缺省分表策略)
actual-data-nodes: db-001.ops_account_info
ops_account_info2:
table-strategy:
complex:
sharding-columns: db_sharding_id
algorithm-class-name: com.xxx.AbcClass