Skip to content

Conversation

@rleungx
Copy link
Member

@rleungx rleungx commented Feb 18, 2020

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

@rleungx rleungx added dev priority/P1 The issue has P1 priority. labels Feb 18, 2020
@TomShawn TomShawn added v4.0 This PR/issue applies to TiDB v4.0. translation/doing This PR’s assignee is translating this PR. labels Feb 18, 2020
{
"group_id": "tiflash",
"id": "learner-replica-table-03",
"start_key": "748000000000000003", // start key of table 3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的key要encode下不

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我从之前那个文章里 copy 过来的

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前那个简单化过,主要是为了好理解。。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

全部改成 6E 和 6D 了

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不行呀,都改成 6E 6D 的话,跟文字说明的“某个table"不匹配

@yikeke
Copy link
Contributor

yikeke commented Feb 23, 2020

After this PR merges, sre-bot will automatically cherry-pick this PR to the release-3.1 branch (the needs-cherry-pick-xxx label will trigger the behavior). FYI. @rleungx @disksing

"count": 2,
"label_constraints": [
{"key": "zone", "op": "in", "values": ["bj1", "bj2"]},
{"key", "disk", "op": "notIn", "values": ["hdd"]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{"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]` 配置:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前版本具体是哪个版本之前的呢?

Suggested change
开启后会根据之前的副本配置默认生成一条规则,下面的生成的规则对应于之前版本的 `max-replicas=3,location-labels=[zone,rack,host]` 配置:
开启后会根据之前的副本配置默认生成一条规则。下面的生成的规则对应之前版本的 `max-replicas=3,location-labels=[zone,rack,host]` 配置:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rleungx 请明确一下之前版本


### group_id

标识规则的创建者,不同创建者之间互不影响
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这部分改为列表形式是否更好?每一个字段为一个列表项目。+ group_id:标识规则的创建者。不同创建者之间互不影响。

Suggested change
标识规则的创建者不同创建者之间互不影响
标识规则的创建者不同创建者之间互不影响


*注意* 由于不同的 Rule 调度时单独计算,只能保证 default 规则的 3 副本按照 `location-labels` 隔离,meta 规则的 2 副本也隔离,而不能防止 default 规则的副本和 meta 规则的副本被调度在一起。

可以通过 default 规则的范围拆分成 2 个,key range 分别为 `["", "6D")` 和 `["6E", "")`,然后把 meta 规则的 `count` 调整为 5,让 meta 数据只适配一条 5 副本的规则,实现 `location-label` 的隔离。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
可以通过 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### 场景二: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 副本
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### 场景三:为某个 table 添加 2 个 TiFlash 副本
### 场景三
场景描述:为某个 table 添加 2 个 TiFlash 副本。

}
```

该规则指定添加的角色为 `learner`,并且通过 `label_constraints` 被用于筛选 `engine` 的类型,指定 `engine` 类型为 `tiflash`。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
该规则指定添加的角色为 `learner`,并且通过 `label_constraints` 被用于筛选 `engine` 的类型,指定 `engine` 类型为 `tiflash`
该规则指定添加的角色为 `learner`,并且通过 `label_constraints` 筛选 `engine` 的类型,指定 `engine` 类型为 `tiflash`


该规则指定添加的角色为 `learner`,并且通过 `label_constraints` 被用于筛选 `engine` 的类型,指定 `engine` 类型为 `tiflash`。

### 场景四:为某个 table 在有高性能磁盘的北京节点添加 2 个 Follower 副本
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### 场景四:为某个 table 在有高性能磁盘的北京节点添加 2 个 Follower 副本
### 场景四
场景描述:为某张表在有高性能磁盘的北京节点添加 2 个 Follower 副本。

@rleungx
Copy link
Member Author

rleungx commented Feb 25, 2020

PTAL @disksing @TomShawn

@yikeke yikeke added size/large Changes of a large size. translation/welcome Waits for a contributor to translate this PR and create a PR to the pingcap/docs-cn repository. translation/doing This PR’s assignee is translating this PR. and removed dev translation/doing This PR’s assignee is translating this PR. translation/welcome Waits for a contributor to translate this PR and create a PR to the pingcap/docs-cn repository. labels Mar 3, 2020
@TomShawn
Copy link
Contributor

TomShawn commented Mar 5, 2020

LGTM
@disksing PTAL again, thanks!

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

```bash
>> config set enable-placement-rules true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
>> config set enable-placement-rules true
config set enable-placement-rules true


## 开启 Placement Rules

可通过 pd-ctl 设置 `enable-placement-rules` 为 `true` 开启 Placement Rules。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pd-ctl 使用文档 link 一下?


{{< copyable "" >}}

```json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我运行后我没看到这条规则, 怎么看?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

使用 pd-ctl 的 config show 没有看到相关配置

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

使用 curl 通过 GET 命令才看到


以下部分介绍添加 Placement Rules 的典型场景。

### 场景一
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

典型场景能不能把之行的命令直接贴一下,要不我还要自己转换 json 。。。

@disksing
Copy link
Contributor

这个comment还没有处理
screen20200312_145125

"start_key": "6D",
"end_key": "6E",
"role": "voter",
"count": "2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"start key should be encoded in table mode: insufficient bytes to decode value"

rleungx and others added 8 commits March 12, 2020 15:13
Signed-off-by: Ryan Leung <rleungx@gmail.com>
This reverts commit b2208b9, reversing
changes made to e50d22e.
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>
@lilin90
Copy link
Member

lilin90 commented Mar 12, 2020

@rleungx It seems that some comments haven't been resolved yet.

@TomShawn
Copy link
Contributor

@GregoryIan @disksing PTAL again, thanks!

@IANTHEREAL
Copy link
Contributor

还有两个建议

  • 提供方法怎么便捷的查询到一些用户常用的 start key & end key,比如某 table

  • 案例太单薄,操作有风险,需要提供更详细的学习文档,或者更加惊醒的提示。 可能会因为误操作 placement rule 而导致的数据丢失

@rleungx
Copy link
Member Author

rleungx commented Mar 19, 2020

@disksing PTAL

@disksing
Copy link
Contributor

No body is satisfied with this document. Closing it, I'll write it later.

@disksing disksing closed this Mar 23, 2020
@disksing disksing mentioned this pull request Mar 31, 2020
4 tasks
@ran-huang ran-huang removed their assignment Apr 16, 2020
@yikeke yikeke removed the translation/doing This PR’s assignee is translating this PR. label May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/P1 The issue has P1 priority. size/large Changes of a large size. v4.0 This PR/issue applies to TiDB v4.0.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants