Manager Handbook for Distributed AntDB-T - P3
Tags: database
Published: 2023-07-27 06:21:45

### node table related commands

The Node table is used to store information about each node in the deployed AntDB cluster, including the same/asynchronous relationship between slave and master nodes, etc. The commands to manage the node table are:

- add node（including ADD GTMCOORD、ADD COORDINATOR、ADD DATANODE）
- alter node（including ALTER GTMCOORD、ALTER COORDINATOR、ALTER DATANODE）
- remove node ( including DROP GTMCOORD、DROP COORDINATOR、DROP DATANODE）
- drop node（including DROP GTMCOORD、DROP COORDINATOR、DROP DATANODE）
- list node

These five commands are described below.

#### add node

---


**Command function:**

Add node information in node table. The specific function can be viewed by the help command `\h add gtmcoord`, `\h add coordinator` and `\h add datanode`.

**Note:** Both gtmcoord and datanode can exist multiple standy machines, and nodetype is slave. The first added slave node is synchronous slave by default, and the subsequent ones are potentially synchronous by default, and the sync\_state field value is `potential`

The specified node data storage path needs to be an empty directory, otherwise report an error when executing the initialization.

**Command format:**

```sql
ADD COORDINATOR MASTER master_name ( option ) 
ADD DATANODE MASTER master_name ( option ) 
ADD DATANODE SLAVE slave_name FOR master_name ( option ) 
ADD GTMCOORD MASTER master_name ( option ) 
ADD GTMCOORD SLAVE slave_name FOR master_name ( option ) 
where option must be the following: 
 
    HOST = host_name, 
    PORT = port_number, 
    SYNC_STATE = sync_mode, 
		PATH = pg_data 
		ZONE = zone_name 
		READONLY = readonly_type (valid only when adding coordinator) 
Parameter Description:  
node_name：Node name, corresponding to the name column of the node table. 
host_name：The hostname, corresponding to the hostname in the host table. 
port_number：The port number that the node listens on
Sync_mode：The synchronous/asynchronous relationship between the standby and the host, "on", "t", "true" all mean synchronous setting, "off", "f", "false" all mean asynchronous setting. 
pg_data：Node data path, you need to ensure that the directory is empty. 
zone_name：The name of the center to which the node belongs, the default is local, used in dual-center scenarios. 
readonly_type：Whether or not the coordinator is a read-only node 
```

Note: datanode and gtmcoord nodes support cascading, i.e. slave node can hang under slave node, so for can be followed by the name of slave node.

**Command example:**

```sql
-- Add a gtmcoord master node, host is localhost1, port is 6768, data path is "/home/antdb/data/gc": 
ADD GTMCOORD MASTER gc (HOST=localhost1, PORT=6768, PATH='/home/antdb/data/gc'); 
-- Add a gtmcoord slave node with host localhost2, port 6768 and data path "/home/antdb/data/gc": 
ADD GTMCOORD SLAVE gcs for gc (HOST=localhost2, PORT=6768, SYNC=t, PATH='/home/antdb/data/gc'); 
-- Add information about coord1 of coordinator node, host is localhost1, port is 5532, data path "/home/antdb/data/coord1": 
ADD COORDINATOR master coord1(HOST=localhost1, PORT=5532,PATH='/home/antdb/data/coord1'); 
-- Add db1 of datanode master node, host is localhost1, port is 15533, data path is "/home/antdb/data/db1": 
ADD DATANODE MASTER db1(HOST=localhost1, PORT=15533,PATH='/home/antdb/data/db1'); 
-- Add db1 of datanode slave node with host localhost2, port 15533 and data path "/home/antdb/data/db1": 
ADD DATANODE SLAVE db1s for db1(HOST=localhost1, PORT=15533, SYNC=t, PATH= '/home/antdb/data/db1'); 
-- Add cascade slave db11s of db1s of datanode slave node
ADD DATANODE SLAVE db11s for db1s(HOST=localhost1, PORT=15543, SYNC=t, PATH= '/home/antdb/data/db11');  
 
```

#### alter node

---


**Command function:**

Modify the node information in the node table. The specific function can be viewed by the help command “\\h alter gtmcoord” , ”\\h alter  coordinator” and ”\\h alter datanode”.

**Note:** **Before cluster initialization, you can update the node information by alter node; after cluster initialization, only the backup slave is allowed to update the sync\_state column with the asynchronous relationship.**

**Command format:**

```sql
ALTER GTMCOORD { MASTER | SLAVE } node_name ( option ) 
ALTER COORDINATOR MASTER node_name ( option ) 
ALTER DATANODE { MASTER | SLAVE } node_name ( option )   
 
where option can be one of: 
 
    HOST =host_name, 
    PORT = port_number, 
    SYNC_STATE = sync_mode, 
		PATH = pg_data 
		ZONE = zone_name 
 
Parameter Description: 
node_name：Node name, corresponding to the name column of the node table. 
host_name：The hostname, corresponding to the hostname in the host table. 
port_number： The port number that the node listens on.
Sync_mode：The synchronous/asynchronous relationship between slave node and master node. Only valid for slave nodes. The value "sync" means that the slave node is a synchronous slave, "potential" means that the slave node is a potentially synchronous node, and "async" means that the slave node async" means the slave is an asynchronous slave. 
pg_data：node data path, you need to ensure that the directory is empty. 
zone_name：The name of the center to which the node belongs, the default is local, used in dual-center scenarios. 
```

**Command example:**

```sql
-- Before cluster initialization, update the port number of gtmcoord master to 6666: 
ALTER GTMCOORD MASTER gtmcoord (PORT=6666); 
-- Update the gtmcoord slave to be in a synchronous relationship with the gtmcoord master: 
ALTER GTMCOORD SLAVE gcs (SYNC_STATE='sync'); 
-- Update gtmcoord extra to have an asynchronous relationship with gtmcoord master: 
ALTER GTMCOORD SLAVE gtms (SYNC_STATE='async'); 
-- Before cluster initialization, update the port of coordinator coord1 to 5532 and the data path is”/home/antdb/data/coord1”: 
ALTER COORDINATOR master coord1 (PORT=5532, PATH=’/home/antdb/data/coord1’); 
-- Before cluster initialization, update the host of datanode master db1 to localhost5, the data path is ”/home/antdb/data/db1”: 
ALTER DATANODE MASTER db1 (HOST=localhost5, PATH=’/home/antdb/data/coord1’); 
-- Update datanode slave db1 to be in a synchronous relationship with host datanode master: 
ALTER DATANODE SLAVE db1s (SYNC_STATE='sync'); 
-- Update datanode extra db1 to have an asynchronous relationship with host datanode master: 
ALTER DATANODE SLAVE db1s (SYNC_STATE='async'); 
```

#### remove node

---


**Command function:**

Modify the node's initialized and field values to false in the node table and delete the node from the pgxc\_node table, but keep the information in mgr's node table.

Note:

There are currently four types of nodes that can only be removed, coordiantor master and slave, datanode slave, and gtmcoord slave, and it requires the node to be in `not running` state.

**Command format**:

```sql
REMOVE COORDINATOR SLAVE node_name 
REMOVE COORDINATOR MASTER node_name 
REMOVE DATANODE SLAVE node_name 
REMOVE GTMCOORD SLAVE node_name 
```

**Command example:**

```sql
-- Remove coordinator node from the cluster 
remove coordinator master cd2; 
-- Remove datanode slave node from the cluster 
remove datanode slave db1_2; 
-- Remove gtmcoord slave node from the cluster 
remove datanode slave gc2; 
```

#### drop node

---


**Command function:**

Delete the node information in the node table. The specific function can be viewed by the help command `\h drop gtmcoord`, `\h drop coordinator` and `\h drop datanode`.

**Note:** Before cluster initialization, you can delete the node information by `drop node`, but in the presence of a backup, you need to delete the backup node before you can delete the master node. After cluster initialization, no `drop node` operation is allowed to be executed.

**Command format:**

```sql
DROP GTMCOORD { MASTER | SLAVE } node_name 
DROP COORDINATOR MASTER node_name [, ...] 
DROP DATANODE { MASTER | SLAVE } node_name [, ...] 
DROP ZONE zonename # Delete all nodes in the same zone 
```

**Command example:**

```sql
-- Delete datanode slave db1s before cluster initialization: 
DROP DATANODE SLAVE db1s; 
-- Delete coordinator coord1 before cluster initialization: 
DROP COORDINATOR master coord1; 
-- Delete gtmcoord slave gc before cluster initialization: 
DROP GTMCOORD SLAVE gcs; 
-- Delete gtmcoord master gc before cluster initialization: 
DROP GTMCOORD MASTER gc; 
```