Running a data movement operation
A data move changes which member cluster serves a collocation while your application keeps sending traffic. Run one under load before your application depends on it, so that you see what your application sees during the move and confirm that your workload keeps running. The example on this page rebalances a scaleout table. Its range routing function places each block of 1,000,000 IDs in one of four collocations, and all four start on member cluster A, so that member cluster A carries all of the load. You see the imbalance in CloudWatch, move two of the ID blocks to member cluster B while the workload runs, and confirm that the load is now split evenly.
The moves don't change the scaleout table or its routing function. Each move changes only the data mapping of one collocation, and the routing layer follows the data mappings, so the rows and the routing move together while the workload keeps using the same table.
The example uses dbcg_load.lua from A sysbench script for a database cluster group for Aurora, and its own database, lt_w, so that it doesn't change the dataset from Preparing a test dataset. Each command runs on the load generator host. The commands are for sysbench 1.1 and Aurora MySQL 8.4.900.
Before you start
Check the following before you start:
-
You use the current
dbcg_load.luafrom A sysbench script for a database cluster group for Aurora, which reopens the connection after an error. -
Every command uses
--mysql-ignore-errors=63927,63923,63928,1412,1317,1180,1927,2013,2006, the codes that a data movement cutover can return. On Aurora MySQL version 8.4.900, a refused read or write returns63927. Later engine versions return63923for the same error. -
Your router user has
dbclustergroup_move_adminordbclustergroup_super_adminfor the moves, anddbclustergroup_metadata_adminordbclustergroup_super_adminto create the routing function and the scaleout table. For the privileges, see ALTER DBCLUSTERGROUP MOVE COLLOCATION and CREATE SCALEOUT ROUTING FUNCTION. -
You run the example in a group that you use for testing, and you have taken a group snapshot, as described in Creating a snapshot of a database cluster group for Aurora. The example moves data.
Creating the scaleout table
The example creates a scaleout table lt_w.sbtest_w over four member tables, lt_w.sbtest_w0 to lt_w.sbtest_w3, each in its own collocation, cg_w0 to cg_w3. A range routing function on id sends each row to the collocation whose range holds its ID. Each collocation holds one block of IDs, as the following table shows.
| Collocation | Member table | IDs |
|---|---|---|
cg_w0 |
sbtest_w0 |
1 to 1,000,000 |
cg_w1 |
sbtest_w1 |
1,000,001 to 2,000,000 |
cg_w2 |
sbtest_w2 |
2,000,001 to 3,000,000 |
cg_w3 |
sbtest_w3 |
3,000,001 and above. The example loads IDs up to 4,000,000. |
All four collocations start on member cluster A. The following diagram shows the layout before the moves.
The following table shows which member cluster holds each collocation before and after the moves.
| Member cluster | Before the moves | After the moves |
|---|---|---|
| A | cg_w0, cg_w1, cg_w2, cg_w3 (IDs 1 and above) |
cg_w0, cg_w1 (IDs 1 to 2,000,000) |
| B | None | cg_w2, cg_w3 (IDs 2,000,001 and above) |
In the following steps, replace ALIAS_A and ALIAS_B with the aliases of the two member clusters, as described in Creating and mapping the dataset.
To create the scaleout table
-
Connect directly to each member cluster and create the database. Create it also on member cluster B, which starts empty, because a data move needs the database on its target.
CREATE DATABASE lt_w; -
From a load generator host, create and fill one table of 4,000,000 rows directly on member cluster A. The command creates
lt_w.sbtest1, with IDs 1 to 4,000,000.sysbench dbcg_load.lua --mysql-host=MEMBER_A_ENDPOINT--mysql-port=3306 --mysql-user=MEMBER_USER\ --mysql-password=PASSWORD--mysql-ssl=REQUIRED --mysql-db=lt_w \ --tables=1 --table_size=4000000 prepare -
Connect directly to member cluster A. Copy each block of IDs into its member table, and then drop
lt_w.sbtest1. Each member table holds 1,000,000 rows.CREATE TABLE lt_w.sbtest_w0 LIKE lt_w.sbtest1; CREATE TABLE lt_w.sbtest_w1 LIKE lt_w.sbtest1; CREATE TABLE lt_w.sbtest_w2 LIKE lt_w.sbtest1; CREATE TABLE lt_w.sbtest_w3 LIKE lt_w.sbtest1; INSERT INTO lt_w.sbtest_w0 SELECT * FROM lt_w.sbtest1 WHERE id BETWEEN 1 AND 1000000; INSERT INTO lt_w.sbtest_w1 SELECT * FROM lt_w.sbtest1 WHERE id BETWEEN 1000001 AND 2000000; INSERT INTO lt_w.sbtest_w2 SELECT * FROM lt_w.sbtest1 WHERE id BETWEEN 2000001 AND 3000000; INSERT INTO lt_w.sbtest_w3 SELECT * FROM lt_w.sbtest1 WHERE id BETWEEN 3000001 AND 4000000; DROP TABLE lt_w.sbtest1; -
At the routing endpoint, with autocommit on, create one table-level data mapping for each member table, each in its own collocation on member cluster A.
INSERT INTO dbclustergroup_sys.data_mappings (cluster_db_name, cluster_table_name, router_db_name, router_table_name, member_cluster_alias, router_collocation_group) VALUES ('lt_w', 'sbtest_w0', 'lt_w', 'sbtest_w0', 'ALIAS_A', 'cg_w0'), ('lt_w', 'sbtest_w1', 'lt_w', 'sbtest_w1', 'ALIAS_A', 'cg_w1'), ('lt_w', 'sbtest_w2', 'lt_w', 'sbtest_w2', 'ALIAS_A', 'cg_w2'), ('lt_w', 'sbtest_w3', 'lt_w', 'sbtest_w3', 'ALIAS_A', 'cg_w3'); -
At the routing endpoint, create a range routing function with one range for each collocation, and the scaleout table over the four member tables.
PARTITION BY COLUMN(id)places each row by the value of itsid. EachVALUES IN RANGEincludes both of its bounds, andMAXVALUEleaves the top of the last range open.CREATE SCALEOUT ROUTING FUNCTION lt_w_range_fn(id BIGINT) AS PARTITION BY COLUMN(id) IN TARGET COLLOCATION ( cg_w0 VALUES IN RANGE (1, 1000000), cg_w1 VALUES IN RANGE (1000001, 2000000), cg_w2 VALUES IN RANGE (2000001, 3000000), cg_w3 VALUES IN RANGE (3000001, MAXVALUE) ); CREATE SCALEOUT TABLE lt_w.sbtest_w ( ROUTE BY KEY(id POSITION(1)) USING ROUTING FUNCTION lt_w_range_fn ) MEMBERS ( MEMBER lt_w.sbtest_w0, MEMBER lt_w.sbtest_w1, MEMBER lt_w.sbtest_w2, MEMBER lt_w.sbtest_w3 );A scaleout table name is unique across the whole group, not for each database, so this example uses
sbtest_wrather than thesbtestof Preparing a test dataset. A secondCREATE SCALEOUT TABLEwith a name already in use, in any database, fails with error64020(Scaleout table 'sbtest' already exists). For the scaleout table statement, see CREATE SCALEOUT TABLE. -
At the routing endpoint, check that the first and last IDs return a row through the scaleout table. If a query returns error 1412, run it again. A data mapping change reaches the routing layer shortly after the statement returns.
SELECT id FROM lt_w.sbtest_w WHERE id = 1; SELECT id FROM lt_w.sbtest_w WHERE id = 4000000;
Starting the workload
Start three processes through the routing endpoint, a few seconds apart: single-statement reads, read transactions with some writes, and writes. Each process queries the scaleout table with --scaleout=sbtest_w, which is lt_w.sbtest_w in the database that --mysql-db=lt_w selects, so the routing layer routes each statement by its id. The read transactions also use --key_block=1000000, so that the five reads in each transaction come from one block of IDs and stay in one collocation. Run the processes for longer than the two moves take, and save each one's output.
# reads sysbench dbcg_load.lua --mysql-host=ROUTING_ENDPOINT--mysql-port=3306 --mysql-user=ROUTER_USER\ --mysql-password=PASSWORD--mysql-ssl=REQUIRED --mysql-db=lt_w \ --tables=1 --table_size=4000000 --scaleout=sbtest_w --mysql-ignore-errors=63927,63923,63928,1412,1317,1180,1927,2013,2006 \ --report-interval=10 --rate=150 --threads=8 --time=3600 run > read.log 2>&1 & sleep 5 # read transactions, with 10 percent writes sysbench dbcg_load.lua --mysql-host=ROUTING_ENDPOINT--mysql-port=3306 --mysql-user=ROUTER_USER\ --mysql-password=PASSWORD--mysql-ssl=REQUIRED --mysql-db=lt_w \ --tables=1 --table_size=4000000 --scaleout=sbtest_w --mysql-ignore-errors=63927,63923,63928,1412,1317,1180,1927,2013,2006 \ --report-interval=10 --rate=100 --point_selects=5 --key_block=1000000 --write_pct=10 --threads=8 --time=3600 run > trx.log 2>&1 & sleep 5 # writes sysbench dbcg_load.lua --mysql-host=ROUTING_ENDPOINT--mysql-port=3306 --mysql-user=ROUTER_USER\ --mysql-password=PASSWORD--mysql-ssl=REQUIRED --mysql-db=lt_w \ --tables=1 --table_size=4000000 --scaleout=sbtest_w --mysql-ignore-errors=63927,63923,63928,1412,1317,1180,1927,2013,2006 \ --report-interval=10 --rate=150 --write_pct=100 --threads=8 --time=3600 run > write.log 2>&1 &
Follow each process with tail -f read.log, and confirm that it reports no errors (err/s: 0.00) before you continue.
Seeing the imbalance
Each sysbench process reports its throughput over the whole scaleout table, so its report doesn't show how the load splits across member clusters. Compare the member clusters instead.
-
At the routing endpoint, count the data mappings on each member cluster. The routing layer accepts
COUNT(*)with one equality, so run one query for each alias.SELECT COUNT(*) FROM dbclustergroup_sys.data_mappings WHERE member_cluster_alias = 'ALIAS_A'; SELECT COUNT(*) FROM dbclustergroup_sys.data_mappings WHERE member_cluster_alias = 'ALIAS_B';With only this dataset in the group, member cluster A holds 4 mappings and member cluster B holds 0.
-
In CloudWatch, compare
SelectThroughput,DMLThroughput, andCPUUtilizationfor each member cluster'sDBClusterIdentifier, with the same period and statistic, as described in Monitoring member clusters side by side. Member cluster A serves all of the workload's reads and writes, and member cluster B serves none of them.
For more ways to find a busy member cluster, see One member cluster is busier than the others.
Moving two collocations under load
Move two blocks of IDs from member cluster A to member cluster B, one after the other, while the three processes keep running: first collocation cg_w2, which holds IDs 2,000,001 to 3,000,000, and then collocation cg_w3, which holds IDs 3,000,001 and above. Use a manual cutover, so that you choose the moment of each cutover and can watch the report lines around it. Run each statement at the routing endpoint, in a session that isn't pinned.
The following diagram shows the steps of the first move, and what the workload sees at each one. The second move has the same steps.
To move two collocations while a workload runs
-
Read the definition of the scaleout table, and save the output. You compare it with the definition after the moves.
SHOW CREATE SCALEOUT TABLE lt_w.sbtest_w;Then read the data mappings of the dataset. The output has one row for each member table,
sbtest_w0tosbtest_w3, and each row namesALIAS_A.SELECT router_table_name, member_cluster_alias, router_collocation_group FROM dbclustergroup_sys.data_mappings WHERE router_db_name = 'lt_w'; -
Preview the move of
cg_w2. Check that the preview reportsCollocation: cg_w2andTable data mapping updates: 1, for the mapping oflt_w.sbtest_w2, and has noErrors:list. For the output, see EXPLAIN ALTER DBCLUSTERGROUP MOVE COLLOCATION.EXPLAIN ALTER DBCLUSTERGROUP MOVE COLLOCATION cg_w2 FROM `ALIAS_A` TO `ALIAS_B` MANUAL_CUTOVER = 1;Quote each alias in backticks, because an alias can contain hyphens.
-
Start the move with a manual cutover. The statement returns the job ID (
JOB_ID). Keep it for the next steps.ALTER DBCLUSTERGROUP MOVE COLLOCATION cg_w2 FROM `ALIAS_A` TO `ALIAS_B` MANUAL_CUTOVER = 1;For the options, see ALTER DBCLUSTERGROUP MOVE COLLOCATION.
-
Read the job's row every 30 seconds, until
phasereadsCdc, which means that the job is ready for the cutover.SELECT job_id, status, phase, progress_details, errors, warnings FROM dbclustergroup_data_movement.move_info WHERE job_id = 'JOB_ID';The job stays in
Initializingfor several minutes, and then passes throughPrecheckandSeeding. The workload continues without errors through these phases. While the job runs, a direct read of the copy on member cluster B is refused with a data movement error, so read the moving data through the routing endpoint. For the phases and the replication lag inprogress_details, see Reading move status and Reading move status. -
Note the time in UTC, and cut over.
ALTER DBCLUSTERGROUP CUTOVER JOB 'JOB_ID';A cutover that you send as soon as the job reaches
Cdccan be refused with error1221(Replication lag has not been reported for this job yet; retry once replication progress is available). Wait untilprogress_detailsreportsreplication_lag_seconds, or send the statement again. The statement returns when the routing layer records the request, not when the cutover ends. For the replication lag bound, see ALTER DBCLUSTERGROUP CUTOVER JOB. -
Read the job's row again until
statusreadsCompleted. Then read the data mappings of the dataset, as in step 1, and confirm that the row ofsbtest_w2namesALIAS_B. A routed read of an ID in the moved block returns a row.SELECT id FROM lt_w.sbtest_w WHERE id = 2000001; -
Move
cg_w3the same way, with steps 2 to 6 andcg_w3in place ofcg_w2. Start the move after the first job readsCompleted. A routed read of an ID in the second moved block returns a row.SELECT id FROM lt_w.sbtest_w WHERE id = 3000001; -
Read the definition of the scaleout table again, and compare it with the output that you saved in step 1. The definition is the same. Then read the data mappings of the dataset, as in step 1. The rows of
sbtest_w0andsbtest_w1nameALIAS_A, and the rows ofsbtest_w2andsbtest_w3nameALIAS_B.SHOW CREATE SCALEOUT TABLE lt_w.sbtest_w; -
Connect directly to member cluster B, and count the rows of a moved member table. It holds all 1,000,000 rows of
cg_w2. On member cluster A, the source copy is gone, and the same query returns error1146(Table 'lt_w.sbtest_w2' doesn't exist).SELECT COUNT(*) FROM lt_w.sbtest_w2;
What to look for
In each process's report lines around each cutover, look for the following:
-
err/srises above 0 for about 2 seconds at the cutover, and returns to 0. The errors are63927on reads and writes of the moving collocation. The message names the member table, not the scaleout table:Cannot read `lt_w`.`sbtest_w2` while data movement job 'for a read, andJOB_ID' is in progressCannot write to `lt_w`.`sbtest_w2` while data movement job 'for a write. Inside a read transaction, a statement can also getJOB_ID' is in progress63928, after the routing layer has rolled the transaction back. A transaction that has written to the moving collocation loses its connection, with error2013. A cutover can also return1412,1317,1180, or1927, or close the connection, which some clients report as2006. sysbench retries each of these errors on a new connection, and each retry succeeds. sysbench reconnects by itself after2013and2006, so those show inreconn/s, noterr/s. With--report-interval=10, they show in one or two report lines. For the meaning of each code, see Cutover and Data movement errors. -
Reads and writes of the collocations that don't move get no errors at a cutover. Every error names the moving member table.
-
No process stops. At the end of each run, the
ignored errorstotal in the sysbench summary counts the errors that it retried.
Then confirm the new balance the same way that you saw the imbalance, as in Seeing the imbalance. Each member cluster now holds 2 of the dataset's mappings, and in CloudWatch the two member clusters serve about the same reads and writes, as the following diagram shows.
If a process stops, it prints a line that starts with FATAL and names the error code. Use the following table to find what to check.
| What stopped the process | What to check |
|---|---|
An error code that isn't in --mysql-ignore-errors |
Check the list on the command line, or in the file that you pass with --config-file. Look up the code in Error codes for database cluster groups for Aurora. If your application retries it, add it to the list and run the workload again. |
Error 1235 in a read transaction |
Check that the read transactions run with --key_block=1000000, so that each transaction stays in one block of IDs, and that you run the current dbcg_load.lua, whose hook reopens the connection before each retry. If both are true, check that each transaction in your workload uses one collocation. |
If a move itself fails, its move_info row reads Error, and the errors column holds the reason. See Data movement errors.
Moving the collocations back, or cleaning up
To run the test again, run another job to move cg_w2 and cg_w3 back from member cluster B to member cluster A, with the steps in Moving two collocations under load and the aliases swapped. Start each move after the previous job reads Completed and its cleanup_status reads Complete.
When you finish, including if you stop before the moves, stop the sysbench processes, or let them end at --time. Then remove the dataset in the following order.
To remove the scaleout table and its dataset
-
At the routing endpoint, drop the scaleout table and the routing function, and then delete the data mappings. Drop the scaleout table first, because the routing layer doesn't drop a routing function that a scaleout table uses.
DROP SCALEOUT TABLE lt_w.sbtest_w; DROP SCALEOUT ROUTING FUNCTION lt_w_range_fn; DELETE FROM dbclustergroup_sys.data_mappings WHERE router_db_name = 'lt_w'; -
Connect directly to each member cluster and drop the database.
DROP DATABASE lt_w;