Shadow DB

Background

Under the distributed application architecture based on microservices, the business needs multiple services to be completed through a series of service and middleware calls, so the stress test of a single service can no longer represent the real scenario. In the test environment, rebuilding a complete set of pressure test environments similar to the production environment would mean an excessively high cost, and often an inability to simulate the complexity and flow of the online environment. Therefore, enterprises usually select the full link voltage test method, i.e. a pressure test in the production environment, so that the test results can accurately reflect the system’s real capacity and performance level.

Parameters

Configuration Entry

  1. <shadow:rule />

Configurable Properties:

NameTypeDescription
idAttributeSpring Bean Id
data-source(?)TagShadow data source configuration
shadow-table(?)TagShadow table configuration
shadow-algorithm(?)TagShadow table configuration
default-shadow-algorithm-name(?)TagDefault shadow algorithm configuration

Shadow data source configuration:

  1. <shadow:data-source />
NameTypeDescription
idAttributeSpring Bean Id
production-data-source-nameAttributeProduction data source name
shadow-data-source-nameAttributeShadow data source name

Shadow table configuration:

  1. <shadow:shadow-table />
NameTypeDescription
nameAttributeShadow table name
data-sourcesAttributeShadow table associated shadow data source name list (multiple values are separated by “,”)
algorithm (?)TagShadow table association shadow algorithm configuration
  1. <shadow:algorithm />
NameTypeDescription
shadow-algorithm-refAttributeShadow table association shadow algorithm name

Shadow algorithm configuration:

  1. <shadow:shadow-algorithm />
NameTypeDescription
idAttributeShadow algorithm name
typeAttributeShadow algorithm type
props (?)TagShadow algorithm attribute configuration
Refer to Builin Shadow Algorithm for details

Procedure

  1. Create production and shadow data sources.
  2. Configure shadow rules.
    • Configure shadow data sources.
    • Configure shadow table.
    • Configure shadow algorithm.

Sample

  1. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:shadow="http://shardingsphere.apache.org/schema/shardingsphere/shadow" xsi:schemaLocation="http://www.springframework.org/schema/beans
  2. http://www.springframework.org/schema/beans/spring-beans.xsd
  3. http://shardingsphere.apache.org/schema/shardingsphere/shadow
  4. http://shardingsphere.apache.org/schema/shardingsphere/shadow/shadow.xsd
  5. ">
  6. <shadow:shadow-algorithm id="user-id-insert-match-algorithm" type="VALUE_MATCH">
  7. <props>
  8. <prop key="operation">insert</prop>
  9. <prop key="column">user_id</prop>
  10. <prop key="value">1</prop>
  11. </props>
  12. </shadow:shadow-algorithm>
  13. <shadow:rule id="shadowRule">
  14. <shadow:data-source id="shadow-data-source" production-data-source-name="ds" shadow-data-source-name="ds_shadow"/>
  15. <shadow:shadow-table name="t_user" data-sources="shadow-data-source">
  16. <shadow:algorithm shadow-algorithm-ref="user-id-insert-match-algorithm" />
  17. </shadow:shadow-table>
  18. </shadow:rule>
  19. </beans>