Manual

Manual

Environment

JAVA,JDK 1.8+.

The migration scene we support:

SourceTarget
MySQL(5.1.15 ~ 5.7.x)MySQL
PostgreSQL(9.4 ~ )PostgreSQL
openGauss(2.1.0)openGauss

Attention:

If the backend database is MySQL, please download mysql-connector-java-5.1.47.jar and put it into ${shardingsphere-proxy}/lib directory.

Privileges

We need to enable binlog for MySQL. Privileges of users scaling used should include Replication privileges.

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

PostgreSQL need to support and open test_decoding feature.

DistSQL API

ShardingSphere-Scaling provides DistSQL API

Preview current sharding rule

Example:

  1. preview select count(1) from t_order;

Response:

  1. mysql> preview select count(1) from t_order;
  2. +------------------+--------------------------------+
  3. | data_source_name | sql |
  4. +------------------+--------------------------------+
  5. | ds_0 | select count(1) from t_order_0 |
  6. | ds_0 | select count(1) from t_order_1 |
  7. | ds_1 | select count(1) from t_order_0 |
  8. | ds_1 | select count(1) from t_order_1 |
  9. +------------------+--------------------------------+
  10. 4 rows in set (0.00 sec)

Start scaling job

  1. Add new data source resources

Please refer to RDL#Data Source for more details.

Example:

  1. ADD RESOURCE ds_2 (
  2. URL="jdbc:mysql://127.0.0.1:3306/db2?serverTimezone=UTC&useSSL=false",
  3. USER=root,
  4. PASSWORD=root,
  5. PROPERTIES("maximumPoolSize"=10,"idleTimeout"="30000")
  6. );
  7. -- ds_3, ds_4
  1. Alter sharding table rule

Please refer to RDL#Sharding for more details.

Example:

  1. ALTER SHARDING TABLE RULE t_order (
  2. RESOURCES(ds_2, ds_3, ds_4),
  3. SHARDING_COLUMN=order_id,
  4. TYPE(NAME=hash_mod,PROPERTIES("sharding-count"=10)),
  5. GENERATED_KEY(COLUMN=another_id,TYPE(NAME=snowflake,PROPERTIES("worker-id"=123)))
  6. );

If RESOURCES and sharding-count is changed, then scaling job will be emitted.

List scaling jobs

Please refer to RAL#Scaling for more details.

Example:

  1. show scaling list;

Response:

  1. mysql> show scaling list;
  2. +--------------------+-----------------------+----------------------+--------+---------------------+---------------------+
  3. | id | tables | sharding_total_count | active | create_time | stop_time |
  4. +--------------------+-----------------------+----------------------+--------+---------------------+---------------------+
  5. | 659853312085983232 | t_order_item, t_order | 2 | 0 | 2021-10-26 20:21:31 | 2021-10-26 20:24:01 |
  6. | 660152090995195904 | t_order_item, t_order | 2 | 0 | 2021-10-27 16:08:43 | 2021-10-27 16:11:00 |
  7. +--------------------+-----------------------+----------------------+--------+---------------------+---------------------+
  8. 2 rows in set (0.04 sec)

Get scaling progress

Example:

  1. show scaling status {jobId};

Response:

  1. mysql> show scaling status 660152090995195904;
  2. +------+-------------+----------+-------------------------------+--------------------------+
  3. | item | data_source | status | inventory_finished_percentage | incremental_idle_minutes |
  4. +------+-------------+----------+-------------------------------+--------------------------+
  5. | 0 | ds_1 | FINISHED | 100 | 2834 |
  6. | 1 | ds_0 | FINISHED | 100 | 2834 |
  7. +------+-------------+----------+-------------------------------+--------------------------+
  8. 2 rows in set (0.00 sec)

Current scaling job is finished, new sharding rule should take effect, and not if scaling job is failed.

status values:

ValueDescription
PREPARINGpreparing
RUNNINGrunning
EXECUTE_INVENTORY_TASKinventory task running
EXECUTE_INCREMENTAL_TASKincremental task running
ALMOST_FINISHEDalmost finished
FINISHEDfinished
PREPARING_FAILUREpreparation failed
EXECUTE_INVENTORY_TASK_FAILUREinventory task failed
EXECUTE_INCREMENTAL_TASK_FAILUREincremental task failed

Preview new sharding rule

Example:

  1. preview select count(1) from t_order;

Response:

  1. mysql> preview select count(1) from t_order;
  2. +------------------+--------------------------------+
  3. | data_source_name | sql |
  4. +------------------+--------------------------------+
  5. | ds_2 | select count(1) from t_order_0 |
  6. | ds_2 | select count(1) from t_order_1 |
  7. | ds_3 | select count(1) from t_order_0 |
  8. | ds_3 | select count(1) from t_order_1 |
  9. | ds_4 | select count(1) from t_order_0 |
  10. | ds_4 | select count(1) from t_order_1 |
  11. +------------------+--------------------------------+
  12. 6 rows in set (0.01 sec)

Other DistSQL

Please refer to RAL#Scaling for more details.