## Module 3: Scaling in a TiKV Cluster

### Step 1. Scale in the TiKV cluster

  ```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
  ```

### Step 2. Check the status of the TiDB cluster

+ The status of the TiKV node (IP address: `HOST_MONITOR1_PRIVATE_IP`) should be changed to `Tombstone` or `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`
  ```

### Step 3. Prune the TiDB cluster

+ If the status of your scaled in TiKV is `Tombstone`, you can prune this TiKV node to clean up the data.

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

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

### Step 4. Check the status of the TiDB cluster

  ```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
  ```
