

# Preparing a test dataset

A test dataset in a database cluster group for Aurora has the same shape as your application's data: each table, database, or key range sits on the member cluster that its data mapping names, in its own collocation, so that you can move it on its own. The example on this page creates four tables in a database `lt` on two member clusters, two tables on each, and then a scaleout table `lt.sbtest` over all four. It uses `dbcg_load.lua` from [A sysbench script for a database cluster group for Aurora](databaseclustergroups-first-workload.md#databaseclustergroups-fw-sysbench-script).

The following diagram shows the layout.

![Member cluster A holds tables lt.sbtest1 and lt.sbtest2, and member cluster B holds lt.sbtest3 and lt.sbtest4. Each table is in its own collocation, lt_c1 to lt_c4, with its own range of 1,000,000 IDs. The optional scaleout table lt.sbtest spans all four tables, routed by id.](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/images/dbcg-fw-dataset-layout.png)


Load the data on each member cluster directly, not through the routing endpoint. A direct load is faster, and it doesn't count toward the workload.

## Creating and mapping the dataset
<a name="databaseclustergroups-fw-dataset-create"></a>

Data mappings name each member cluster by its alias. Before you start, read the alias of each member cluster at the routing endpoint.

```sql
SELECT member_cluster_alias, db_cluster_identifier FROM dbclustergroup_sys.member_cluster_mappings;
```

The output pairs each alias with the DB cluster identifier of its member cluster, for example:

```
+----------------------+-----------------------+
| member_cluster_alias | db_cluster_identifier |
+----------------------+-----------------------+
| member-a             | my-cluster-a          |
| member-b             | my-cluster-b          |
+----------------------+-----------------------+
```

In the following steps, replace {{ALIAS\_A}} and {{ALIAS\_B}} with the aliases of the two member clusters, such as `member-a` and `member-b`. Member cluster A is the one that you load tables 1 and 2 on.

**To create and map a test dataset**

1. Connect directly to each member cluster and create the database. Create it also on member clusters that start empty, because a data move needs the database on its target.

   ```sql
   CREATE DATABASE lt;
   ```

1. From a load generator host, create and fill the tables that each member cluster holds. Set `--mysql-host` to each member cluster's cluster endpoint and `--mysql-user` to a user of that member cluster, as [Connection options](databaseclustergroups-first-workload.md#databaseclustergroups-fw-sysbench-connection) shows.

   ```bash
   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 \
     --tables=4 --table_size=1000000 --table_set=1,2 prepare
   sysbench dbcg_load.lua --mysql-host={{MEMBER_B_ENDPOINT}} --mysql-port=3306 --mysql-user={{MEMBER_USER}} \
     --mysql-password={{PASSWORD}} --mysql-ssl=REQUIRED --mysql-db=lt \
     --tables=4 --table_size=1000000 --table_set=3,4 prepare
   ```

   `--table_size` is the number of rows in each table. `--table_set` lists the numbers of the tables that the command creates, here tables 1 and 2 on member cluster A and tables 3 and 4 on member cluster B. Without it, the command creates all the tables from 1 to `--tables`. Each command prints the ID range of each table that it creates, for example `sbtest3: ids 2000001..3000000`.

1. At the routing endpoint, with autocommit on, create one table-level data mapping for each table, each in its own collocation.

   ```sql
   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', 'sbtest1', 'lt', 'sbtest1', '{{ALIAS_A}}', 'lt_c1'),
          ('lt', 'sbtest2', 'lt', 'sbtest2', '{{ALIAS_A}}', 'lt_c2'),
          ('lt', 'sbtest3', 'lt', 'sbtest3', '{{ALIAS_B}}', 'lt_c3'),
          ('lt', 'sbtest4', 'lt', 'sbtest4', '{{ALIAS_B}}', 'lt_c4');
   ```

1. (Optional) At the routing endpoint, create a range routing function over the ID ranges and a scaleout table over the four tables. With the scaleout table, a test reaches every member cluster through one table name, routed by `id`.

   ```sql
   CREATE SCALEOUT ROUTING FUNCTION lt_range_fn(id BIGINT) AS PARTITION BY COLUMN(id) IN TARGET COLLOCATION (
     lt_c1 VALUES IN RANGE (1, 1000000),
     lt_c2 VALUES IN RANGE (1000001, 2000000),
     lt_c3 VALUES IN RANGE (2000001, 3000000),
     lt_c4 VALUES IN RANGE (3000001, 4000000));
   
   CREATE SCALEOUT TABLE lt.sbtest (ROUTE BY KEY(id POSITION(1)) USING ROUTING FUNCTION lt_range_fn)
     MEMBERS (MEMBER lt.sbtest1, MEMBER lt.sbtest2, MEMBER lt.sbtest3, MEMBER lt.sbtest4);
   ```

1. At the routing endpoint, check that the first and last IDs in the dataset return a row. If a query returns error 1412, run it again. A data mapping change reaches the routing layer shortly after the statement returns. Run the query on `lt.sbtest` only if you created the scaleout table.

   ```sql
   SELECT id FROM lt.sbtest1 WHERE id = 1;
   SELECT id FROM lt.sbtest4 WHERE id = 4000000;
   SELECT id FROM lt.sbtest WHERE id = 4000000;
   ```

For the data mapping and scaleout table statements, see [Data mappings and collocations](databaseclustergroups-data-mappings.md) and [Creating and loading a scaleout table](databaseclustergroups-create-scaleout-table.md). To remove the dataset when you finish, see [Removing the dataset](#databaseclustergroups-fw-dataset-remove).

## Removing the dataset
<a name="databaseclustergroups-fw-dataset-remove"></a>

Remove the dataset in the following order.

**To remove the test dataset**

1. At the routing endpoint, drop the scaleout table and the routing function, if you created them, and then delete the data mappings.

   ```sql
   DROP SCALEOUT TABLE lt.sbtest;
   DROP SCALEOUT ROUTING FUNCTION lt_range_fn;
   DELETE FROM dbclustergroup_sys.data_mappings WHERE router_db_name = 'lt';
   ```

1. Connect directly to each member cluster and drop the database.

   ```sql
   DROP DATABASE lt;
   ```