CREATE READWRITE_SPLITTING RULE

Description

The CREATE READWRITE_SPLITTING RULE syntax is used to create a read/write splitting rule.

Syntax

Grammar Railroad diagram

  1. CreateReadwriteSplittingRule ::=
  2. 'CREATE' 'READWRITE_SPLITTING' 'RULE' ifNotExists? readwriteSplittingDefinition (',' readwriteSplittingDefinition)*
  3. ifNotExists ::=
  4. 'IF' 'NOT' 'EXISTS'
  5. readwriteSplittingDefinition ::=
  6. ruleName '(' dataSourceDefinition (',' transactionalReadQueryStrategyDefinition)? (',' loadBalancerDefinition)? ')'
  7. dataSourceDefinition ::=
  8. 'WRITE_STORAGE_UNIT' '=' writeStorageUnitName ',' 'READ_STORAGE_UNITS' '(' storageUnitName (',' storageUnitName)* ')'
  9. transactionalReadQueryStrategyDefinition ::=
  10. 'TRANSACTIONAL_READ_QUERY_STRATEGY' '=' transactionalReadQueryStrategyType
  11. loadBalancerDefinition ::=
  12. 'TYPE' '(' 'NAME' '=' algorithmType (',' propertiesDefinition)? ')'
  13. ruleName ::=
  14. identifier
  15. writeStorageUnitName ::=
  16. identifier
  17. storageUnitName ::=
  18. identifier
  19. transactionalReadQueryStrategyType ::=
  20. string
  21. algorithmType ::=
  22. string
  23. propertiesDefinition ::=
  24. 'PROPERTIES' '(' key '=' value (',' key '=' value)* ')'
  25. key ::=
  26. string
  27. value ::=
  28. literal

Note

  • transactionalReadQueryStrategyType specifies the routing strategy for read query within a transaction, please refer to YAML configuration;
  • algorithmType specifies the load balancing algorithm type, please refer to Load Balance Algorithm;
  • Duplicate ruleName will not be created;
  • ifNotExists clause used to avoid the Duplicate readwrite_splitting rule error.

Example

Create a read/write splitting rule

  1. CREATE READWRITE_SPLITTING RULE ms_group_0 (
  2. WRITE_STORAGE_UNIT=write_ds,
  3. READ_STORAGE_UNITS(read_ds_0,read_ds_1),
  4. TYPE(NAME="random")
  5. );

Create read/write splitting rule with the ifNotExists clause

  • read/write splitting rule
  1. CREATE READWRITE_SPLITTING RULE IF NOT EXISTS ms_group_0 (
  2. WRITE_STORAGE_UNIT=write_ds,
  3. READ_STORAGE_UNITS(read_ds_0,read_ds_1),
  4. TYPE(NAME="random")
  5. );

Reserved words

CREATE, READWRITE_SPLITTING, RULE, WRITE_STORAGE_UNIT, READ_STORAGE_UNITS , TYPE, NAME, PROPERTIES, TRUE, FALSE