ApsaraDB for MongoDB replica set instances run on a three-node architecture: a primary node, a secondary node, and a hidden node. The primary and secondary nodes provide external endpoints; the hidden node acts as a standby to support high availability. When a node fails, the high-availability system automatically triggers a primary/secondary switchover. Trigger a switchover manually for scenarios such as disaster recovery drills.
Prerequisites
Before you begin, ensure that you have:
A replica set or sharded cluster instance (standalone instances do not support primary/secondary switchovers due to their single-node architecture)
An instance in the Running state
An application that supports automatic reconnection (the instance will be disconnected for up to 30 seconds during the switchover)
Trigger a primary/secondary switchover
Go to the Replica Set Instances page. In the top navigation bar, select a resource group and a region, then click the ID of the target instance.
In the left navigation pane, click Service Availability.
Click Switch Role.
In the Switch Role panel, select the roles to switch under Roles, then set Effective At:
Option Description Effective Immediately The switchover starts right away. Effective Within Maintenance Window The switchover runs within the configured maintenance window. To use a different window, select one from the Change Maintenance Window drop-down list. Click OK.
The instance status changes to Failing Over. When it returns to Running, the switchover is complete. The whole process takes about one minute.
If your application connects directly to the primary node endpoint, update the connection string to use the new primary node endpoint. Otherwise, read and write operations may fail. For more information, see Connect to a replica set instance.
What's next
API reference
| API | Description |
|---|---|
| SwitchDBInstanceHA | Switches the primary and secondary nodes for an ApsaraDB for MongoDB instance. |