使用手册

使用手册

环境要求

纯JAVA开发,JDK建议1.8以上版本。

支持迁移场景如下:

源端目标端是否支持
MySQL(5.1.15 ~ 5.7.x)sharding-proxy支持
PostgreSQL(9.4 ~ )sharding-proxy支持

注意: 如果后端连接MySQL数据库,需要下载MySQL Connector/J, 解压缩后,将mysql-connector-java-5.1.47.jar拷贝到${sharding-scaling}\lib目录。

权限要求

MySQL 需要开启binlogbinlog format为Row模式,且迁移时所使用用户需要赋予Replication相关权限。

  1. +-----------------------------------------+---------------------------------------+
  2. | Variable_name | Value |
  3. +-----------------------------------------+---------------------------------------+
  4. | log_bin | ON |
  5. | binlog_format | ROW |
  6. +-----------------------------------------+---------------------------------------+
  7. +------------------------------------------------------------------------------+
  8. |Grants for ${username}@${host} |
  9. +------------------------------------------------------------------------------+
  10. |GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO ${username}@${host} |
  11. |....... |
  12. +------------------------------------------------------------------------------+

PostgreSQL 需要开启test_decoding

API接口

弹性迁移组件提供了简单的HTTP API接口

创建迁移任务

接口描述:POST /shardingscaling/job/start

请求体:

ParameterDescribe
ruleConfiguration.sourceDatasource源端sharding sphere数据源相关配置
ruleConfiguration.sourceRule源端sharding sphere表规则相关配置
ruleConfiguration.destinationDataSources.name目标端sharding proxy名称
ruleConfiguration.destinationDataSources.url目标端sharding proxy jdbc url
ruleConfiguration.destinationDataSources.username目标端sharding proxy用户名
ruleConfiguration.destinationDataSources.password目标端sharding proxy密码
jobConfiguration.concurrency迁移并发度,举例:如果设置为3,则待迁移的表将会有三个线程同时对该表进行迁移,前提是该表有整数型主键

示例:

  1. curl -X POST \
  2. http://localhost:8888/shardingscaling/job/start \
  3. -H 'content-type: application/json' \
  4. -d '{
  5. "ruleConfiguration": {
  6. "sourceDatasource": "ds_0: !!YamlDataSourceConfiguration\n dataSourceClassName: com.zaxxer.hikari.HikariDataSource\n properties:\n jdbcUrl: jdbc:mysql://127.0.0.1:3306/test?serverTimezone=UTC&useSSL=false\n username: root\n password: '\''123456'\''\n connectionTimeout: 30000\n idleTimeout: 60000\n maxLifetime: 1800000\n maxPoolSize: 50\n minPoolSize: 1\n maintenanceIntervalMilliseconds: 30000\n readOnly: false\n",
  7. "sourceRule": "defaultDatabaseStrategy:\n inline:\n algorithmExpression: ds_${user_id % 2}\n shardingColumn: user_id\ntables:\n t1:\n actualDataNodes: ds_0.t1\n keyGenerator:\n column: order_id\n type: SNOWFLAKE\n logicTable: t1\n tableStrategy:\n inline:\n algorithmExpression: t1\n shardingColumn: order_id\n t2:\n actualDataNodes: ds_0.t2\n keyGenerator:\n column: order_item_id\n type: SNOWFLAKE\n logicTable: t2\n tableStrategy:\n inline:\n algorithmExpression: t2\n shardingColumn: order_id\n",
  8. "destinationDataSources": {
  9. "name": "dt_0",
  10. "password": "123456",
  11. "url": "jdbc:mysql://127.0.0.1:3306/test2?serverTimezone=UTC&useSSL=false",
  12. "username": "root"
  13. }
  14. },
  15. "jobConfiguration": {
  16. "concurrency": 3
  17. }
  18. }'

返回信息:

  1. {
  2. "success": true,
  3. "errorCode": 0,
  4. "errorMsg": null,
  5. "model": null
  6. }

查询迁移任务进度

接口描述:GET /shardingscaling/job/progress/{jobId}

示例:

  1. curl -X GET \
  2. http://localhost:8888/shardingscaling/job/progress/1

返回信息:

  1. {
  2. "success": true,
  3. "errorCode": 0,
  4. "errorMsg": null,
  5. "model": {
  6. "id": 1,
  7. "jobName": "Local Sharding Scaling Job",
  8. "status": "RUNNING/STOPPED"
  9. "syncTaskProgress": [{
  10. "id": "127.0.0.1-3306-test",
  11. "status": "PREPARING/MIGRATE_HISTORY_DATA/SYNCHRONIZE_REALTIME_DATA/STOPPING/STOPPED",
  12. "historySyncTaskProgress": [{
  13. "id": "history-test-t1#0",
  14. "estimatedRows": 41147,
  15. "syncedRows": 41147
  16. }, {
  17. "id": "history-test-t1#1",
  18. "estimatedRows": 42917,
  19. "syncedRows": 42917
  20. }, {
  21. "id": "history-test-t1#2",
  22. "estimatedRows": 43543,
  23. "syncedRows": 43543
  24. }, {
  25. "id": "history-test-t2#0",
  26. "estimatedRows": 39679,
  27. "syncedRows": 39679
  28. }, {
  29. "id": "history-test-t2#1",
  30. "estimatedRows": 41483,
  31. "syncedRows": 41483
  32. }, {
  33. "id": "history-test-t2#2",
  34. "estimatedRows": 42107,
  35. "syncedRows": 42107
  36. }],
  37. "realTimeSyncTaskProgress": {
  38. "id": "realtime-test",
  39. "delayMillisecond": 1576563771372,
  40. "logPosition": {
  41. "filename": "ON.000007",
  42. "position": 177532875,
  43. "serverId": 0
  44. }
  45. }
  46. }]
  47. }
  48. }

查询所有迁移任务

接口描述:GET /shardingscaling/job/list

示例:

  1. curl -X GET \
  2. http://localhost:8888/shardingscaling/job/list

返回信息:

  1. {
  2. "success": true,
  3. "errorCode": 0,
  4. "model": [
  5. {
  6. "jobId": 1,
  7. "jobName": "Local Sharding Scaling Job",
  8. "status": "RUNNING"
  9. }
  10. ]
  11. }

停止迁移任务

接口描述:POST /shardingscaling/job/stop

请求体:

ParameterDescribe
jobIdjob id

示例:

  1. curl -X POST \
  2. http://localhost:8888/shardingscaling/job/stop \
  3. -H 'content-type: application/json' \
  4. -d '{
  5. "jobId":1
  6. }'

返回信息:

  1. {
  2. "success": true,
  3. "errorCode": 0,
  4. "errorMsg": null,
  5. "model": null
  6. }

通过UI界面来操作

Sharding-scaling与sharding-ui集成了用户界面,所以上述所有任务相关的操作都可以通过UI界面点点鼠标来实现,当然本质上还是调用了上述基本接口。

更多信息请参考sharding-ui项目。