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 ECS instance and an ApsaraDB for MongoDB instance are in the same zone and connected over the 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 will be affected.

Environment for role switching

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 change the role of the node in Zone 2 to primary and the role of the node in Zone 1 to secondary. Note that only the node roles are changed. ECS and ApsaraDB for MongoDB instances can be connected in the same zone without changing the actual zones and role IDs.

Prerequisites

Replica set or sharded cluster instances must be used.

Precautions

  • Switching node roles will cause a transient disconnection of up to 30 seconds. Perform this operation during off-peak hours or ensure that your application has a reconnection mechanism.
  • Switching node roles only changes the roles of nodes, but not the zones and role IDs of nodes.

Procedure

  1. Log on to the ApsaraDB for MongoDB console.
  2. In the upper-left corner of the page, select the resource group and the region of the target instance.
  3. In the left-side navigation pane, click Replica Set Instances or Sharded Cluster Instances based on the instance type.
  4. Find the target instance and click its ID.
  5. In the left-side navigation pane, click Service Availability.
  6. Subsequent steps on the Service Availability page vary depending on instance types.
    • Replica set instances
      1. Click Switch Role in the upper-right corner of the page.
      2. In the Switch Role dialog box that appears, select the roles.
      3. Select the Effective At.
        • Effective Immediately: The system will switch the roles of the nodes immediately.
        • Effective Within Maintenance Window: The system will switch the roles of the nodes during the maintenance period. How to specify a maintenance period, see Specify a maintenance period.
    • Sharded cluster instances
      Note For sharded cluster instances, you can only manage the zone distribution of shard and Configserver nodes.
      1. In the upper-right corner of the Zone Distribution for Shards or Zone Distribution for Configservers section, click Switch Role.
      2. In the Switch Role dialog box that appears, select the nodes.
      3. Select the Effective At.
        • Effective Immediately: The system will switch the roles of the nodes immediately.
        • Effective Within Maintenance Window: The system will switch the roles of the nodes during the maintenance period. How to specify a maintenance period, see Specify a maintenance period.
  7. Click Submit.