how-to: add placement rules guide#2246
Conversation
| { | ||
| "group_id": "tiflash", | ||
| "id": "learner-replica-table-03", | ||
| "start_key": "748000000000000003", // start key of table 3 |
There was a problem hiding this comment.
不行呀,都改成 6E 6D 的话,跟文字说明的“某个table"不匹配
| "count": 2, | ||
| "label_constraints": [ | ||
| {"key": "zone", "op": "in", "values": ["bj1", "bj2"]}, | ||
| {"key", "disk", "op": "notIn", "values": ["hdd"]} |
There was a problem hiding this comment.
| {"key", "disk", "op": "notIn", "values": ["hdd"]} | |
| {"key": "disk", "op": "notIn", "values": ["hdd"]} |
| >> config set enable-placement-rules true | ||
| ``` | ||
|
|
||
| 开启后会根据之前的副本配置默认生成一条规则,下面的生成的规则对应于之前版本的 `max-replicas=3,location-labels=[zone,rack,host]` 配置: |
There was a problem hiding this comment.
之前版本具体是哪个版本之前的呢?
| 开启后会根据之前的副本配置默认生成一条规则,下面的生成的规则对应于之前版本的 `max-replicas=3,location-labels=[zone,rack,host]` 配置: | |
| 开启后会根据之前的副本配置默认生成一条规则。下面的生成的规则对应之前版本的 `max-replicas=3,location-labels=[zone,rack,host]` 配置: |
|
|
||
| ### group_id | ||
|
|
||
| 标识规则的创建者,不同创建者之间互不影响 |
There was a problem hiding this comment.
这部分改为列表形式是否更好?每一个字段为一个列表项目。+ group_id:标识规则的创建者。不同创建者之间互不影响。
| 标识规则的创建者,不同创建者之间互不影响 | |
| 标识规则的创建者。不同创建者之间互不影响。 |
|
|
||
| *注意* 由于不同的 Rule 调度时单独计算,只能保证 default 规则的 3 副本按照 `location-labels` 隔离,meta 规则的 2 副本也隔离,而不能防止 default 规则的副本和 meta 规则的副本被调度在一起。 | ||
|
|
||
| 可以通过 default 规则的范围拆分成 2 个,key range 分别为 `["", "6D")` 和 `["6E", "")`,然后把 meta 规则的 `count` 调整为 5,让 meta 数据只适配一条 5 副本的规则,实现 `location-label` 的隔离。 |
There was a problem hiding this comment.
| 可以通过 default 规则的范围拆分成 2 个,key range 分别为 `["", "6D")` 和 `["6E", "")`,然后把 meta 规则的 `count` 调整为 5,让 meta 数据只适配一条 5 副本的规则,实现 `location-label` 的隔离。 | |
| 可以通过 default 规则的范围拆分成 2 个 key range,分别为 `["", "6D")` 和 `["6E", "")`,然后把 meta 规则的 `count` 调整为 `5`,让 meta 数据只适配一条 5 副本的规则,实现 `location-label` 的隔离。 |
| } | ||
| ``` | ||
|
|
||
| ### 场景二:5 副本按 2-2-1 的比例放置在 3 个数据中心,且第 3 个中心不调度 Leader |
There was a problem hiding this comment.
| ### 场景二:5 副本按 2-2-1 的比例放置在 3 个数据中心,且第 3 个中心不调度 Leader | |
| ### 场景二 | |
| 场景描述:5 副本按 2:2:1 的比例放置在 3 个数据中心,且第 3 个中心不调度 Leader。 |
|
|
||
| 每个数据中心对应一条规则,通过 `count` 设置副本数,通过 `role` 标识副本角色(是否需要 `leader`)。由于每个规则对应的副本都使用 `label_constraints` 约束在单个数据中心内了,`location_labels` 只需配置 `rack`,`host` 两级。 | ||
|
|
||
| ### 场景三:为某个 table 添加 2 个 TiFlash 副本 |
There was a problem hiding this comment.
| ### 场景三:为某个 table 添加 2 个 TiFlash 副本 | |
| ### 场景三 | |
| 场景描述:为某个 table 添加 2 个 TiFlash 副本。 |
| } | ||
| ``` | ||
|
|
||
| 该规则指定添加的角色为 `learner`,并且通过 `label_constraints` 被用于筛选 `engine` 的类型,指定 `engine` 类型为 `tiflash`。 |
There was a problem hiding this comment.
| 该规则指定添加的角色为 `learner`,并且通过 `label_constraints` 被用于筛选 `engine` 的类型,指定 `engine` 类型为 `tiflash`。 | |
| 该规则指定添加的角色为 `learner`,并且通过 `label_constraints` 筛选 `engine` 的类型,指定 `engine` 类型为 `tiflash`。 |
|
|
||
| 该规则指定添加的角色为 `learner`,并且通过 `label_constraints` 被用于筛选 `engine` 的类型,指定 `engine` 类型为 `tiflash`。 | ||
|
|
||
| ### 场景四:为某个 table 在有高性能磁盘的北京节点添加 2 个 Follower 副本 |
There was a problem hiding this comment.
| ### 场景四:为某个 table 在有高性能磁盘的北京节点添加 2 个 Follower 副本 | |
| ### 场景四 | |
| 场景描述:为某张表在有高性能磁盘的北京节点添加 2 个 Follower 副本。 |
|
LGTM |
| {{< copyable "shell-regular" >}} | ||
|
|
||
| ```bash | ||
| >> config set enable-placement-rules true |
There was a problem hiding this comment.
| >> config set enable-placement-rules true | |
| config set enable-placement-rules true |
|
|
||
| ## 开启 Placement Rules | ||
|
|
||
| 可通过 pd-ctl 设置 `enable-placement-rules` 为 `true` 开启 Placement Rules。 |
|
|
||
| {{< copyable "" >}} | ||
|
|
||
| ```json |
There was a problem hiding this comment.
使用 pd-ctl 的 config show 没有看到相关配置
|
|
||
| 以下部分介绍添加 Placement Rules 的典型场景。 | ||
|
|
||
| ### 场景一 |
There was a problem hiding this comment.
典型场景能不能把之行的命令直接贴一下,要不我还要自己转换 json 。。。
| "start_key": "6D", | ||
| "end_key": "6E", | ||
| "role": "voter", | ||
| "count": "2", |
There was a problem hiding this comment.
[root@4 bin]# curl -X POST -H "Content-Type: application/json" --data @data.json http://172.16.5.204:2379/pd/api/v1/config/rule
{
"code": "input",
"msg": "json: cannot unmarshal string into Go struct field Rule.count of type int",
"data": {
"Value": "string",
"Type": {},
"Offset": 101,
"Struct": "Rule",
"Field": "count"
}
}
| { | ||
| "group_id": "pd", | ||
| "id": "meta", | ||
| "start_key": "6D", |
There was a problem hiding this comment.
"start key should be encoded in table mode: insufficient bytes to decode value"
Signed-off-by: Ryan Leung <rleungx@gmail.com>
This reverts commit 922e368.
Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: Ryan Leung <rleungx@gmail.com>
110ccaf to
42674e4
Compare
|
@rleungx It seems that some comments haven't been resolved yet. |
|
@GregoryIan @disksing PTAL again, thanks! |
|
还有两个建议
|
|
@disksing PTAL |
|
No body is satisfied with this document. Closing it, I'll write it later. |

What is changed, added or deleted?
This PR adds the Placement Rules related document.
What is the related PR or file link(s)?
N/A
Which TiDB version(s) does your changes apply to?
3.1/dev