## 模块 5: 存储层的缩容

+ 在`sysbench`工作负载进行期间缩减存储层。

### 步骤 1. 执行测试工作负载

+ 切换至[终端 2](ssh://monitor1-ssh#2)，再次执行`sysbench`工作负载。在工作负载进行期间，继续执行后续步骤，无需等待其完成。

   ```bash
   sysbench --config-file=sysbench_config oltp_read_only --tables=6 --table-size=1000000 run
   ```

   ```output
   sysbench 1.0.17 (using bundled LuaJIT 2.1.0-beta2)

   Running the test with following options:
   Number of threads: 14
   Report intermediate results every 5 second(s)
   Initializing random number generator from current time

   Initializing worker threads...

   Threads started!
   ...
   ```

### 步骤 2. 从集群中删除一个 TiKV 服务器

+ 在[终端 1](ssh://monitor1-ssh#1) 中，随机删除一个TiKV服务器，缩减存储层。

   ```bash
   ~/.tiup/bin/tiup cluster scale-in tidb-demo --node ${LAB:HOST_KV4_PRIVATE_IP}:20160 -y
   ```

   ```output
   ...
   Scaled cluster `tidb-demo` in successfully
   ```

+ 销毁已删除的TiKV节点。

   ```bash
   ~/.tiup/bin/tiup cluster prune tidb-demo -y
   ```

   ```output
   ...
   Destroy success
   ```

### 步骤 3. 确认 TiDB 集群状态

+ 确保TiDB集群中有三个`tikv`服务器。存储层的规模从4降至3。

   ```bash
   ~/.tiup/bin/tiup cluster display tidb-demo
   ```

   ```output
   Cluster type:       tidb
   Cluster name:       tidb-demo
   Cluster version:    v${LAB:TIDB_VERSION}
   Deploy user:        ec2-user
   SSH type:           builtin
   Dashboard URL:      http://54.185.182.184:2379/dashboard
   Grafana URL:        http://10.90.4.216:3000
   ID                 Role          Host         Ports        OS/Arch       Status  Data Dir                      Deploy Dir
   --                 ----          ----         -----        -------       ------  --------                      ----------
   10.90.4.216:9093   alertmanager  10.90.4.216  9093/9094    linux/x86_64  Up      /tidb-data/alertmanager-9093  /tidb-deploy/alertmanager-9093
   10.90.4.216:3000   grafana       10.90.4.216  3000         linux/x86_64  Up      -                             /tidb-deploy/grafana-3000
   10.90.3.191:2379   pd            10.90.3.191  2379/2380    linux/x86_64  Up|L    /tidb-data/pd-2379            /tidb-deploy/pd-2379
   10.90.4.216:9090   prometheus    10.90.4.216  9090/12020   linux/x86_64  Up      /tidb-data/prometheus-9090    /tidb-deploy/prometheus-9090
   10.90.1.16:4000    tidb          10.90.1.16   4000/10080   linux/x86_64  Up      -                             /tidb-deploy/tidb-4000
   10.90.1.51:4000    tidb          10.90.1.51   4000/10080   linux/x86_64  Up      -                             /tidb-deploy/tidb-4000
   10.90.3.213:20160  tikv          10.90.3.213  20160/20180  linux/x86_64  Up      /tidb-data/tikv-20160         /tidb-deploy/tikv-20160
   10.90.3.40:20160   tikv          10.90.3.40   20160/20180  linux/x86_64  Up      /tidb-data/tikv-20160         /tidb-deploy/tikv-20160
   10.90.3.71:20160   tikv          10.90.3.71   20160/20180  linux/x86_64  Up      /tidb-data/tikv-20160         /tidb-deploy/tikv-20160
   10.90.4.216:6000   tiproxy       10.90.4.216  6000/3080    linux/x86_64  Up      -                             /tidb-deploy/tiproxy-6000
   Total nodes: 9
   ```
