TiDB-OPS

TiKV 磁盘空间回收步骤记录

场景

操作

调整 store 权重

通过 PD Http API 快速查看集群内所有 Store 权重信息

curl http://10.10.10.15:2379/pd/api/v1/stores |  egrep '(id|address|state_name|region_weight|available)' | awk '{if(NR%5!=0)ORS=" "; else ORS="\n"}1' | sed 's/[ ][ ]*/  /g' | sed 's/"//g' | sort -nrk 8
./pd-ctl -u http://10.10.10.15:2379
» help store
show the store status

Usage:
  pdctl store [delete|label|weight] <store_id>
  store [command]

Available Commands:
  delete      delete the store
  label       set a store's label value
  weight      set a store's leader and region balance weight

Use "help store [command] " for more information about a command.
» store weight 194 0.1 0.1
» store 194
{
  "store": {
    "id": 194,
    "address": "10.10.10.13:20160",
    "state": 0,
    "state_name": "Up"
  },
  "status": {
    "capacity": "500 GiB",
    "available": "82 GiB",
    "leader_weight": 0.1,   # leader 权重
    "region_count": 31316,
    "region_weight": 0.1,   # region 权重
    "region_score": 313160,
    "start_ts": "2018-04-22T08:05:13+08:00",
    "last_heartbeat_ts": "2018-05-03T16:27:12.85852309+08:00",
    "uptime": "272h21m59.85852309s"
  }
}

添加 store 调度

添加指定 store evict scheduler ,控制该 store 在集群内 region leader 数量为 0 或者接近 0 值,不能控制该 store 是否增加成员副本。

curl -X POST -d '{"name":"evict-leader-scheduler","store_id": 194}' "http://10.10.10.15:2379/pd/api/v1/schedulers"
# curl http://10.13.128.205:2379/pd/api/v1/schedulers

[
  "evict-leader-scheduler-194",   # store 194 调度器
  "balance-region-scheduler",     # 默认调度器,region 均衡调度
  "balance-leader-scheduler",     # 默认调度器,leader 均衡调度
  "balance-hot-region-scheduler"  # 默认调度器,热点调度
]
curl -X DELETE "http://10.10.10.15:2379/pd/api/v1/schedulers/evict-leader-scheduler-194"

下线 Store

该方案可作为压轴方案 (集群内只有三台 TiKV 时,下线一台后,region 无处调度,但剩余两副本可继续维持集群使用)

./pd-ctl -u http://10.10.10.15:2379
» help store
show the store status

Usage:
  pdctl store [delete|label|weight] <store_id>
  store [command]

Available Commands:
  delete      delete the store
  label       set a store's label value
  weight      set a store's leader and region balance weight

Use "help store [command] " for more information about a command.
» store delete 194
» store 194
{
  "store": {
    "id": 194,
    "address": "10.10.10.13:20160",
    "state": 0,
    "state_name": "Offline"  # store 状态 ( UP 、Down 、Offline 、Tomestone)
  },
  "status": {
    "capacity": "500 GiB",
    "available": "82 GiB",
    "leader_weight": 0.1,   # leader 权重
    "region_count": 31316,
    "region_weight": 0.1,   # region 权重
    "region_score": 313160,
    "start_ts": "2018-04-22T08:05:13+08:00",
    "last_heartbeat_ts": "2018-05-03T16:27:12.85852309+08:00",
    "uptime": "272h21m59.85852309s"
  }
}