Skip to content
Open
Show file tree
Hide file tree
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
25 changes: 25 additions & 0 deletions best-practices/pd-scheduling-best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,31 @@ For hot regions scheduling, use `hot-region-scheduler`. Since TiDB v3.0, the pro

For hot write regions, `hot-region-scheduler` attempts to redistribute both region peers and leaders; for hot read regions, `hot-region-scheduler` only redistributes region leaders.

#### Hot region scheduling and replica isolation

If you need to place replicas of the same Region on different physical hosts, see [Configure host-level replica isolation](/configure-placement-rules.md#configure-host-level-replica-isolation) to set TiKV store labels and the replica placement policy. However, when multiple TiKV stores are deployed on the same physical host, these settings still cannot guarantee host isolation after every hot-region migration. The limitations are as follows.

`move-hot-read-leader` and `move-hot-write-leader` both migrate the replica that currently serves as the leader. Whether Placement Rules are enabled affects the isolation result after the migration:

- When Placement Rules are disabled, both migration paths choose a target according to `location-labels`, but do not directly check `isolation-level`. Therefore, setting only `isolation-level = "host"` cannot guarantee host isolation after the migration.
- When Placement Rules are enabled, both migration paths check the label constraints of the matching rule. However, if you configure multiple topology levels, PD might still place two replicas on the same host to distribute replicas across different zones. Therefore, setting `isolation_level = "host"` in the rule alone cannot guarantee host isolation after the migration.

Transferring the leader only to an existing voter peer does not change replica placement and does not repair an existing isolation problem.

> **Note:**
>
> In TiDB v8.5, when Placement Rules are disabled, `move-hot-read-leader` does not check `location-labels` or `isolation-level`. Enabling `schedule.enable-location-replacement` lets PD try to improve replica placement, but cannot prevent these migrations from placing replicas on the same host.

#### Configuration when only host isolation is required

If you only need host isolation and do not need replicas distributed across zones or racks, configure the cluster as follows so that leader and peer migrations for hot regions keep voter replicas on different hosts:

1. Configure an accurate `host` label for every store, make sure the number of available hosts is at least the number of voter replicas, and confirm that existing voter replicas are already distributed across different hosts.
2. Enable Placement Rules so that all voter replicas of the same Region are managed by the same `voter` rule.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Explain how to obtain the single voter rule.

If a cluster has retained multiple rules, enabling Placement Rules restores those rules; it does not consolidate them into one voter rule. Step 3 then has no single rule to configure. Direct readers to inspect and, if necessary, adjust the matching rules before continuing, while preserving the warning about existing policies.

As per coding guidelines, procedural steps must “make each step a clear action.”

Source: Coding guidelines

3. Set that rule's `location_labels` to `["host"]` and `isolation_level` to `"host"`. If you use only the default rule, the corresponding cluster configuration is `replication.location-labels = ["host"]` and `replication.isolation-level = "host"`.

With this configuration, PD no longer prioritizes distributing replicas across different zones or racks. If your cluster already requires cross-zone or cross-rack disaster recovery, or uses a multi-rule layout, evaluate the impact on the existing replica policy before you apply it.

### Cluster topology awareness

Cluster topology awareness enables PD to distribute replicas of a region as much as possible. This is how TiKV ensures high availability and disaster recovery capability. PD continuously scans all regions in the background. When PD finds that the distribution of regions is not optimal, it generates an operator to replace peers and redistribute regions.
Expand Down
19 changes: 19 additions & 0 deletions configure-placement-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@ pd-ctl config placement-rules disable
>
> After disabling Placement Rules, PD uses the original `max-replicas`, `location-labels`, and `isolation-level` configurations. The modification of rules (when Placement Rules is enabled) will not update these three configurations in real time. In addition, all the rules that have been configured remain in PD and will be used the next time you enable Placement Rules.

### Configure host-level replica isolation

Host isolation places replicas of the same Region on different physical hosts. Configure it as follows:

1. Configure topology labels for each TiKV store so that they match the actual deployment. For more information, see [Configure `labels` for TiKV, TiFlash, and TiDB](/schedule-replicas-by-topology-labels.md#configure-labels-for-tikv-tiflash-and-tidb). All stores on the same physical host must use the same `host` value, and different physical hosts must use different `host` values. If you also use upper-level labels such as `zone` or `rack`, make sure those labels also reflect the physical topology accurately.
2. Configure the replica placement policy according to how you use Placement Rules:

| Scenario | Configuration |
| --- | --- |
| Placement Rules disabled | Include `host` in `replication.location-labels` and set `replication.isolation-level = "host"` |

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Add the location-replacement prerequisite to the disabled-rules procedure.

If Placement Rules are disabled and some replicas of a Region are on the same host, the labels and isolation level in this procedure do not move those replicas. PD does not increase a replica's isolation through scheduling while schedule.enable-location-replacement is false (pd-control.md). Enable this setting before you apply the procedure to an existing cluster. Then confirm that the replicas are on different hosts.

| Placement Rules enabled with only the default rule | Include `host` in `replication.location-labels` and set `replication.isolation-level = "host"`. PD then updates the default rule automatically. |
| Placement Rules enabled with custom rules | Include `host` in each relevant rule's `location_labels` and set `isolation_level = "host"`. Cluster-level replication settings do not override custom rules. |

Each rule's isolation settings apply only to the replicas matched by that rule and do not automatically guarantee isolation across rules. If voter replicas of the same Region are managed by multiple rules, you can use `label_constraints` to restrict which hosts each rule can select based on store labels. For example, if one rule can select only `host-a` and `host-b`, and another can select only `host-c` and `host-d`, replicas managed by the two rules cannot share a host.

> **Note:**
>
> Even after you complete this configuration, hot-region migration can still place multiple replicas of the same Region on the same host. For the detailed limitations and the configuration that applies when you need only host isolation, see [Hot region scheduling and replica isolation](/best-practices/pd-scheduling-best-practices.md#hot-region-scheduling-and-replica-isolation).

### Set rules using pd-ctl

> **Note:**
Expand Down