Para agentes de IA: um índice de documentação está disponível em https://www.mongodb.com/pt-br/docs/llms.txt — as versões de markdown de todas as páginas estão disponíveis anexando .md a qualquer caminho de URL.
Menu Docs

rs.reconfigForPSASet() (método mongosh)

rs.reconfigForPSASet( memberIndex, config, { options } )

Novidade na versão 5.0.

Execute com segurança algumas alterações de reconfiguração em um conjunto de réplicas primário-secundário-árbitro (PSA) ou em um conjunto de réplicas que está mudando para uma arquitetura PSA. Você só deve usar esse método em um dos seguintes casos:

Para obter detalhes sobre o comportamento desse método, consulte Comportamento.

Esse método está disponível em implantações hospedadas nos seguintes ambientes:

  • MongoDB Enterprise: a versão autogerenciada e baseada em assinatura do MongoDB

  • MongoDB Community: uma versão com código disponível, de uso gratuito e autogerenciada do MongoDB

The rs.reconfigForPSASet() method has the following syntax:

rs.reconfigForPSASet(
memberIndex: <num>,
config: <configuration>,
{
"force" : <boolean>,
"maxTimeMS" : <int>
}
)
Parâmetro
Tipo
Descrição

memberIndex

inteiro

O índice do secundário que está sendo adicionado ou modificado.

config

documento

Um documento que especifica a nova configuração de um conjunto de réplicas.

force

booleano

Opcional

WARNING: Running the rs.reconfigForPSASet() method with force: true is not recommended and can lead to committed writes being rolled back.

Especifique true para forçar os membros do conjunto de réplica disponíveis a aceitar a nova configuração. O padrão é false.

A reconfiguração forçada pode resultar em comportamento inesperado ou indesejado, incluindo a reversão de "majority" gravações confirmadas.

maxTimeMS

inteiro

Opcional

Specifies a cumulative time limit in milliseconds for processing each reconfiguration during the rs.reconfigForPSASet() operation. By default, rs.reconfigForPSASet() waits indefinitely for the replica configurations to propagate to a majority of replica set members.

The rs.reconfigForPSASet() method reconfigures your replica set in two steps:

  1. O método reconfigura seu conjunto de réplicas para adicionar ou modificar um secundário com { votes: 1, priority: 0 } .

  2. Once the added or modified secondary has caught up with all committed writes, the method reconfigures the secondary to have the priority specified in the rs.reconfigForPSASet() command ({ votes: 1, priority: <num> }).

A abordagem de duas etapas evita a possibilidade de reverter gravações confirmadas no caso de um failover para o novo secundário antes que o novo secundário tenha todas as gravações confirmadas da configuração anterior.

Um conjunto de réplica denominado rs0 tem a seguinte configuração:

{
"_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.

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);
  1. A primeira declaração usa o método rs.conf() para recuperar um documento que contém a configuração atual do conjunto de réplicas e armazena o documento na variável local cfg.

  2. A segunda declaração adiciona o novo secundário à array members. Nessa configuração, o novo secundário é adicionado em memberIndex 1. O memberIndex é o mesmo que o índice da array. Para obter configurações adicionais, consulte as configurações do conjunto de réplicas.

  3. The last statement calls the rs.reconfigForPSASet() method with the memberIndex 1 and the modified cfg. The memberIndex is the array position of the new member in the members array. 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")
    }
    }