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, the performance of the ApsaraDB for MongoDB instance is degraded, and your business is affected.
In this example, the ECS instance to which your 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. Note that only the role of the node in Zone 2 is changed, whereas the zone and role ID of the node remain unchanged. ECS and ApsaraDB for MongoDB instances can be connected in the same zone.
Prerequisites
The ApsaraDB for MongoDB instance is a replica set or sharded cluster instance.
Usage notes
Each time node roles are switched in an ApsaraDB for MongoDB instance, the instance may be disconnected for up to 30 seconds. We recommend that you perform this operation during off-peak hours or make sure that your application can automatically reconnect to the instance.
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 node roles are switched in an ApsaraDB for MongoDB instance, the instance may be disconnected for up to 30 seconds. We recommend that you perform this operation during off-peak hours and make sure that your applications can automatically reconnect to the instance.
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 within a maintenance window. You can select the current maintenance window or customize a maintenance window in the Change Maintenance Window drop-down list.
Click OK.