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.您希望将具有非零优先级的新投票数据承载节点添加到包含一个主仲裁器和一个仲裁器的现有两成员副本集中。
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 如果要添加的辅助副本滞后,并且生成的副本集是PSA配置,则第一次配置更改将更改需要提交"majority"
. "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:如果您正在执行前面的操作之一,则需要分两步重新配置复制副本集:
Reconfigure the replica set to add or modify a secondary with重新配置副本集以添加或修改具有{ votes: 1, priority: 0 }
.{ votes: 1, priority: 0 }
的secondary。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。
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);
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);