On this page本页内容
rs.reconfigForPSASet( memberIndex, config, { options } )
New in version 5.0.在版本5.0中新增。
Safely perform some reconfiguration changes on a primary-secondary-arbiter (PSA) replica set or on a replica set that is changing to a PSA architecture. 在主辅助仲裁器(PSA)副本集或正在更改为PSA架构的副本集上安全地执行一些重新配置更改。You should only use this method in one of the following cases:只能在以下情况之一下使用此方法:
priority
.priority
的投票、数据承载节点。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.在这种情况下,您的提交点将延迟,直到辅助节点赶上。
For details about the behavior of this method, see Behavior.有关此方法行为的详细信息,请参阅行为。
The rs.reconfigForPSASet()
method has the following syntax:rs.reconfigForPSASet()
方法具有以下语法:
rs.reconfigForPSASet( memberIndex: <num>, config: <configuration>, { "force" : <boolean>, "maxTimeMS" : <int> } )
memberIndex | integer | |
config | document | |
force | boolean |
|
maxTimeMS | integer |
|
The rs.reconfigForPSASet()
method reconfigures your replica set in two steps:rs.reconfigForPSASet()
方法分两步重新配置副本集:
{ votes: 1, priority: 0 }
.{ votes: 1, priority: 0 }
的辅助副本。priority
specified in the rs.reconfigForPSASet()
command ({ votes: 1, priority: <num> }
).rs.reconfigForPSASet()
命令中指定的priority
({ 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 configuration.两步方法避免了在故障转移到新辅助设备的情况下,在新辅助设备完成以前配置中的所有提交写入之前回滚提交写入的可能性。
A replica set named 名为rs0
has the following configuration:rs0
的副本集具有以下配置:
{ "_id" : "rs0", "version" : 1, "term": 1, "members" : [ { "_id" : 0, "host" : "mongodb0.example.net:27017", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : {}, "secondaryDelaySecs" : Long("0"), "votes" : 1 }, { "_id" : 2, "host" : "mongodb2.example.net:27017", "arbiterOnly" : true, "buildIndexes" : true, "hidden" : false, "priority" : 0, "tags" : {}, "secondaryDelaySecs" : Long("0"), "votes" : 1 } ], "protocolVersion" : Long("1"), "writeConcernMajorityJournalDefault": true, "settings" : { "chainingAllowed" : true, "heartbeatIntervalMillis" : 2000, "heartbeatTimeoutSecs" : 10, "electionTimeoutMillis" : 10000, "catchUpTimeoutMillis" : 2000, "getLastErrorModes" : {}, "getLastErrorDefaults" : { "w" : 1, "wtimeout" : 0 }, "replicaSetId" : ObjectId("60e6f83923193faa336889d2") } }
The following sequence of operations add a new secondary to the replica set. 以下操作序列将向副本集添加一个新的辅助副本。The operations are issued in the 这些操作在连接到主服务器时在mongosh
shell while connected to the primary.mongosh
shell中发出。
cfg = rs.conf(); cfg["members"] = [ { "_id" : 0, "host" : "mongodb0.example.net:27017", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : {}, "secondaryDelaySecs" : Long("0"), "votes" : 1 }, { "_id" : 1, "host" : "mongodb2.example.net:27017", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 2, "tags" : {}, "secondaryDelaySecs" : Long("0"), "votes" : 1 }, { "_id" : 2, "host" : "mongodb2.example.net:27017", "arbiterOnly" : true, "buildIndexes" : true, "hidden" : false, "priority" : 0, "tags" : {}, "secondaryDelaySecs" : Long("0"), "votes" : 1 } ] rs.reconfigForPSASet(1, cfg);
rs.conf()
method to retrieve a document containing the current configuration for the replica set and stores the document in the local variable cfg
.rs.conf()
方法检索包含副本集当前配置的文档,并将该文档存储在本地变量cfg
中。members
array. members
数组中。memberIndex
1
. memberIndex1
。memberIndex
is the same as the array index. memberIndex
与数组索引相同。The last statement calls the 最后一条语句使用rs.reconfigForPSASet()
method with the memberIndex
1
and the modified cfg
. memberIndex
1
和修改后的cfg
调用rs.reconfigForPSASet()
方法。The memberIndex
is the array position of the new member in the members
array. memberIndex
是新成员在members
数组中的数组位置。Upon successful reconfiguration, the replica set configuration resembles the following:成功重新配置后,副本集配置如下所示:
{ "_id" : "rs0", "version" : 1, "term": 1, "members" : [ { "_id" : 0, "host" : "mongodb0.example.net:27017", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : {}, "secondaryDelaySecs" : Long("0"), "votes" : 1 }, { "_id" : 1, "host" : "mongodb2.example.net:27017", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 2, "tags" : {}, "secondaryDelaySecs" : Long("0"), "votes" : 1 }, { "_id" : 2, "host" : "mongodb2.example.net:27017", "arbiterOnly" : true, "buildIndexes" : true, "hidden" : false, "priority" : 0, "tags" : {}, "secondaryDelaySecs" : Long("0"), "votes" : 1 } ], "protocolVersion" : Long("1"), "writeConcernMajorityJournalDefault": true, "settings" : { "chainingAllowed" : true, "heartbeatIntervalMillis" : 2000, "heartbeatTimeoutSecs" : 10, "electionTimeoutMillis" : 10000, "catchUpTimeoutMillis" : 2000, "getLastErrorModes" : {}, "getLastErrorDefaults" : { "w" : 1, "wtimeout" : 0 }, "replicaSetId" : ObjectId("60e6f83923193faa336889d2") } }