DB Discovery

Syntax

  1. CREATE DB_DISCOVERY RULE ruleDefinition [, ruleDefinition] ...
  2. ALTER DB_DISCOVERY RULE ruleDefinition [, ruleDefinition] ...
  3. DROP DB_DISCOVERY RULE ruleName [, ruleName] ...
  4. CREATE DB_DISCOVERY TYPE databaseDiscoveryTypeDefinition [, databaseDiscoveryTypeDefinition] ...
  5. ALTER DB_DISCOVERY TYPE databaseDiscoveryTypeDefinition [, databaseDiscoveryTypeDefinition] ...
  6. DROP DB_DISCOVERY TYPE discoveryTypeName [, discoveryTypeName] ...
  7. CREATE DB_DISCOVERY HEARTBEAT databaseDiscoveryHeartbaetDefinition [, databaseDiscoveryHeartbaetDefinition] ...
  8. ALTER DB_DISCOVERY HEARTBEAT databaseDiscoveryHeartbaetDefinition [, databaseDiscoveryHeartbaetDefinition] ...
  9. DROP DB_DISCOVERY HEARTBEAT discoveryHeartbeatName [, discoveryHeartbeatName] ...
  10. ruleDefinition:
  11. (databaseDiscoveryRuleDefinition | databaseDiscoveryRuleConstruction)
  12. databaseDiscoveryRuleDefinition
  13. ruleName (resources, typeDefinition, heartbeatDefinition)
  14. databaseDiscoveryRuleConstruction
  15. ruleName (resources, TYPE = discoveryTypeName, HEARTBEAT = discoveryHeartbeatName)
  16. databaseDiscoveryTypeDefinition
  17. discoveryTypeName (typeDefinition)
  18. databaseDiscoveryHeartbaetDefinition
  19. discoveryHeartbeatName (PROPERTIES (properties))
  20. resources:
  21. RESOURCES(resourceName [, resourceName] ...)
  22. typeDefinition:
  23. TYPE(NAME=typeName [, PROPERTIES([properties] )] )
  24. heartbeatDefinition
  25. HEARTBEAT (PROPERTIES (properties))
  26. properties:
  27. property [, property] ...
  28. property:
  29. key=value

Parameters Explained

nameDateTypeDescription
discoveryTypeNameIDENTIFIERDatabase discovery type name
ruleNameIDENTIFIERRule name
discoveryHeartbeatNameIDENTIFIERDetect heartbeat name
typeNameSTRINGDatabase discovery type, such as: MySQL.MGR
resourceNameIDENTIFIERResource name

Notes

  • discoveryType specifies the database discovery service type, ShardingSphere has built-in support for MySQL.MGR
  • Duplicate ruleName will not be created
  • The discoveryType and discoveryHeartbeat being used cannot be deleted
  • Names with - need to use " " when changing
  • When removing the discoveryRule, the discoveryType and discoveryHeartbeat used by the discoveryRule will not be removed

Example

When creating a discoveryRule, create both discoveryType and discoveryHeartbeat

  1. CREATE DB_DISCOVERY RULE db_discovery_group_0 (
  2. RESOURCES(ds_0, ds_1, ds_2),
  3. TYPE(NAME='MySQL.MGR',PROPERTIES('group-name'='92504d5b-6dec')),
  4. HEARTBEAT(PROPERTIES('keep-alive-cron'='0/5 * * * * ?'))
  5. );
  6. ALTER DB_DISCOVERY RULE db_discovery_group_0 (
  7. RESOURCES(ds_0, ds_1, ds_2),
  8. TYPE(NAME='MySQL.MGR',PROPERTIES('group-name'='246e9612-aaf1')),
  9. HEARTBEAT(PROPERTIES('keep-alive-cron'='0/5 * * * * ?'))
  10. );
  11. DROP DB_DISCOVERY RULE db_discovery_group_0;
  12. DROP DB_DISCOVERY TYPE db_discovery_group_0_mgr;
  13. DROP DB_DISCOVERY HEARTBEAT db_discovery_group_0_heartbeat;

Use the existing discoveryType and discoveryHeartbeat to create a discoveryRule

  1. CREATE DB_DISCOVERY TYPE db_discovery_group_1_mgr(
  2. TYPE(NAME='MySQL.MGR',PROPERTIES('group-name'='92504d5b-6dec'))
  3. );
  4. CREATE DB_DISCOVERY HEARTBEAT db_discovery_group_1_heartbeat(
  5. PROPERTIES('keep-alive-cron'='0/5 * * * * ?')
  6. );
  7. CREATE DB_DISCOVERY RULE db_discovery_group_1 (
  8. RESOURCES(ds_0, ds_1, ds_2),
  9. TYPE=db_discovery_group_1_mgr,
  10. HEARTBEAT=db_discovery_group_1_heartbeat
  11. );
  12. ALTER DB_DISCOVERY TYPE db_discovery_group_1_mgr(
  13. TYPE(NAME='MySQL.MGR',PROPERTIES('group-name'='246e9612-aaf1'))
  14. );
  15. ALTER DB_DISCOVERY HEARTBEAT db_discovery_group_1_heartbeat(
  16. PROPERTIES('keep-alive-cron'='0/10 * * * * ?')
  17. );
  18. ALTER DB_DISCOVERY RULE db_discovery_group_1 (
  19. RESOURCES(ds_0, ds_1),
  20. TYPE=db_discovery_group_1_mgr,
  21. HEARTBEAT=db_discovery_group_1_heartbeat
  22. );
  23. DROP DB_DISCOVERY RULE db_discovery_group_1;
  24. DROP DB_DISCOVERY TYPE db_discovery_group_1_mgr;
  25. DROP DB_DISCOVERY HEARTBEAT db_discovery_group_1_heartbeat;