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 18 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
20 changes: 20 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,25 @@ 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 实例。在为该集群创建放置策略时,按如下方式设置上 `SURVIVAL_PREFERENCES`:
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]";
```

创建好放置策略后,你可以按需将放置策略绑定到对应的表上:
qiancai marked this conversation as resolved.
Show resolved Hide resolved
- 对于绑定了 `multiaz` 放置策略的表,数据将以 3 副本的形式放置在不同的可用区里,优先满足跨 `zone`(即可用区)级别数据隔离的生存目标,再满足跨 `host`(即节点)级别的数据隔离的生存目标。
- 对于绑定了 `singleaz` 放置策略的表,数据会优先以 3 副本的形式全部放置在 `zone1` 这个可用区里,再满足跨 `host`(即节点)级别的数据隔离的生存目标。
qiancai 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