Logo
Mixing rules

Mixing rules #

The overlay between rule items in a hybrid configuration is related by data source name and table name.

If the previous rule is for data source aggregation, the next rule, when configuring the data source, needs to use the logical data source name after the aggregation configured by the previous rule; similarly, if the previous rule is for table aggregation, the next rule, when configuring the table, needs to use the logical table name after the aggregation configured by the previous rule.

Description of configuration items #

dataSources: # Configure a real existing data source as the name 
  write_ds:
    # ...Omit specific configuration
  read_ds_0:
    # ...Omit specific configuration
  read_ds_1:
    # ...Omit specific configuration

rules:
  - !SHARDING # Config sharding rule
    tables:
      t_user:
        actualDataNodes: ds.t_user_${0..1} # Data source name `ds` Logical data source name using read-write splitting configuration
        tableStrategy:
          standard:
            shardingColumn: user_id
            shardingAlgorithmName: t_user_inline
    shardingAlgorithms:
      t_user_inline:
        type: INLINE
        props:
          algorithm-expression: t_user_${user_id % 2}
  
  - !ENCRYPT # Config encrypt rule
    tables:
      t_user: # Table name `t_user` Logical table name using data sharding configuration
        columns:
          pwd:
            plainColumn: plain_pwd
            cipherColumn: cipher_pwd
            encryptorName: encryptor_aes
    encryptors:
      encryptor_aes:
        type: aes
        props:
          aes-key-value: 123456abc
  
  - !READWRITE_SPLITTING # config readwrite splitting rule
    dataSources:
      ds: # Logical data source name for read/write separation `ds` for use in data sharding
        type: Static
        props:
          write-data-source-name: write_ds  # Use real data source names `write_ds`
          read-data-source-names: read_ds_0, read_ds_1 # Use real data source names `read_ds_0` `read_ds_1`
        loadBalancerName: roundRobin
    loadBalancers:
      roundRobin:
        type: ROUND_ROBIN

props:
  sql-show: true