Manager Handbook for Distributed AntDB-T - P6
Tags: database
Published: 2023-08-02 06:20:09

#### append

**Command function:**

Append command is used to append cluster nodes to AntDB cluster for cluster expansion. Gtmcoord master is the core of the cluster, the append command does not include appending gtmcoord master command. Before executing the append command, you need to perform the following steps (assuming append coordinator to a new machine).

1. Add the host information of the new machine to the host table.
2. Add the coordinator information to be appended to the node table.
3. Create the user and password on the new machine.
4. Execute the deploy command to distribute the cluster executable files to the new machine.
5. Modify the hidden file `.bashrc` under the current user on the new machine by appending the following content and executing `source ~/.bashrc` to make it effective.

```shell
export ADBHOME=/opt/antdb/app (modify according to the actual situation) 
export PATH=$ADBHOME/bin:$PATH 
export LD_LIBRARY_PATH=$ADBHOME/lib:$LD_LIBRARY_PATH 
```

6. Execute start agent to start the agent process on the new machine.
7. Execute the append command. The specific functions can be viewed through the help command `\h append`.

**Command format:**

```sql
APPEND GTMCOORD SLAVE node_name 
APPEND DATANODE { MASTER | SLAVE } node_name 
APPEND COORDINATOR MASTER node_name 
 
-- Accelerate append coordinator with stream replication 
APPEND COORDINATOR dest_coordinator_name FOR source_coordinator_name 
APPEND ACTIVATE COORDINATOR node_name 
```

**Command example:**

```sql
-- Append a coordinator node named coord4 to the AntDB cluster: 
APPEND COORDINATOR master coord4; 
-- Append a datanode master node named db4 to the AntDB cluster:
APPEND DATANODE MASTER db4; 
-- Append a datanode slave node named db4 to the AntDB cluster:
APPEND DATANODE SLAVE db4; 
-- Append a coordinator master node to the AntDB cluster with stream replication:
APPEND COORDINATOR coord5 FOR coord1;  
APPEND ACTIVATE COORDINATOR coord5; 
```

#### failover

---


**Command function:**

When the gtmcoord/datanode master master node in the cluster has problems, you can switch the host of backup node over with this command to ensure the availability of the cluster.

In case of problems with the host, the backup machine can be upgraded to the host by the failover command to ensure the sustainability of the service. The specific functions can be viewed through the help command `\h failover gtmcoord` and `\h failover datanode`.

Note:

- Failover command allows standby machine to be upgraded to master  without adding “FORCE” only if the standby machine is synchronous and operates noemally, otherwise it reports an error; if  “FORCE” is added to failover command, the standby machine can  be upgraded to master as long as it opertaes normally. 

- The Failover command verifies the value of sync\_state column by node information and selects the synchronous standby to be promoted to master. If there is no synchronous standby, use the force option, the asynchronous standby with the closest xlog location to master will be selected to be promoted to master.

- **If the asynchronous standby is forced to be promoted to master by adding "FORCE" command, there may be a risk of data loss.**

**Command format:**

```sql
FAILOVER GTMCOORD node_name [ FORCE ] 
FAILOVER DATANODE node_name [ FORCE ] 
Parameter Description: 
node_name: 
Node name, corresponding to the name column of the node table. 
```

**Command example:**

```sql
-- Promote the synchronous standby machine of the gtmcoord master to the host: 
FAILOVER GTMCOORD  gc_1; 
-- Force the normally running asynchronous standby gc_1 to be promoted to host: 
FAILOVER GTMCOORD gc_1 FORCE; 
-- Promote the synchronous standby machine of datanode master db1 to host: 
FAILOVER DATANODE db1; 
-- Force the normally running asynchronous standby machine to be promoted to host.
FAILOVER DATANODE  db1 FORCE; 
```

#### switchover

**Command function:**

The switchover is done between the master and the standby. The original standby is promoted to the master and the original host is downgraded to the standby and re-followed to the new host. The switchover detects whether the xlog position between the primary and the standby is the same, if it is, the switchover is done, if not, the switchover is not done. If you need to do a forced switch, you need to add the force keyword.

**If the failover is forced to be performed by adding "FORCE" command, there may be a risk of data loss.**

**Command format:**

```
Command:     SWITCHOVER DATANODE 
Description: datanode master, datanode slave switchover, the original master changes to slave and the original slave changes to master 
Syntax: 
SWITCHOVER DATANODE SLAVE datanode_name 
 
Command:     SWITCHOVER GTMCOORD 
Description: gtmcoord master, gtmcoord slave switchover, the original master changes to slave and the original slave changes to master 
Syntax: 
SWITCHOVER GTMCOORD SLAVE gtmcoord_name 
```

**Command example:**

```sql
-- datanode master db1_1 exchanges roles with slave db1_2 
switchover datanode slave db1_2; 
-- datanode master db1_2  with slave db1_1  
switchover datanode slave db1_1 force; 
```