Mixed Rules

Background

ShardingSphere provides a variety of features, such as data sharding, read/write splitting, and data encryption. These features can be used independently or in combination. Below, you will find the parameters’ explanation and configuration samples based on YAML.

Parameters

  1. rules:
  2. - !SHARDING
  3. tables:
  4. <logic_table_name>: # Logical table name:
  5. actualDataNodes: # consists of logical data source name plus table name (refer to Inline syntax rules)
  6. tableStrategy: # Table shards strategy. The same as database shards strategy
  7. standard:
  8. shardingColumn: # Sharding column name
  9. shardingAlgorithmName: # Sharding algorithm name
  10. keyGenerateStrategy:
  11. column: # Auto-increment column name. By default, the auto-increment primary key generator is not used.
  12. keyGeneratorName: # Distributed sequence algorithm name
  13. defaultDatabaseStrategy:
  14. standard:
  15. shardingColumn: # Sharding column name
  16. shardingAlgorithmName: # Sharding algorithm name
  17. shardingAlgorithms:
  18. <sharding_algorithm_name>: # Sharding algorithm name
  19. type: INLINE
  20. props:
  21. algorithm-expression: # INLINE expression
  22. t_order_inline:
  23. type: INLINE
  24. props:
  25. algorithm-expression: # INLINE expression
  26. keyGenerators:
  27. <key_generate_algorithm_name> (+): # Distributed sequence algorithm name
  28. type: # Distributed sequence algorithm type
  29. props: # Property configuration of distributed sequence algorithm
  30. - !ENCRYPT
  31. encryptors:
  32. <encrypt_algorithm_name> (+): # Encryption and decryption algorithm name
  33. type: # Encryption and decryption algorithm type
  34. props: # Encryption and decryption algorithm property configuration
  35. <encrypt_algorithm_name> (+): # Encryption and decryption algorithm name
  36. type: # Encryption and decryption algorithm type
  37. tables:
  38. <table_name>: # Encryption table name
  39. columns:
  40. <column_name> (+): # Encrypt logic column name
  41. cipher:
  42. name: # Cipher column name
  43. encryptorName: # Cipher encrypt algorithm name
  44. assistedQuery (?):
  45. name: # Assisted query column name
  46. encryptorName: # Assisted query encrypt algorithm name
  47. likeQuery (?):
  48. name: # Like query column name
  49. encryptorName: # Like query encrypt algorithm name

Samples

  1. rules:
  2. - !SHARDING
  3. tables:
  4. t_order:
  5. actualDataNodes: replica_ds_${0..1}.t_order_${0..1}
  6. tableStrategy:
  7. standard:
  8. shardingColumn: order_id
  9. shardingAlgorithmName: t_order_inline
  10. keyGenerateStrategy:
  11. column: order_id
  12. keyGeneratorName: snowflake
  13. defaultDatabaseStrategy:
  14. standard:
  15. shardingColumn: user_id
  16. shardingAlgorithmName: database_inline
  17. shardingAlgorithms:
  18. database_inline:
  19. type: INLINE
  20. props:
  21. algorithm-expression: replica_ds_${user_id % 2}
  22. t_order_inline:
  23. type: INLINE
  24. props:
  25. algorithm-expression: t_order_${order_id % 2}
  26. t_order_item_inline:
  27. type: INLINE
  28. props:
  29. algorithm-expression: t_order_item_${order_id % 2}
  30. keyGenerators:
  31. snowflake:
  32. type: SNOWFLAKE
  33. - !ENCRYPT
  34. encryptors:
  35. aes_encryptor:
  36. type: AES
  37. props:
  38. aes-key-value: 123456abc
  39. assisted_encryptor:
  40. type: MD5
  41. like_encryptor:
  42. type: CHAR_DIGEST_LIKE
  43. tables:
  44. t_encrypt:
  45. columns:
  46. user_id:
  47. cipher:
  48. name: user_cipher
  49. encryptorName: aes_encryptor
  50. assistedQuery:
  51. name: assisted_query_user
  52. encryptorName: assisted_encryptor
  53. likeQuery:
  54. name: like_query_user
  55. encryptorName: like_encryptor
  56. order_id:
  57. cipher:
  58. name: order_cipher
  59. encryptorName: aes_encryptor