Overview
重新配置主从仲裁节点 (PSA) 副本集或更改为 PSA 架构时,在以下情况下需要特别小心:
您想要将具有 PSA 架构的现有三成员副本集中的从节点重新配置为具有非零优先级的投票、数据承载节点。
您想要将一个新的具有非零优先级的投票、数据承载节点添加到包含一个主节点和一个仲裁节点的现有双成员副本集中。
警告
如果您添加的从节点滞后,并且生成的副本集是 PSA 配置,则第一个配置更改将使用 "majority" 更改提交更改需要的节点数。在这种情况下,您的提交点将滞后,直到从节点赶上。
本文档概述了在这些特定案例中不使用指定辅助方法rs.reconfigForPSASet()的情况下重新配置副本集的过程。
步骤
如果您正在执行上述操作之一,则需要分两步重新配置副本集:
重新配置副本集以使用
{ votes: 1, priority: 0 }添加或修改从节点。一旦添加或修改的从节点赶上所有已提交的写入,请重新配置从节点以具有非零优先级
{ votes: 1, priority: <num> }。
这种两步走的方法避免了在故障转移到新的从节点的情况下,在新的从节点拥有来自上一个主节点的所有已提交写入之前回滚已提交写入的可能性。
要运行rs.reconfigForPSASet()方法,您必须连接到副本集的主节点。
添加或修改投票为 1 但优先级为 0 的从节点
为避免在添加或更改承载数据的投票节点时回滚未提交的写入,需要先添加具有{ priority: 0 }的节点。
In mongosh, modify the replica set configuration. 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():
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);
重新配置从节点以具有非零优先级
从节点赶上后,将优先级设置为所需的数字。 在此重新配置成功之前,从节点必须复制其投票为零时提交的所有写入。 当您发出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);