Skip to content

Commit

Permalink
Add domiciling doc with PLACEMENT RESTRICTED
Browse files Browse the repository at this point in the history
Fixes DOC-1178
Fixes DOC-1242

Summary of changes:

- Update 'Data Domiciling' page with some basic info, that explains how
  to accomplish domiciling with the 'ALTER DATABASE ... PLACEMENT
  RESTRICTED' feature, and how to check that replicas are where they are
  supposed to be using the Replication Reports.
  • Loading branch information
rmloveland committed Mar 23, 2022
1 parent c7b45e5 commit 87dd1a1
Show file tree
Hide file tree
Showing 6 changed files with 349 additions and 163 deletions.
2 changes: 1 addition & 1 deletion _includes/v21.2/sidebar-data/deploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
]
},
{
"title": "Data Domiciling",
"title": "Data Domiciling with CockroachDB",
"urls": [
"/${VERSION}/data-domiciling.html"
]
Expand Down
17 changes: 17 additions & 0 deletions _includes/v21.2/sql/multiregion-movr-global.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Because the data in `promo_codes` is not updated frequently (a.k.a., "read-mostly"), and needs to be available from any region, the right table locality is [`GLOBAL`](multiregion-overview.html#global-tables).

{% include copy-clipboard.html %}
~~~ sql
ALTER TABLE promo_codes SET locality GLOBAL;
~~~

Next, alter the `user_promo_codes` table to have a foreign key into the global `promo_codes` table. This will enable fast reads of the `promo_codes.code` column from any region in the cluster.

{% include copy-clipboard.html %}
~~~ sql
ALTER TABLE user_promo_codes
ADD CONSTRAINT user_promo_codes_code_fk
FOREIGN KEY (code)
REFERENCES promo_codes (code)
ON UPDATE CASCADE;
~~~
103 changes: 103 additions & 0 deletions _includes/v21.2/sql/multiregion-movr-regional-by-row.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
All of the tables except `promo_codes` contain rows which are partitioned by region, and updated very frequently. For these tables, the right table locality for optimizing access to their data is [`REGIONAL BY ROW`](multiregion-overview.html#regional-by-row-tables).

Apply this table locality to the remaining tables. These statements use a `CASE` statement to put data for a given city in the right region and can take around 1 minute to complete for each table.

- `rides`

{% include copy-clipboard.html %}
~~~ sql
ALTER TABLE rides ADD COLUMN region crdb_internal_region AS (
CASE WHEN city = 'amsterdam' THEN 'europe-west1'
WHEN city = 'paris' THEN 'europe-west1'
WHEN city = 'rome' THEN 'europe-west1'
WHEN city = 'new york' THEN 'us-east1'
WHEN city = 'boston' THEN 'us-east1'
WHEN city = 'washington dc' THEN 'us-east1'
WHEN city = 'san francisco' THEN 'us-west1'
WHEN city = 'seattle' THEN 'us-west1'
WHEN city = 'los angeles' THEN 'us-west1'
END
) STORED;
ALTER TABLE rides ALTER COLUMN REGION SET NOT NULL;
ALTER TABLE rides SET LOCALITY REGIONAL BY ROW AS "region";
~~~

- `user_promo_codes`

{% include copy-clipboard.html %}
~~~ sql
ALTER TABLE user_promo_codes ADD COLUMN region crdb_internal_region AS (
CASE WHEN city = 'amsterdam' THEN 'europe-west1'
WHEN city = 'paris' THEN 'europe-west1'
WHEN city = 'rome' THEN 'europe-west1'
WHEN city = 'new york' THEN 'us-east1'
WHEN city = 'boston' THEN 'us-east1'
WHEN city = 'washington dc' THEN 'us-east1'
WHEN city = 'san francisco' THEN 'us-west1'
WHEN city = 'seattle' THEN 'us-west1'
WHEN city = 'los angeles' THEN 'us-west1'
END
) STORED;
ALTER TABLE user_promo_codes ALTER COLUMN REGION SET NOT NULL;
ALTER TABLE user_promo_codes SET LOCALITY REGIONAL BY ROW AS "region";
~~~

- `users`

{% include copy-clipboard.html %}
~~~ sql
ALTER TABLE users ADD COLUMN region crdb_internal_region AS (
CASE WHEN city = 'amsterdam' THEN 'europe-west1'
WHEN city = 'paris' THEN 'europe-west1'
WHEN city = 'rome' THEN 'europe-west1'
WHEN city = 'new york' THEN 'us-east1'
WHEN city = 'boston' THEN 'us-east1'
WHEN city = 'washington dc' THEN 'us-east1'
WHEN city = 'san francisco' THEN 'us-west1'
WHEN city = 'seattle' THEN 'us-west1'
WHEN city = 'los angeles' THEN 'us-west1'
END
) STORED;
ALTER TABLE users ALTER COLUMN REGION SET NOT NULL;
ALTER TABLE users SET LOCALITY REGIONAL BY ROW AS "region";
~~~

- `vehicle_location_histories`

{% include copy-clipboard.html %}
~~~ sql
ALTER TABLE vehicle_location_histories ADD COLUMN region crdb_internal_region AS (
CASE WHEN city = 'amsterdam' THEN 'europe-west1'
WHEN city = 'paris' THEN 'europe-west1'
WHEN city = 'rome' THEN 'europe-west1'
WHEN city = 'new york' THEN 'us-east1'
WHEN city = 'boston' THEN 'us-east1'
WHEN city = 'washington dc' THEN 'us-east1'
WHEN city = 'san francisco' THEN 'us-west1'
WHEN city = 'seattle' THEN 'us-west1'
WHEN city = 'los angeles' THEN 'us-west1'
END
) STORED;
ALTER TABLE vehicle_location_histories ALTER COLUMN REGION SET NOT NULL;
ALTER TABLE vehicle_location_histories SET LOCALITY REGIONAL BY ROW AS "region";
~~~

- `vehicles`

{% include copy-clipboard.html %}
~~~ sql
ALTER TABLE vehicles ADD COLUMN region crdb_internal_region AS (
CASE WHEN city = 'amsterdam' THEN 'europe-west1'
WHEN city = 'paris' THEN 'europe-west1'
WHEN city = 'rome' THEN 'europe-west1'
WHEN city = 'new york' THEN 'us-east1'
WHEN city = 'boston' THEN 'us-east1'
WHEN city = 'washington dc' THEN 'us-east1'
WHEN city = 'san francisco' THEN 'us-west1'
WHEN city = 'seattle' THEN 'us-west1'
WHEN city = 'los angeles' THEN 'us-west1'
END
) STORED;
ALTER TABLE vehicles ALTER COLUMN REGION SET NOT NULL;
ALTER TABLE vehicles SET LOCALITY REGIONAL BY ROW AS "region";
~~~
4 changes: 2 additions & 2 deletions v21.1/demo-low-latency-multi-region-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,14 @@ ALTER DATABASE movr ADD REGION "us-west1";

#### Configure GLOBAL tables

As mentioned earlier, all of the tables except `promo_codes` are geographically specific. Because the data in `promo_codes` is not updated frequently (a.k.a., "read-mostly"), and needs to be available from any region, the right table locality is [`GLOBAL`](multiregion-overview.html#global-tables).
All of the tables except `promo_codes` contain rows which are partitioned by region, and updated very frequently. Because the data in `promo_codes` is not updated frequently (a.k.a., "read-mostly"), and needs to be available from any region, the right table locality is [`GLOBAL`](multiregion-overview.html#global-tables).

{% include copy-clipboard.html %}
~~~ sql
ALTER TABLE promo_codes SET locality GLOBAL;
~~~

Next, alter the `user_promo_codes` table to have a foreign key into the `promo_codes` table. This step is necessary to modify the MovR schema design to take full advantage of the multi-region features in v21.1+.
Next, alter the `user_promo_codes` table to have a foreign key into the global `promo_codes` table. This will enable fast reads of the `promo_codes.code` column from any region in the cluster.

{% include copy-clipboard.html %}
~~~ sql
Expand Down
Loading

0 comments on commit 87dd1a1

Please sign in to comment.