影子库
详情请参见内置影子算法列表
- 在 YAML 文件中配置影子库规则,包含数据源、影子库规则、全局属性等配置项;
- 调用 YamlShardingSphereDataSourceFactory 对象的 createDataSource 方法,根据 YAML 文件中的配置信息创建 ShardingSphereDataSource。
ds:
url: jdbc:mysql://127.0.0.1:3306/ds?serverTimezone=UTC&useSSL=false
username: root
password:
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
shadow_ds:
url: jdbc:mysql://127.0.0.1:3306/shadow_ds?serverTimezone=UTC&useSSL=false
username: root
password:
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
rules:
- !SHADOW
dataSources:
shadowDataSource:
productionDataSourceName: ds
shadowDataSourceName: shadow_ds
t_order:
- shadowDataSource
shadowAlgorithmNames:
- user_id_insert_match_algorithm
- sql_hint_algorithm
shadowAlgorithms:
user_id_insert_match_algorithm:
type: REGEX_MATCH
props:
operation: insert
column: user_id
regex: "[1]"
sql_hint_algorithm:
type: SQL_HINT