By default, an ApsaraDB for MongoDB replica set instance consists of a primary node, a secondary node, and a hidden node. The primary and secondary nodes provide external endpoints. The hidden node serves as a standby to ensure high availability. If a node fails, the ApsaraDB for MongoDB high-availability system automatically triggers a primary/secondary switchover to ensure instance availability. You can also trigger a primary/secondary switchover for an ApsaraDB for MongoDB instance in scenarios such as disaster recovery drills.
Background information
You can trigger a primary/secondary switchover only for replica set and sharded cluster instances. This feature is not supported for standalone instances because of their single-node architecture.
After you trigger a primary/secondary switchover, the instance is disconnected for up to 30 seconds. Ensure that your application can automatically reconnect to the instance.
You can trigger a primary/secondary switchover only for instances that are in the Running state.
Procedure
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.
On the instance details page, click Service Availability in the navigation pane on the left.
Click Switch Role.
In the Switch Role panel, select the Roles to switch and configure the Effective At parameter.
Effective Immediately: The system immediately performs a primary/secondary switchover.
Effective Within Maintenance Window: The system performs a primary/secondary switchover within the specified maintenance window. You can use the current maintenance window or specify a different one from the Change Maintenance Window drop-down list.
Click OK.
The instance status changes to Failing Over. When the instance status changes to Running, the switchover is complete.
NoteThe switchover takes about one minute to complete. After the switchover, the instance returns to a normal state.
If you connect to the instance using the endpoint of the primary node, you must use the endpoint of the new primary node after the switchover. Otherwise, read and write operations may fail. For more information, see Connect to a replica set instance.
Related questions
Why does the high availability system trigger a primary/secondary switchover?
Related APIs
API | Description |
Switches the primary and secondary nodes for an ApsaraDB for MongoDB instance. |