## Module 3: Upgrade the TiDB Cluster While The Workloads Are Running

### Step 1. Set the TiUP mirror location

+ Go back to [Terminal 1](ssh://monitor1-ssh#1), run tiup command to change the TiUP local mirror to v8.1.1.

  ```bash
  tiup mirror set tidb-community-server-8.1.1-linux-amd64
  ```

  ```output
  Successfully set mirror to /home/ec2-user/tidb-community-server-8.1.1-linux-amd64
  ```

### Step 2. Upgrade your TiDB cluster

+ Run `tiup` command to upgrade your TiDB cluster from v7.5.4 to v8.1.1. While the upgrade is in-progress, switch to [Terminal 2](ssh://monitor1-ssh#2) and [Terminal 3](ssh://monitor1-ssh#3).

  ```bash
  tiup cluster upgrade tidb-demo 8.1.1 --yes
  ```

  ```output
  Before the upgrade, it is recommended to read the upgrade guide at https://docs.tidb.io/tidb/stable/upgrade-tidb-using-tiup and finish the preparation steps.
  This operation will upgrade tidb v7.5.4 cluster tidb-demo to v8.1.1:
  will upgrade and restart component "                 pd" to "v8.1.1",
  will upgrade and restart component "               tikv" to "v8.1.1",
  will upgrade and restart component "               tidb" to "v8.1.1",
  ...
  + [ Serial ] - Download: component=grafana, version=v8.1.1, os=linux, arch=amd64
  + [ Serial ] - Download: component=tikv, version=v8.1.1, os=linux, arch=amd64
  + [ Serial ] - Download: component=tidb, version=v8.1.1, os=linux, arch=amd64
  + [ Serial ] - Download: component=prometheus, version=v8.1.1, os=linux, arch=amd64
  + [ Serial ] - Download: component=pd, version=v8.1.1, os=linux, arch=amd64
  ...
  Upgrading component pd
  	Restarting instance 10.90.1.135:2379
  	Restart instance 10.90.1.135:2379 success
  	Restarting instance 10.90.2.182:2379
  	Restart instance 10.90.2.182:2379 success
  	Restarting instance 10.90.3.231:2379
  	Restart instance 10.90.3.231:2379 success
  Upgrading component tikv
  	Evicting 11 leaders from store 10.90.1.55:20160...
  	  Still waiting for 11 store leaders to transfer...
  	  Still waiting for 11 store leaders to transfer...
  ...
  Upgrading component tidb
  	Restarting instance 10.90.1.124:4000
  	Restart instance 10.90.1.124:4000 success
  	Restarting instance 10.90.2.122:4000
  	Restart instance 10.90.2.122:4000 success
  ...
  ```

### Step 3. Verify that the INSERT and QUERY workloads are not interrupted

+ Observe [Terminal 2](ssh://monitor1-ssh#2) and [Terminal 3](ssh://monitor1-ssh#3), that the sample application connections and transactions have never been interrupted during the upgrade.

+ Wait until the upgrade command in [Terminal 1](ssh://monitor1-ssh#1) completes to proceed to the next step.

  ```output
  ...
  Upgraded cluster `tidb-demo` successfully
  ```

### Step 4. Verify the upgrade result

+ Run the command to get the cluster status and verify your cluster version is v8.1.1.

  ```bash
  tiup cluster display tidb-demo
  ```

  ```output
  Cluster type:       tidb
  Cluster name:       tidb-demo
  Cluster version:    v8.1.1
  Deploy user:        ec2-user
  SSH type:           builtin
  Dashboard URL:      http://18.138.239.33:2379/dashboard
  Grafana URL:        http://10.90.4.8:3000
  ID                Role          Host         Ports        OS/Arch       Status  Data Dir                      Deploy Dir
  --                ----          ----         -----        -------       ------  --------                      ----------
  10.90.4.8:9093    alertmanager  10.90.4.8    9093/9094    linux/x86_64  Up      /tidb-data/alertmanager-9093  /tidb-deploy/alertmanager-9093
  10.90.4.8:3000    grafana       10.90.4.8    3000         linux/x86_64  Up      -                             /tidb-deploy/grafana-3000
  10.90.1.152:2379  pd            10.90.1.152  2379/2380    linux/x86_64  Up|L    /tidb-data/pd-2379            /tidb-deploy/pd-2379
  10.90.2.73:2379   pd            10.90.2.73   2379/2380    linux/x86_64  Up      /tidb-data/pd-2379            /tidb-deploy/pd-2379
  10.90.3.163:2379  pd            10.90.3.163  2379/2380    linux/x86_64  Up      /tidb-data/pd-2379            /tidb-deploy/pd-2379
  10.90.4.8:9090    prometheus    10.90.4.8    9090/12020   linux/x86_64  Up      /tidb-data/prometheus-9090    /tidb-deploy/prometheus-9090
  10.90.2.180:4000  tidb          10.90.2.180  4000/10080   linux/x86_64  Up      -                             /tidb-deploy/tidb-4000
  10.90.3.89:4000   tidb          10.90.3.89   4000/10080   linux/x86_64  Up      -                             /tidb-deploy/tidb-4000
  10.90.1.88:20160  tikv          10.90.1.88   20160/20180  linux/x86_64  Up      /tidb-data/tikv-20160         /tidb-deploy/tikv-20160
  10.90.2.20:20160  tikv          10.90.2.20   20160/20180  linux/x86_64  Up      /tidb-data/tikv-20160         /tidb-deploy/tikv-20160
  10.90.3.69:20160  tikv          10.90.3.69   20160/20180  linux/x86_64  Up      /tidb-data/tikv-20160         /tidb-deploy/tikv-20160
  10.90.1.60:6000   tiproxy       10.90.1.60   6000/3080    linux/x86_64  Up      -                             /tidb-deploy/tiproxy-6000
  Total nodes: 12
  ```

+ Press <kbd>Ctrl</kbd>+<kbd>C</kbd> in [Terminal 2](ssh://monitor1-ssh#2) and [Terminal 3](ssh://monitor1-ssh#3) to stop both workloads.
