Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

placementinsql: add the survival preferences docs #12682

Merged
merged 22 commits into from
Feb 15, 2023
Merged
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions placement-rules-in-sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ SELECT * FROM information_schema.partitions WHERE tidb_placement_policy_name IS
| `FOLLOWER_CONSTRAINTS` | 仅适用于 follower 的约束列表。 |
| `LEARNER_CONSTRAINTS` | 仅适用于 learner 的约束列表。 |
| `LEARNERS` | 指定 learner 的数量。 |
| `SURVIVAL_PREFERENCE` | 指定按 label 容灾等级的优先级放置副本。例如 `SURVIVAL_PREFERENCE="[region, zone, host]"`。 |

## 示例

Expand Down Expand Up @@ -247,6 +248,23 @@ PARTITION BY RANGE( YEAR(purchased) ) (
>
> 字典和列表格式都基于 YAML 解析,但 YAML 语法有些时候不能被正常解析。例如 YAML 会把 `"{+disk=ssd:1,+disk=nvme:2}"`(`:` 后无空格)错误地解析成 `'{"+disk=ssd:1": null, "+disk=nvme:2": null}'`,不符合预期。但 `"{+disk=ssd: 1,+disk=nvme: 2}"`(`:` 后有空格)能被正确解析成 `'{"+disk=ssd": 1, "+disk=nvme": 2}'`。

### 生存偏好

在创建或修改放置策略时,你可以使用 `SURVIVAL_PREFERENCES` 选项设置数据的生存能力偏好。

例如,在一个拓扑是部署在 3 个 `zone` (即可用区),每个可用区的 `host`(即节点)上混合部署多个 tikv 实例的集群上:
nolouch marked this conversation as resolved.
Show resolved Hide resolved

``` sql
CREATE PLACEMENT POLICY multiaz SURVIVAL_PREFERENCES="[zone, host]";
CREATE PLACEMENT POLICY singleaz CONSTRAINTS="[+zone=zone1]" SURVIVAL_PREFERENCES="[host]";
nolouch marked this conversation as resolved.
Show resolved Hide resolved
```

对于以上例子,绑定了 `multiaz` 该放置策略的表,会以 3 副本的形式放置在不同的可用区里, 数据会先优先满足跨 `zone`(即可用区)级别数据隔离的生存目标,再满足跨 `host`(即机器)级别的数据隔离的生存目标;应用了 `singleaz` 放置策略的数据,会优先以 3 副本的形式全部放置在名为 `zone1` 这个可用区里,再满足跨 `host`(即机器)级别的数据隔离的生存目标。
nolouch marked this conversation as resolved.
Show resolved Hide resolved

> **注意:**
>
> `SURVIVAL_PREFERENCES` 和 PD 中的 `LOCATION_LABELS` 是等价的,更多信息可以参考[通过拓扑 label 进行副本调度](/schedule-replicas-by-topology-labels.md)。
qiancai marked this conversation as resolved.
Show resolved Hide resolved

## 工具兼容性

| 工具名称 | 最低兼容版本 | 说明 |
Expand Down