Skip to content
Merged
Changes from all 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
88 changes: 69 additions & 19 deletions configure-placement-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The following table shows the meaning of each field in a rule:
| `Count` | `int`, positive integer | The number of replicas. |
| `LabelConstraint` | `[]Constraint` | Filers nodes based on the label. |
| `LocationLabels` | `[]string` | Used for physical isolation. |
| `IsolationLevel` | `string` | Used to set the minimum physical isolation level
| `IsolationLevel` | `string` | Used to set the minimum physical isolation level

`LabelConstraint` is similar to the function in Kubernetes that filters labels based on these four primitives: `in`, `notIn`, `exists`, and `notExists`. The meanings of these four primitives are as follows:

Expand Down Expand Up @@ -207,24 +207,6 @@ EOF
pd-ctl config placement save --in=rules.json
```

pd-ctl also supports directly saving rules to the file by using the `load` command for easier modification:

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

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

Executing the above command saves all rules to the `rules.json` file.

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

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

The above command saves the rules of a PD Group to the `rules.txt` file.

### Use pd-ctl to configure rule groups

- To view the list of all rule groups:
Expand Down Expand Up @@ -259,6 +241,74 @@ The above command saves the rules of a PD Group to the `rules.txt` file.
pd-ctl config placement-rules rule-group delete pd
```

### Use pd-ctl to batch update groups and rules in groups

To view and modify the rule groups and all rules in the groups at the same time, execute the `rule-bundle` subcommand.

In this subcommand, `get {group_id}` is used to query a group, and the output result shows the rule group and rules of the group in a nested form:

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

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

The output of the above command:

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

To write the output to a file, add the `-out` argument to the `rule-bundle get` subcommand, which is convenient for subsequent modification and saving.

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

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

After the modification is finished, you can use the `rule-bundle set` subcommand to save the configuration in the file to the PD server. Unlike the `save` command described in [Set rules using pd-ctl](#set-rules-using-pd-ctl), this command replaces all the rules of this group on the server side.

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

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

### Use pd-ctl to view and modify all configurations

You can also view and modify all configuration using pd-ctl. To do that, save all configuration to a file, edit the configuration file, and then save the file to the PD server to overwrite the previous configuration. This operation also uses the `rule-bundle` subcommand.

For example, to save all configuration to the `rules.json` file, execute the following command:

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

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

After editing the file, execute the following command to save the configuration to the PD server:

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

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

### Use tidb-ctl to query the table-related key range

If you need special configuration for metadata or a specific table, you can execute the [`keyrange` command](https://github.com/pingcap/tidb-ctl/blob/master/doc/tidb-ctl_keyrange.md) in [tidb-ctl](https://github.com/pingcap/tidb-ctl) to query related keys. Remember to add `--encode` at the end of the command.
Expand Down