数据库发现

语法说明

  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
  • discoveryType 指定数据库发现服务类型,ShardingSphere 内置支持 MGR
  • 重复的 ruleName 将无法被创建
  • 正在被使用的 discoveryTypediscoveryHeartbeat 无法被删除
  • 带有 - 的命名在改动时需要使用 " "
  • 移除 discoveryRule 时不会移除被该 discoveryRule 使用的 discoveryTypediscoveryHeartbeat

示例

创建 discoveryRule 时同时创建 discoveryTypediscoveryHeartbeat

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

使用已有的 discoveryTypediscoveryHeartbeat 创建 discoveryRule

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