You can switch the node roles of an ApsaraDB for MongoDB instance in the ApsaraDB for MongoDB console based on your business deployment.
Typical scenario
When an Elastic Compute Service (ECS) instance and an ApsaraDB for MongoDB instance are in the same zone and connected over an internal network, the latency is minimal. If they are connected across different zones, the latency increases and the performance of ApsaraDB for MongoDB instances and your business is affected.
In this example, the ECS instance to which the application belongs is in Zone 2. If the primary node of the ApsaraDB for MongoDB instance is in Zone 1, the ECS instance needs to connect to the primary node across zones.
To optimize the business deployment architecture, you can switch the roles of the primary and secondary nodes. In this example, you can switch the role of the node in Zone 2 to primary. Only the node roles are changed, whereas the zones and role IDs of nodes remain unchanged. ECS and ApsaraDB for MongoDB instances can be connected in the same zone.
Prerequisites
The instance is a replica set or sharded cluster instance.
Precautions
Each time node roles are switched, the instance may experience a transient connection of up to 30 seconds. We recommend that you perform this operation during off-peak hours or make sure that your application can automatically re-establish a connection.
Each time you switch node roles, only the node roles are changed, whereas the zones and role IDs of nodes remain unchanged. ECS and ApsaraDB for MongoDB instances can be connected in the same zone.
Procedure
Log on to the ApsaraDB for MongoDB console.
In the left-side navigation pane, click Replica Set Instances or Sharded Cluster Instances based on the instance type.
In the upper-left corner of the page, select the resource group and region to which the instance belongs.
Click the ID of an instance, or click in the Actions column corresponding to the instance and select Manage.
In the left-side navigation pane of the instance details page, click Service Availability.
Perform the following operations based on the instance categories and their zones.
NoteEach time you trigger a primary/secondary switchover for an instance, the instance may be disconnected for no more than 30 seconds. We recommend that you perform this operation during off-peak hours and make sure that your applications can automatically re-establish a connection.
Replica set instances
In the Zone Distribution section, click Switch Role in the upper-left corner.
Sharded cluster instances
NoteFor sharded cluster instances, you can manage only the zone distribution of the shard and Configserver nodes.
In the Zone Distribution for Shards or Zone Distribution for Configservers section, click Switch Role in the upper-left corner.
In the Switch Role panel, specify the following parameters.
Parameter
Description
Role
The role before the switchover.
Role
The role after the switchover.
Effective At
The time period for the switchover.
Effective Immediately: The system immediately switches the roles of the nodes.
Effective Within Maintenance Window: The system switches the roles of the nodes in a maintenance window. You can select the current maintenance window or customize a maintenance window in the Change Maintenance Window drop-down list.
Click Submit.