Skip to content

Commit

Permalink
placementinsql: add the survival preferences docs (pingcap#12428)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiancai authored Feb 15, 2023
1 parent f212f32 commit d19fa85
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions placement-rules-in-sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ In addition to the placement options above, you can also use the advance configu
| `FOLLOWER_CONSTRAINTS` | A list of constraints that only apply to followers. |
| `LEARNER_CONSTRAINTS` | A list of constraints that only apply to learners. |
| `LEARNERS` | The number of learners. |
| `SURVIVAL_PREFERENCE` | The replica placement priority according to the disaster tolerance level of the labels. For example, `SURVIVAL_PREFERENCE="[region, zone, host]"`. |
## Examples
Expand Down Expand Up @@ -248,6 +249,26 @@ In dictionary format, constraints also indicate a number of instances that apply
>
> Dictionary and list formats are based on the YAML parser, but the YAML syntax might be incorrectly parsed. For example, `"{+disk=ssd:1,+disk=nvme:2}"` is incorrectly parsed as `'{"+disk=ssd:1": null, "+disk=nvme:1": null}'`. But `"{+disk=ssd: 1,+disk=nvme: 1}"` is correctly parsed as `'{"+disk=ssd": 1, "+disk=nvme": 1}'`.
### Survival preferences

When you create or modify a placement policy, you can use the `SURVIVAL_PREFERENCES` option to set the preferred survivability for your data.

For example, assuming that you have a TiDB cluster across 3 availability zones, with multiple TiKV instances deployed on each host in each zone. And when creating placement policies for this cluster, you have set the `SURVIVAL_PREFERENCES` as follows:

``` sql
CREATE PLACEMENT POLICY multiaz SURVIVAL_PREFERENCES="[zone, host]";
CREATE PLACEMENT POLICY singleaz CONSTRAINTS="[+zone=zone1]" SURVIVAL_PREFERENCES="[host]";
```

After creating the placement policies, you can attach them to the corresponding tables as needed:

- For tables attached with the `multiaz` placement policy, data will be placed in 3 replicas in different availability zones, prioritizing survival goals of data isolation cross zones, followed by survival goals of data isolation cross hosts.
- For tables attached with the `singleaz` placement policy, data will be placed in 3 replicas in the `zone1` availability zone first, and then meet survival goals of data isolation cross hosts.

> **Note:**
>
> `SURVIVAL_PREFERENCES` is equivalent to `location-labels` in PD. For more information, see [Schedule Replicas by Topology Labels](/schedule-replicas-by-topology-labels.md).
## Compatibility with tools

| Tool Name | Minimum supported version | Description |
Expand Down

0 comments on commit d19fa85

Please sign in to comment.