Modify PSA Replica Set Safely安全地修改PSA副本集

On this page本页内容

Overview概述

When reconfiguring primary-secondary-arbiter (PSA) replica sets or changing to a PSA architecture, you need to take special care in the following cases:在重新配置主辅助仲裁器(PSA)副本集或更改为PSA体系结构时,在以下情况下需要特别注意:

  • You want to reconfigure a secondary in an existing three-member replica set with a PSA architecture to become a voting, data-bearing node with a non-zero priority.您希望在PSA体系结构的现有三成员副本集中重新配置辅助副本,使其成为具有非零优先级的投票、数据承载节点。
  • You want to add a new voting, data-bearing node with a non-zero priority to an existing two-member replica set that contains one primary and one arbiter.您希望将具有非零优先级的新投票、数据承载节点添加到包含一个主节点和一个仲裁器的现有两成员副本集。
Warning警告

If the secondary you are adding is lagged and the resulting replica set is a PSA configuration, the first configuration change will change the number of nodes that need to commit a change with "majority". 如果要添加的次要副本已滞后,并且生成的副本集是PSA配置,则第一次配置更改将更改需要提交"majority"更改的节点数。In this case, your commit point will lag until the secondary has caught up.在这种情况下,您的提交点将滞后,直到辅助服务器赶上。

This document outlines the procedure for reconfiguring your replica set in these specific cases without using the designated helper method rs.reconfigForPSASet().本文档概述了在这些特定情况下重新配置副本集的过程,无需使用指定的助手方法rs.reconfigForPSASet()

Procedure过程

If you are performing one of the preceding operations, it is necessary to reconfigure your replica set in two steps:如果要执行上述操作之一,则需要分两步重新配置副本集:

  1. Reconfigure the replica set to add or modify a secondary with { votes: 1, priority: 0 }.重新配置副本集以添加或修改具有{ votes: 1, priority: 0 }的辅助副本。
  2. Once the added or modified secondary has caught up with all committed writes, reconfigure the secondary to have a non-zero priority { votes: 1, priority: <num> }.一旦添加或修改的辅助文件赶上所有提交的写入,请将辅助文件重新配置为具有非零优先级{ votes: 1, priority: <num> }

The two-step approach avoids the possibility of rolling back committed writes in the case of a failover to the new secondary before the new secondary has all committed writes from the previous primary.两步方法避免了在故障切换到新辅助设备时,在新辅助设备从上一个主设备完成所有已提交的写入之前回滚已提交的写操作的可能性。

To run the rs.reconfigForPSASet() method, you must connect to the primary of the replica set.要运行rs.reconfigForPSASet()方法,必须连接到副本集的primary

1

Add or modify a secondary with votes 1 but priority 0添加或修改投票数为1但优先级为0的辅助项

To avoid rolling back uncommitted writes when adding or changing a voting, data-bearing node, it is required that you add the node with { priority: 0 } first.为了避免在添加或更改投票数据承载节点时回滚未提交的写入,需要先添加具有{ priority: 0 }的节点。

In mongosh, modify the replica set configuration. mongosh中,修改副本集配置。To reconfigure an existing replica set, first retrieve the current configuration with rs.conf(), modify the configuration document as needed, and then pass the modified document to rs.reconfig():要重新配置现有副本集,首先使用rs.conf()检索当前配置,根据需要修改配置文档,然后将修改后的文档传递给rs.reconfig()

cfg = rs.conf();
cfg["members"] = [
  {
     // existing member or members
  },
  {
     "_id" : <num>,  // The array position of the new member in the
                     // ``members`` array.
     "host" : <host>,
     "arbiterOnly" : false,
     "buildIndexes" : true,
     "hidden" : false,
     "priority" : 0,
     "tags" : { <tags> },
     "secondaryDelaySecs" : <num>,
     "votes" : 1
  },
  {
     // existing member or members
  }
]
rs.reconfig(cfg);
2

Reconfigure the secondary to have non-zero priority将辅助服务器重新配置为具有非零优先级

Once the secondary is caught up, set the prority to the desired number. 一旦第二个被占用,将比例设置为所需的数字。Before this reconfiguration succeeds, the secondary must replicate all the writes that were committed when it had zero votes. 在重新配置成功之前,辅助服务器必须复制在其拥有零票时提交的所有写入。This is automatically checked when you issue the rs.reconfig() command.发出rs.reconfig()命令时,会自动检查此项。

cfg = rs.conf();
cfg["members"] = [
  {
     // existing member or members
  },
  {
     "_id" : <num>,  // The array position of the new member in the
                     // ``members`` array.
     "host" : <host>,
     "arbiterOnly" : false,
     "buildIndexes" : true,
     "hidden" : false,
     "priority" : <num>,
     "tags" : { <tags> },
     "secondaryDelaySecs" : <num>,
     "votes" : 1
  },
  {
     // existing member or members
  }
]
rs.reconfig(cfg);
←  Rename a Replica SetMitigate Performance Issues with PSA Replica Set →