Shadow DB

Background

Please refer to the following configuration in order to use the ShardingSphere shadow DB feature in ShardingSphere-Proxy.

Parameters

  1. rules:
  2. - !SHADOW
  3. dataSources:
  4. shadowDataSource:
  5. productionDataSourceName: # production data source name
  6. shadowDataSourceName: # shadow data source name
  7. tables:
  8. <table_name>:
  9. dataSourceNames: # shadow table associates shadow data source name list
  10. - <shadow_data_source>
  11. shadowAlgorithmNames: # shadow table associates shadow algorithm name list
  12. - <shadow_algorithm_name>
  13. defaultShadowAlgorithmName: # default shadow algorithm name (option)
  14. shadowAlgorithms:
  15. <shadow_algorithm_name> (+): # shadow algorithm name
  16. type: # shadow algorithm type
  17. props: # shadow algorithm attribute configuration

Please refer to Built-in shadow algorithm list for more details.

Procedure

  1. Configure shadow DB rules in the YAML file, including data sources, shadow library rules, global properties and other configuration items;
  2. Call the createDataSource() method of the YamlShardingSphereDataSourceFactory object to create a ShardingSphereDataSource based on the configuration information in the YAML file.

Sample

The YAML configuration sample of shadow DB is as follows:

  1. dataSources:
  2. ds:
  3. url: jdbc:mysql://127.0.0.1:3306/ds?serverTimezone=UTC&useSSL=false
  4. username: root
  5. password:
  6. connectionTimeoutMilliseconds: 30000
  7. idleTimeoutMilliseconds: 60000
  8. maxLifetimeMilliseconds: 1800000
  9. maxPoolSize: 50
  10. minPoolSize: 1
  11. shadow_ds:
  12. url: jdbc:mysql://127.0.0.1:3306/shadow_ds?serverTimezone=UTC&useSSL=false
  13. username: root
  14. password:
  15. connectionTimeoutMilliseconds: 30000
  16. idleTimeoutMilliseconds: 60000
  17. maxLifetimeMilliseconds: 1800000
  18. maxPoolSize: 50
  19. minPoolSize: 1
  20. rules:
  21. - !SHADOW
  22. dataSources:
  23. shadowDataSource:
  24. productionDataSourceName: ds
  25. shadowDataSourceName: shadow_ds
  26. tables:
  27. t_order:
  28. dataSourceNames:
  29. - shadowDataSource
  30. shadowAlgorithmNames:
  31. - user_id_insert_match_algorithm
  32. - simple_hint_algorithm
  33. shadowAlgorithms:
  34. user_id_insert_match_algorithm:
  35. type: REGEX_MATCH
  36. props:
  37. operation: insert
  38. column: user_id
  39. regex: "[1]"
  40. simple_hint_algorithm:
  41. type: SIMPLE_HINT
  42. props:
  43. foo: bar