Shadow Algorithm

Background

The shadow DB feature carries out shadow measurement to SQL statements executed. Shadow measurement supports two types of algorithms, and users can choose one or a combination of them based on actual business needs.

Parameters

Column-based shadow algorithm

Column value matching shadow algorithm

Type:VALUE_MATCH

Attribute NameData TypeDescription
columnStringshadow column
operationStringSQL operation type (INSERT, UPDATE, DELETE, SELECT)
valueStringvalue matched by shadow column

Column-based Regex matching algorithm

Type:REGEX_MATCH

Attribute NameData TypeDescription
columnStringmatch a column
operationStringSQL operation type(INSERT, UPDATE, DELETE, SELECT)
regexStringshadow column matching Regex

Hint-based shadow algorithm

Simple Hint matching shadow algorithm

Type:SIMPLE_HINT

Attribute NameData TypeDescription
fooStringbar

Configuration sample

  • Java API
  1. public final class ShadowConfiguration {
  2. // ...
  3. private AlgorithmConfiguration createShadowAlgorithmConfiguration() {
  4. Properties userIdInsertProps = new Properties();
  5. userIdInsertProps.setProperty("operation", "insert");
  6. userIdInsertProps.setProperty("column", "user_id");
  7. userIdInsertProps.setProperty("value", "1");
  8. return new AlgorithmConfiguration("VALUE_MATCH", userIdInsertProps);
  9. }
  10. // ...
  11. }
  • YAML:
  1. shadowAlgorithms:
  2. user-id-insert-algorithm:
  3. type: VALUE_MATCH
  4. props:
  5. column: user_id
  6. operation: insert
  7. value: 1
  • Spring Boot Starter:
  1. spring.shardingsphere.rules.shadow.shadow-algorithms.user-id-insert-algorithm.type=VALUE_MATCH
  2. spring.shardingsphere.rules.shadow.shadow-algorithms.user-id-insert-algorithm.props.operation=insert
  3. spring.shardingsphere.rules.shadow.shadow-algorithms.user-id-insert-algorithm.props.column=user_id
  4. spring.shardingsphere.rules.shadow.shadow-algorithms.user-id-insert-algorithm.props.value=1
  • Spring Namespace:
  1. <shadow:shadow-algorithm id="user-id-insert-algorithm" type="VALUE_MATCH">
  2. <props>
  3. <prop key="operation">insert</prop>
  4. <prop key="column">user_id</prop>
  5. <prop key="value">1</prop>
  6. </props>
  7. </shadow:shadow-algorithm>