## モジュール 3: TiKV クラスタのスケールイン

### 手順 1. TiKV クラスタをスケールインする

  ```bash
  tiup cluster scale-in tidb-test --node ${HOST_MONITOR1_PRIVATE_IP}:20160
  ```

  ```output
  ...
  Do you want to continue? [y/N]:(default=N) y
  The component `[tikv]` will become tombstone, maybe exists in several minutes or hours, after that you can use the prune command to clean it
  Do you want to continue? [y/N]:(default=N) y
  ...
  Scaled cluster `tidb-test` in successfully
  ```

### 手順 2. TiDB クラスタの状態を確認する

+ TiKVノードの状態（IPアドレス: `HOST_MONITOR1_PRIVATE_IP`）は `Tombstone` または `Pending Offline` に変更されている必要があります。

  ```bash
  tiup cluster display tidb-test
  ```

  ```output
  tiup is checking updates for component cluster ...
  ...
  ID                 Role          Host         Ports                            OS/Arch       Status     Data Dir                      Deploy Dir
  --                 ----          ----         -----                            -------       ------     --------                      ----------
  ...
  10.90.4.214:20160  tikv          10.90.4.214  20160/20180                      linux/x86_64  Tombstone  /tidb-data/tikv-20160         /tidb-deploy/tikv-20160
  Total nodes: 13
  There are some nodes can be pruned:
     Nodes: [10.90.4.214:20160]
     You can destroy them with the command: `tiup cluster prune tidb-test`
  ```

### 手順 3. TiDB クラスタの剪定

+ スケールインされたTiKVのステータスが`Tombstone`の場合、このTiKVノードを剪定してデータをクリーンアップできます。

  ```bash
  tiup cluster prune tidb-test
  ```

  ```output
  ...
  Do you confirm this action? [y/N]:(default=N) y
  ...
  Destroy success
  ```

### 手順 4. TiDB クラスタのステータスを確認する

+ TiDBクラスタの状態を確認してください。

  ```bash
  tiup cluster display tidb-test
  ```

  ```output
  tiup is checking updates for component cluster ...
  Starting component `cluster`: /home/ec2-user/.tiup/components/cluster/v1.12.1/tiup-cluster display tidb-test
  Cluster type:       tidb
  Cluster name:       tidb-test
  Cluster version:    v7.5.1
  Deploy user:        tidb
  SSH type:           builtin
  Dashboard URL:      http://10.90.1.122:2379/dashboard
  Grafana URL:        http://10.90.4.214:3000
  ID                 Role          Host         Ports                            OS/Arch       Status   Data Dir                      Deploy Dir
  --                 ----          ----         -----                            -------       ------   --------                      ----------
  10.90.4.214:9093   alertmanager  10.90.4.214  9093/9094                        linux/x86_64  Up       /tidb-data/alertmanager-9093  /tidb-deploy/alertmanager-9093
  10.90.4.214:3000   grafana       10.90.4.214  3000                             linux/x86_64  Up       -                             /tidb-deploy/grafana-3000
  10.90.1.122:2379   pd            10.90.1.122  2379/2380                        linux/x86_64  Up|L|UI  /tidb-data/pd-2379            /tidb-deploy/pd-2379
  10.90.2.243:2379   pd            10.90.2.243  2379/2380                        linux/x86_64  Up       /tidb-data/pd-2379            /tidb-deploy/pd-2379
  10.90.3.25:2379    pd            10.90.3.25   2379/2380                        linux/x86_64  Up       /tidb-data/pd-2379            /tidb-deploy/pd-2379
  10.90.4.214:9090   prometheus    10.90.4.214  9090/12020                       linux/x86_64  Up       /tidb-data/prometheus-9090    /tidb-deploy/prometheus-9090
  10.90.1.133:4000   tidb          10.90.1.133  4000/10080                       linux/x86_64  Up       -                             /tidb-deploy/tidb-4000
  10.90.2.92:4000    tidb          10.90.2.92   4000/10080                       linux/x86_64  Up       -                             /tidb-deploy/tidb-4000
  10.90.4.103:9000   tiflash       10.90.4.103  9000/8123/3930/20170/20292/8234  linux/x86_64  Up       /tidb-data/tiflash-9000       /tidb-deploy/tiflash-9000
  10.90.1.98:20160   tikv          10.90.1.98   20160/20180                      linux/x86_64  Up       /tidb-data/tikv-20160         /tidb-deploy/tikv-20160
  10.90.2.235:20160  tikv          10.90.2.235  20160/20180                      linux/x86_64  Up       /tidb-data/tikv-20160         /tidb-deploy/tikv-20160
  10.90.3.148:20160  tikv          10.90.3.148  20160/20180                      linux/x86_64  Up       /tidb-data/tikv-20160         /tidb-deploy/tikv-20160
  Total nodes: 12
  ```
