View a markdown version of this page

UPDATE dbclustergroup_sys.data_mappings - Amazon Aurora

UPDATE dbclustergroup_sys.data_mappings

Use UPDATE dbclustergroup_sys.data_mappings to change the cluster name behind a router name, repoint a collocation, or rename a collocation in a database cluster group for Aurora.

Description

Changes data mappings: the cluster name behind a router name, the member cluster of a whole collocation, or a collocation's name. A mapping write moves no data. To move a collocation with its data, use ALTER DBCLUSTERGROUP MOVE COLLOCATION.

For the task, see Changing data mappings.

Syntax

UPDATE dbclustergroup_sys.data_mappings SET column = 'value' [, column = 'value' ...] WHERE { column = 'value' | (column, column [, ...]) = ('value', 'value' [, ...]) };

Parameters and options

For the columns, see INSERT INTO dbclustergroup_sys.data_mappings.

SET cluster_db_name, cluster_table_name

The new cluster names behind a row. The router name stays.

SET member_cluster_alias

The member cluster of the rows. To set it alone, use WHERE router_collocation_group = 'collocation' alone, which changes the whole collocation. To move one mapping, set router_collocation_group in the same SET list.

SET router_collocation_group

The new collocation. Set member_cluster_alias in the same statement, unless the WHERE clause filters on router_collocation_group. Then the statement renames the collocation, or moves the matched rows to a new collocation on the same member cluster.

WHERE

Required. One equality, or one tuple equality, on any column except db_cluster_identifier. Every row that matches changes, so a WHERE on a shared value such as router_collocation_group, member_cluster_alias, or router_db_name changes every row with that value. On Aurora MySQL, select one table with (router_db_name, router_table_name).

Where it runs and required privileges

Run the statement where you run every mapping write: at the routing endpoint, in an unpinned session, outside a transaction. For the rules, see INSERT INTO dbclustergroup_sys.data_mappings.

The router user needs dbclustergroup_metadata_admin or dbclustergroup_super_admin. For all privileges for database cluster groups for Aurora, see Privileges.

Usage notes

Keep the following in mind when you use the statement.

  • A mapping change reaches the routing layer within a short time, and a statement routed on an older mapping returns a retryable error. See Applying data mapping changes.

  • Before you repoint a collocation, copy and check every object of the collocation on the target member cluster. A data movement job does this for you.

  • Every row of a collocation is on the same member cluster, so a repoint names the whole collocation. The routing layer refuses a change of member_cluster_alias alone for any other WHERE clause, even for a row that is alone in its collocation. To move one mapping to its own collocation, set router_collocation_group and member_cluster_alias together in one UPDATE. Check that the number of affected rows matches the collocation's row count.

  • To put a member table of a scaleout table on another member cluster, move its collocation. The routing layer accepts an UPDATE of a member table's cluster_table_name, and that collocation's reads and writes go to the named table after the change reaches the routing layer.

  • Export the mappings before and after every change. See Exporting the mappings before and after a change.

One UPDATE can change at most 1,000 mappings. A statement whose WHERE clause matches more rows fails with error 1235, Replace of <n> rows exceeds the per-request limit of 1000; narrow the filter or split the write into smaller requests, and changes nothing. An UPDATE that repoints a whole collocation counts as one row, whatever the number of mappings in the collocation. For more information about the limit, see Routing metadata and naming limits.

An UPDATE that filters on router_collocation_group can set member_cluster_alias alone. It moves every data mapping in the collocation group to the new member cluster. To move one data mapping out of its group, set router_collocation_group and member_cluster_alias together. An UPDATE that filters on a single data mapping and sets only member_cluster_alias fails with error 64043, because the mappings of a collocation group must stay on one member cluster. This UPDATE changes only where the routing layer sends queries; it doesn't move data. Make sure the data is already on the new member cluster before you run it, or use ALTER DBCLUSTERGROUP MOVE COLLOCATION to move the data.

While a data movement job moves a collocation, the routing layer refuses a mapping write that touches the collocation or any object in it, with error 1205 (Metadata for ... is being changed by another operation).

A mapping change needs an available writer instance on every member cluster that it affects. This includes both the old and the new member cluster when you repoint a mapping. If one has no available writer, the change fails and nothing changes. The member clusters don't need to be reachable through the routing endpoint, because the routing layer reaches them directly.

Examples

The following example repoints the collocation cg_06 to member-c, after its objects are on member-c.

UPDATE dbclustergroup_sys.data_mappings SET member_cluster_alias = 'member-c' WHERE router_collocation_group = 'cg_06';

The following example keeps a router name and points it at a new object on the member cluster.

UPDATE dbclustergroup_sys.data_mappings SET cluster_table_name = 'customers_v2' WHERE (router_db_name, router_table_name) = ('app', 'customers');

Errors

The statement can return the following errors. For the error texts and all errors from the routing layer, see Routing and data mapping errors.

Aurora MySQL Meaning
1227 The router user lacks dbclustergroup_metadata_admin.
1235 (42000) The write is inside a transaction. Commit or roll back, and send it again outside a transaction.
64043 (42000) A change of member_cluster_alias alone with a WHERE clause other than router_collocation_group alone. Repoint the whole collocation, or set a collocation in the same SET list.
64066 (42000) The mapping is a member table of a scaleout table, and the change would leave a collocation that its routing function targets without a member.
64062 (42000) The statement sets router_collocation_group to an existing collocation on a different member cluster than member_cluster_alias. Name a collocation on that member cluster, or a new one.
64063 (42000) The statement sets router_collocation_group without member_cluster_alias, and the WHERE clause doesn't filter on router_collocation_group. Set both in the same SET list.
1235 (42000) AND/OR are not supported in the WHERE clause on this table: the WHERE clause has more than one condition. Use the tuple form.
1235 (42000) Replace of <n> rows exceeds the per-request limit of 1000; narrow the filter or split the write into smaller requests: your WHERE clause matches more than 1,000 rows, so the statement changes nothing. Narrow the WHERE clause.
1412 (HY000) After a mapping change, a statement that the routing layer routed on the older mapping returns this error. The routing layer resends a text-protocol statement up to 3 times first, then returns 1412 with the session and any open transaction intact, so retry the statement.
63928 (40001) Inside a transaction, a statement needed a mapping that changed after the transaction's first routed statement, and the routing layer rolled the whole transaction back. Retry the whole transaction from its first statement; don't send COMMIT.

For more information, see the following: