Sign In Try Free

Scale the TiDB Cluster Using TiUP

The capacity of a TiDB cluster can be increased or decreased without interrupting the online services.

This document describes how to scale the TiDB, TiKV, PD, TiCDC, or TiFlash cluster using TiUP. If you have not installed TiUP, refer to the steps inInstall TiUP on the control machineand import the cluster into TiUP before you use TiUP to scale the TiDB cluster.

To view the current cluster name list, runtiup cluster list.

For example, if the original topology of the cluster is as follows:

Host IP Service
10.0.1.3 TiDB + TiFlash
10.0.1.4 TiDB + PD
10.0.1.5 TiKV + Monitor
10.0.1.1 TiKV
10.0.1.2 TiKV

Scale out a TiDB/PD/TiKV cluster

If you want to add a TiDB node to the10.0.1.5host, take the following steps.

  1. Configure the scale-out topology:

    Add the scale-out topology configuration in thescale-out.yamlfile:

    
                    
    vi scale-out.yaml
    
                    
    tidb_servers:主持人:10.0.1.5 ssh_port: 22端口:4000 status_port: 10080 deploy_dir: /data/deploy/install/deploy/tidb-4000 log_dir: /data/deploy/install/log/tidb-4000

    Here is a TiKV configuration file template:

    
                    
    tikv_servers: - host: 10.0.1.5 ssh_port: 22 port: 20160 status_port: 20180 deploy_dir: /data/deploy/install/deploy/tikv-20160 data_dir: /data/deploy/install/data/tikv-20160 log_dir: /data/deploy/install/log/tikv-20160

    Here is a PD configuration file template:

    
                    
    pd_servers: - host: 10.0.1.5 ssh_port: 22 name: pd-1 client_port: 2379 peer_port: 2380 deploy_dir: /data/deploy/install/deploy/pd-2379 data_dir: /data/deploy/install/data/pd-2379 log_dir: /data/deploy/install/log/pd-2379

    To view the configuration of the current cluster, runtiup cluster edit-config . Because the parameter configuration ofglobalandserver_configsis inherited byscale-out.yamland thus also takes effect inscale-out.yaml.

    After the configuration, the current topology of the cluster is as follows:

    Host IP Service
    10.0.1.3 TiDB + TiFlash
    10.0.1.4 TiDB + PD
    10.0.1.5 TiDB+ TiKV + Monitor
    10.0.1.1 TiKV
    10.0.1.2 TiKV
  2. Run the scale-out command:

    
                    
    tiup cluster scale-out scale-out.yaml

    If you see theScaled cluster out successfully, the scale-out operation is successfully completed.

  3. Check the cluster status:

    
                    
    tiup cluster display

    Access the monitoring platform athttp://10.0.1.5:3000using your browser to monitor the status of the cluster and the new node.

After the scale-out, the cluster topology is as follows:

Host IP Service
10.0.1.3 TiDB + TiFlash
10.0.1.4 TiDB + PD
10.0.1.5 TiDB+ TiKV + Monitor
10.0.1.1 TiKV
10.0.1.2 TiKV

Scale out a TiFlash cluster

If you want to add a TiFlash node to the10.0.1.4host, take the following steps.

  1. Add the node information to thescale-out.yamlfile:

    Create thescale-out.yamlfile to add the TiFlash node information.

    
                    
    tiflash_servers: - host: 10.0.1.4

    Currently, you can only add IP but not domain name.

  2. Run the scale-out command:

    
                    
    tiup cluster scale-out scale-out.yaml
  3. View the cluster status:

    
                    
    tiup cluster display

    Access the monitoring platform athttp://10.0.1.5:3000using your browser, and view the status of the cluster and the new node.

After the scale-out, the cluster topology is as follows:

Host IP Service
10.0.1.3 TiDB + TiFlash
10.0.1.4 TiDB + PD +TiFlash
10.0.1.5 TiDB+ TiKV + Monitor
10.0.1.1 TiKV
10.0.1.2 TiKV

Scale out a TiCDC cluster

If you want to add two TiCDC nodes to the10.0.1.3and10.0.1.4hosts, take the following steps.

  1. Add the node information to thescale-out.yamlfile:

    Create thescale-out.yamlfile to add the TiCDC node information.

    
                    
    cdc_servers: - host: 10.0.1.3 gc-ttl: 86400 data_dir: /data/deploy/install/data/cdc-8300 - host: 10.0.1.4 gc-ttl: 86400 data_dir: /data/deploy/install/data/cdc-8300
  2. Run the scale-out command:

    
                    
    tiup cluster scale-out scale-out.yaml
  3. View the cluster status:

    
                    
    tiup cluster display

    Access the monitoring platform athttp://10.0.1.5:3000using your browser, and view the status of the cluster and the new nodes.

After the scale-out, the cluster topology is as follows:

Host IP Service
10.0.1.3 TiDB + TiFlash +TiCDC
10.0.1.4 TiDB + PD + TiFlash +TiCDC
10.0.1.5 TiDB+ TiKV + Monitor
10.0.1.1 TiKV
10.0.1.2 TiKV

Scale in a TiDB/PD/TiKV cluster

If you want to remove a TiKV node from the10.0.1.5host, take the following steps.

  1. View the node ID information:

    
                    
    tiup cluster display
    
                    
    Starting /root/.tiup/components/cluster/v0.4.6/cluster display TiDB Cluster: TiDB Version: v4.0.16 ID Role Host Ports Status Data Dir Deploy Dir -- ---- ---- ----- ------ -------- ---------- 10.0.1.3:8300 cdc 10.0.1.3 8300 Up data/cdc-8300 deploy/cdc-8300 10.0.1.4:8300 cdc 10.0.1.4 8300 Up data/cdc-8300 deploy/cdc-8300 10.0.1.4:2379 pd 10.0.1.4 2379/2380 Healthy data/pd-2379 deploy/pd-2379 10.0.1.1:20160 tikv 10.0.1.1 20160/20180 Up data/tikv-20160 deploy/tikv-20160 10.0.1.2:20160 tikv 10.0.1.2 20160/20180 Up data/tikv-20160 deploy/tikv-20160 10.0.1.5:20160 tikv 10.0.1.5 20160/20180 Up data/tikv-20160 deploy/tikv-20160 10.0.1.3:4000 tidb 10.0.1.3 4000/10080 Up - deploy/tidb-4000 10.0.1.4:4000 tidb 10.0.1.4 4000/10080 Up - deploy/tidb-4000 10.0.1.5:4000 tidb 10.0.1.5 4000/10080 Up - deploy/tidb-4000 10.0.1.3:9000 tiflash 10.0.1.3 9000/8123/3930/20170/20292/8234 Up data/tiflash-9000 deploy/tiflash-9000 10.0.1.4:9000 tiflash 10.0.1.4 9000/8123/3930/20170/20292/8234 Up data/tiflash-9000 deploy/tiflash-9000 10.0.1.5:9090 prometheus 10.0.1.5 9090 Up data/prometheus-9090 deploy/prometheus-9090 10.0.1.5:3000 grafana 10.0.1.5 3000 Up - deploy/grafana-3000 10.0.1.5:9093 alertmanager 10.0.1.5 9093/9294 Up data/alertmanager-9093 deploy/alertmanager-9093
  2. Run the scale-in command:

    
                    
    tiup cluster scale-in --node 10.0.1.5:20160

    The--nodeparameter is the ID of the node to be taken offline.

    If you see theScaled cluster in successfully, the scale-in operation is successfully completed.

  3. Check the cluster status:

    The scale-in process takes some time. If the status of the node to be scaled in becomesTombstone, that means the scale-in operation is successful.

    To check the scale-in status, run the following command:

    
                    
    tiup cluster display

    Access the monitoring platform athttp://10.0.1.5:3000using your browser, and view the status of the cluster.

The current topology is as follows:

Host IP Service
10.0.1.3 TiDB + TiFlash + TiCDC
10.0.1.4 TiDB + PD + TiFlash + TiCDC
10.0.1.5 TiDB + Monitor(TiKV is deleted)
10.0.1.1 TiKV
10.0.1.2 TiKV

Scale in a TiFlash cluster

If you want to remove a TiFlash node from the10.0.1.4host, take the following steps.

1. Adjust the number of replicas of the tables according to the number of remaining TiFlash nodes

Before the node goes down, make sure that the number of remaining nodes in the TiFlash cluster is no smaller than the maximum number of replicas of all tables. Otherwise, modify the number of TiFlash replicas of the related tables.

  1. For all tables whose replicas are greater than the number of remaining TiFlash nodes in the cluster, execute the following command in the TiDB client:

    
                    
    alter table <db-name>.< table -name> settiflash replica0;
  2. Wait for the TiFlash replicas of the related tables to be deleted.Check the table replication progressand the replicas are deleted if the replication information of the related tables is not found.

2. Perform the scale-in operation

Next, perform the scale-in operation with one of the following solutions.

Solution 1: Use TiUP to remove a TiFlash node

  1. First, confirm the name of the node to be taken down:

    
                    
    tiup cluster display
  2. Remove the TiFlash node (assume that the node name is10.0.1.4:9000from Step 1):

    
                    
    tiup cluster scale-in --node 10.0.1.4:9000

Solution 2: Manually remove a TiFlash node

In special cases (such as when a node needs to be forcibly taken down), or if the TiUP scale-in operation fails, you can manually remove a TiFlash node with the following steps.

  1. Use the store command of pd-ctl to view the store ID corresponding to this TiFlash node.

    • Enter the store command inpd-ctl(the binary file is underresources/binin the tidb-ansible directory).

    • If you use TiUP deployment, replacepd-ctlwithtiup ctl: pd:

      
                        
      tiup ctl: pd -u http://: store
  2. Remove the TiFlash node in pd-ctl:

    • Enterstore delete in pd-ctl (is the store ID of the TiFlash node found in the previous step.

    • If you use TiUP deployment, replacepd-ctlwithtiup ctl: pd:

      
                        
      tiup ctl: pd -u http://: store delete
  3. Wait for the store of the TiFlash node to disappear or for thestate_nameto becomeTombstonebefore you stop the TiFlash process.

    If, after waiting for a long time, the node still fails to disappear or thestate_namefails to becomeTombstone, consider using the following command to force the node out of the cluster (use with caution).

    
                    
    curl -X POST'http:///pd/api/v1/store//state?state=Tombstone'
  4. Manually delete TiFlash data files (whose location can be found in thedata_dirdirectory under the TiFlash configuration of the cluster topology file).

  5. Manually update TiUP's cluster configuration file (delete the information of the TiFlash node that goes down in edit mode).

    
                    
    tiup cluster edit-config

The steps to manually clean up the replication rules in PD are below:

  1. View all data replication rules related to TiFlash in the current PD instance:

    
                    
    curl http://:/pd/api/v1/config/rules/group/tiflash
    
                    
    [{“group_id”:“tiflash”、“id”:“table-45-r”、“机汇erride": true, "start_key": "7480000000000000FF2D5F720000000000FA", "end_key": "7480000000000000FF2E00000000000000F8", "role": "learner", "count": 1, "label_constraints": [ { "key": "engine", "op": "in", "values": [ "tiflash" ] } ] } ]
  2. Remove all data replication rules related to TiFlash. Take the rule whoseidistable-45-ras an example. Delete it by the following command:

    
                    
    curl -v -X DELETE http://:/pd/api/v1/config/rule/tiflash/table-45-r

Scale in a TiCDC cluster

If you want to remove the TiCDC node from the10.0.1.4host, take the following steps:

  1. Take the node offline:

    
                    
    tiup cluster scale-in --node 10.0.1.4:8300
  2. View the cluster status:

    
                    
    tiup cluster display

    Access the monitoring platform athttp://10.0.1.5:3000using your browser, and view the status of the cluster.

The current topology is as follows:

Host IP Service
10.0.1.3 TiDB + TiFlash + TiCDC
10.0.1.4 TiDB + PD +(TiCDC is deleted)
10.0.1.5 TiDB + Monitor
10.0.1.1 TiKV
10.0.1.2 TiKV
Download PDF Request docs changes Ask questions on Discord
Playground
New
One-stop & interactive experience of TiDB's capabilities WITHOUT registration.
Was this page helpful?
Products
TiDB
TiDB Dedicated
TiDB Serverless
Pricing
Get Demo
Get Started
©2023PingCAP. All Rights Reserved.