TiDB如何修改默认的PLACEMENT POLICY?


虽然没办法通过Placement Rules in SQL方式来更改default的策略,但是可以通过pd-ctl来更改。这里实测在default rule中加入以下规则,可以让默认的数据(不加任何PLACEMENT POLICY)不写入到label里包含disk=sata的TiKV节点。

      "label_constraints": [
      {
        "key": "disk",
        "op": "notIn",
        "values": [
          "sata"
        ]
      }
      ]

完整的配置和操作步骤为:

[tidb@prod-tiup-f01 ~]$ cat default-rule.json 
{
  "group_id": "pd",
  "group_index": 0,
  "group_override": false,
  "rules": [
    {
      "group_id": "pd",
      "id": "default",
      "start_key": "",
      "end_key": "",
      "role": "voter",
      "count": 3,
      "label_constraints": [
      {
        "key": "disk",
        "op": "notIn",
        "values": [
          "sata"
        ]
      }
      ],
      "location_labels": [
        "zone",
        "dc",
        "host"
      ]
    }
  ]
}
[tidb@prod-tiup-f01 ~]$ tiup ctl:v6.1.1 pd -u ****:2379 -i
Starting component `ctl`: /home/tidb/.tiup/components/ctl/v6.1.1/ctl pd -u ****:2379 -i
» config placement-rules rule-bundle set pd --in="default-rule.json"