Skip to content

Commit

Permalink
pd: update placement rules (pingcap#4530)
Browse files Browse the repository at this point in the history
* pd: update placement rules

Signed-off-by: disksing <[email protected]>

* Update configure-placement-rules.md

Co-authored-by: TomShawn <[email protected]>

* Update configure-placement-rules.md

Co-authored-by: TomShawn <[email protected]>

* Update configure-placement-rules.md

Co-authored-by: TomShawn <[email protected]>

* Update configure-placement-rules.md

Co-authored-by: TomShawn <[email protected]>

* Update configure-placement-rules.md

Co-authored-by: TomShawn <[email protected]>

Co-authored-by: TomShawn <[email protected]>
  • Loading branch information
disksing and TomShawn authored Sep 21, 2020
1 parent 0fa5a1c commit bef0dae
Showing 1 changed file with 68 additions and 18 deletions.
86 changes: 68 additions & 18 deletions configure-placement-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,24 +211,6 @@ EOF
pd-ctl config placement save --in=rules.json
```

pd-ctl 还支持通过 `load` 命令将规则直接转存至文件以方便进行修改,只需要将查看命令的 `show` 改为 `load`

{{< copyable "shell-regular" >}}

```bash
pd-ctl config placement-rules load
```

以上命令将所有规则转存至 rules.json 文件。

{{< copyable "shell-regular" >}}

```bash
pd-ctl config placement-rules load --group=pd --out=rule.txt
```

以上命令将 PD Group 的规则转存至 rule.txt 文件。

### 使用 pd-ctl 设置规则分组

+ 查看所有的规则分组列表
Expand Down Expand Up @@ -263,6 +245,74 @@ pd-ctl config placement-rules load --group=pd --out=rule.txt
pd-ctl config placement-rules rule-group delete pd
```

### 使用 pd-ctl 批量更新分组及组内规则

使用 `rule-bundle` 子命令,可以方便地同时查看和修改规则分组及组内的所有规则。

该子命令中 `get {group_id}` 用来查询一个分组,输出结果为嵌套形式的规则分组和组内规则:

{{< copyable "shell-regular" >}}

```bash
pd-ctl config placement-rules rule-bundle get pd
```

输出示例:

```json
{
"group_id": "pd",
"group_index": 0,
"group_override": false,
"rules": [
{
"group_id": "pd",
"id": "default",
"start_key": "",
"end_key": "",
"role": "voter",
"count": 3
}
]
}
```

`rule-bundle get` 子命令中可以添加 `-out` 参数来将输出写入文件,方便后续修改保存。

{{< copyable "shell-regular" >}}

```bash
pd-ctl config placement-rules rule-bundle get pd -out="group.json"
```

修改完成后,使用 `rule-bundle set` 子命令将文件中的配置保存至 PD 服务器。与前面介绍的 `save` 不同,此命令会替换服务器端该分组内的所有规则。

{{< copyable "shell-regular" >}}

```bash
pd-ctl config placement-rules rule-bundle set pd -in="group.json"
```

### 使用 pd-ctl 查看和修改所有配置

用户还可以使用 pd-ctl 查看和修改所有配置,即把全部配置保存至文件,修改后再覆盖保存。该操作同样使用 `rule-bundle` 子命令。

下面的命令将所有配置保存至 `rules.json` 文件:

{{< copyable "shell-regular" >}}

```bash
pd-ctl config placement-rules rule-bundle load -out="rules.json"
```

编辑完文件后,使用下面的命令将配置保存至 PD 服务器:

{{< copyable "shell-regular" >}}

```bash
pd-ctl config placement-rules rule-bundle save -in="rules.json"
```

### 使用 tidb-ctl 查询表相关的 key range

若需要针对元数据或某个特定的表进行特殊配置,可以通过 [tidb-ctl](https://github.com/pingcap/tidb-ctl) 的 [`keyrange` 命令](https://github.com/pingcap/tidb-ctl/blob/master/doc/tidb-ctl_keyrange.md) 来查询相关的 key。注意要添加 `--encode` 返回 PD 中的表示形式。
Expand Down

0 comments on commit bef0dae

Please sign in to comment.