影子库

    详情请参见内置影子算法列表

    1. 在 YAML 文件中配置影子库规则,包含数据源、影子库规则、全局属性等配置项;
    2. 调用 YamlShardingSphereDataSourceFactory 对象的 createDataSource 方法,根据 YAML 文件中的配置信息创建 ShardingSphereDataSource。
    1. ds:
    2. url: jdbc:mysql://127.0.0.1:3306/ds?serverTimezone=UTC&useSSL=false
    3. username: root
    4. password:
    5. connectionTimeoutMilliseconds: 30000
    6. idleTimeoutMilliseconds: 60000
    7. maxLifetimeMilliseconds: 1800000
    8. maxPoolSize: 50
    9. shadow_ds:
    10. url: jdbc:mysql://127.0.0.1:3306/shadow_ds?serverTimezone=UTC&useSSL=false
    11. username: root
    12. password:
    13. idleTimeoutMilliseconds: 60000
    14. maxLifetimeMilliseconds: 1800000
    15. maxPoolSize: 50
    16. minPoolSize: 1
    17. rules:
    18. - !SHADOW
    19. dataSources:
    20. shadowDataSource:
    21. productionDataSourceName: ds
    22. shadowDataSourceName: shadow_ds
    23. t_order:
    24. - shadowDataSource
    25. shadowAlgorithmNames:
    26. - user_id_insert_match_algorithm
    27. - sql_hint_algorithm
    28. shadowAlgorithms:
    29. user_id_insert_match_algorithm:
    30. type: REGEX_MATCH
    31. props:
    32. operation: insert
    33. column: user_id
    34. regex: "[1]"
    35. sql_hint_algorithm:
    36. type: SQL_HINT