rs.reconfigForPSASet()
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:您只能在以下情况之一中使用此方法: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您希望在具有PSA体系结构的现有三成员复制集中重新配置辅助节点,使其成为具有非零priority
.priority
的投票、数据承载节点。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 voting, data-bearing node and one arbiter.您希望向包含一个投票、数据承载节点和一个仲裁器的现有两成员副本集添加一个具有非零优先级的新投票、数据携带节点。
WarningIf 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.有关此方法行为的详细信息,请参阅行为。
Syntax语法
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 | Warning rs.reconfigForPSASet() method with force: true is not recommended and can lead to committed writes being rolled back. force:true 运行rs.reconfigForPSASet() 方法,这可能会导致提交的写入被回滚。true to force the available replica set members to accept the new configuration. true 可强制可用副本集成员接受新配置。false .false 。"majority" committed writes. "majority" 提交的写入。 |
maxTimeMS | integer | rs.reconfigForPSASet() operation. rs.reconfigForPSASet() 操作期间处理每次重新配置的累积时间限制(以毫秒为单位)。rs.reconfigForPSASet() waits indefinitely for the replica configurations to propagate to a majority of replica set members. rs.reconfigForPSASet() 无限期地等待复制副本配置传播到大多数复制副本集成员。 |
Behavior行为
The rs.reconfigForPSASet()
method reconfigures your replica set in two steps:rs.reconfigForPSASet()
方法分两步重新配置复制副本集:
The method reconfigures your replica set to add or modify a secondary with该方法重新配置复制副本集以添加或修改具有{ votes: 1, priority: 0 }
.{ votes: 1, priority: 0 }
的辅助。Once the added or modified secondary has caught up with all committed writes, the method reconfigures the secondary to have the一旦添加或修改的辅助设备赶上了所有提交的写入,该方法就会将辅助设备重新配置为具有priority
specified in thers.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.两步方法避免了在故障转移到新辅助设备的情况下,在新辅助设备从以前的配置中完成所有提交的写入之前,将提交的写入回滚到该辅助设备的可能性。
Example实例
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" : "mongodb1.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" : "mongodb1.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);
The first statement uses the第一条语句使用rs.conf()
method to retrieve a document containing the current configuration for the replica set and stores the document in the local variablecfg
.rs.conf()
方法检索包含副本集当前配置的文档,并将该文档存储在本地变量cfg
中。The second statement adds the new secondary to the第二条语句将新的辅助项添加到members
array.members
数组中。In this configuration the new secondary is added at在此配置中,新的辅助项添加在memberIndex
1
.memberIndex
1
处。ThememberIndex
is the same as the array index.memberIndex
与数组索引相同。For additional settings, see replica set configuration settings.有关其他设置,请参阅复制副本集配置设置。The last statement calls the最后一条语句使用rs.reconfigForPSASet()
method with thememberIndex
1
and the modifiedcfg
.memberIndex
1
和修改后的cfg
调用rs.reconfigForPSASet()
方法。ThememberIndex
is the array position of the new member in themembers
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" : "mongodb1.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")
}
}