Copying data and running backfills
In a database cluster group for Aurora, you use a data movement job to move whole collocations. For other changes, copy or rewrite the rows yourself. A mapping write or a routing function switch changes only where the routing layer looks, and moves no rows. Copy the rows first, and then change the mapping.
Use this page for the following tasks:
-
Take one database or table out of its collocation and place it on another member cluster.
-
Fill a new column, change stored values, or give rows a new routing key, in small batches through the routing endpoint.
To move a whole collocation, we recommend using data movement, as described in Moving data between member clusters. You can't move one key range of a scaleout table. A routing function switch moves no rows, so switch it only on an empty scaleout table, and data movement moves whole objects. To spread a table's keys differently, build a new scaleout table, as described in Changing the key or splitting a busy collocation.
Moving data yourself
To place one database or table on another member cluster, copy it with your own tools. Each copy follows the same pattern: copy the rows while writes continue, stop writes for a short pause, bring the target up to date, change the mapping, and check. The tools and statements for Aurora MySQL follow the procedure.
Before you begin, do the following:
-
Export the mappings and every scaleout definition that you change, as described in Exporting the mappings before and after a change. You use the export to undo the change.
-
Check that no data movement job that affects the object's collocation is running.
-
Create the target objects with their whole definition, including foreign keys, triggers, routines, and key counters.
-
Create the application's users and grants on the target. A missing grant appears only after the mapping change, as a permission error.
-
On Aurora MySQL, a move refuses any table that has a foreign key or is referenced by one, even when the related tables move together. Drop the foreign keys before you move the tables.
-
End sessions pinned to the source member cluster. A pinned session keeps writing the source copy after the mapping change. For more information, see Sessions, transactions, and session pinning.
To move data yourself
-
From a host that reaches both member cluster endpoints, copy the definitions, and then copy the rows from a consistent snapshot.
-
Stop writes to the moving objects. Pause the application, or set the source database read-only on the source writer (direct). Writes then fail, and the application retries them.
-
Over direct connections, re-copy what changed since step 1, including deleted rows. Compare counts and checksums on the source and the target, and continue only if they match.
-
At the routing endpoint, change the mapping, one statement at a time in autocommit.
For when the change reaches the routing layer, and what an open transaction that used the object sees, see Applying data mapping changes. Make the application retry on the error that page lists.
-
At the routing endpoint, from a new connection, run a routed read of each moved name and of a name that didn't move.
-
Resume writes, or make the source database writable again on the source writer (direct).
-
After your rollback window closes, clean up the source copy over a direct connection, not through the routing endpoint.
If routed reads miss rows after the mapping change, write the mapping back from your export. Copy back to the source any rows written on the target since the mapping change, and resolve key counter clashes in that copy.
Running a keyed backfill
A keyed backfill runs a large write as many small batches, one routing key value at a time, each checked before the next. Through the routing endpoint, every statement resolves to one member cluster. Use a keyed backfill to fill a new routing key column, change stored type values, or give rows a new key.
Before you begin, do the following:
-
Take a backup and export the mappings.
-
Check that no data movement job of the collocations that the batches reach is running. A move's cutover phase rejects writes, as described in Cutover.
-
Write a scaleout table only through the routing endpoint. A direct write to a member table bypasses the routing function. Run direct batches on a member cluster only for a database with a database-level mapping.
-
Size the backfill: the rows per key and per member cluster, and the indexes that each batch rewrites. Run large backfills in a quiet period.
-
List the routing key values to process, and keep a list of finished keys so that you can resume after a stop.
To run a keyed backfill
-
Make the change that comes before the batches. For example, add the new column as nullable on each member cluster, as described in Rolling out schema changes. Then have the application write it on new rows.
-
At the routing endpoint, run one batch for each key, with the key sent as its native type.
UPDATEROUTER_DB.TABLESETCOLUMN=VALUEWHEREKEY_COLUMN=KEYANDPK>=LOANDPK<HI;Group keys by member cluster, so that one member cluster's batches finish before the next one's start. Bound each batch with a statement time limit.
-
At the routing endpoint, after each batch, compare the rows that it was meant to change with the rows that it changed, for that key. Stop on any difference.
-
In your batch log, record the finished key. Pause when a member cluster's load rises, and stop if its routed reads slow down or fail.
-
After you record every key as finished, complete the change. For example, make the new column
NOT NULLon each member cluster.
The routing layer refuses an UPDATE of a routing key value, an UPDATE with no key, and a multi-row statement whose keys span member clusters. To give a row a new key, insert it under the new key, read it back, and then delete the old row. Run the insert and the delete in one transaction only when both keys route to the same member cluster.
To change stored type values, first have the application read both the old and the new value and write only the new one. Then rewrite the old value in keyed batches, and stop reading it after no row carries it.
When the backfill is done, check that your list records every key as finished, with matching counts. Run one routed read for each collocation, and compare the schemas across member clusters as described in Auditing access and member cluster configuration.
Related pages
For related tasks and concepts, see the following pages: