diff --git a/placement-rules-in-sql.md b/placement-rules-in-sql.md index e665c471c123d..430784a5fca04 100644 --- a/placement-rules-in-sql.md +++ b/placement-rules-in-sql.md @@ -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 @@ -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 |