Definição
removeShardRemoves a shard from a sharded cluster. When you run
removeShard, MongoDB drains the shard by using the balancer to move the shard's chunks to other shards in the cluster. Once the shard is drained, MongoDB removes the shard from the cluster.Observação
Se quiser adicionar novamente um fragmento removido ao cluster fragmentado, você deverá limpar o
storage.dbPathde todos os nós do fragmento para remover os arquivos do fragmento antes de poder adicioná-lo novamente.
Compatibilidade
Esse comando 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
Observação
Este comando não é suportado no MongoDB Atlas. Consulte Modificar seu Atlas Cluster Sharded para adicionar ou remover shards do seu Atlas cluster.
Sintaxe
O comando tem a seguinte sintaxe:
db.adminCommand( { removeShard : <shardToRemove> } )
Comportamento
Nenhum backup de cluster durante a remoção de fragmentos
Você não pode fazer backup dos dados do cluster durante a remoção de fragmentos.
Operações removeShard simultâneas
You can have more than one removeShard operation in progress.
Requisitos de acesso
Se você tiver authorization habilitado, deverá ter a função clusterManager ou qualquer função que inclua a ação removeShard .
Requisitos de migração de reconhecimento de data center
Cada reconhecimento de data center em um cluster fragmentado tem um fragmento primário. Se o fragmento que você deseja remover também for o primário de um dos reconhecimento de data center do cluster, você deverá mover manualmente os reconhecimento de data center para um novo fragmento após migrar todos os dados do fragmento. Consulte o comando movePrimary e a seção Remover Fragmentos de um Cluster Fragmentado Existente para obter mais informações.
Balanceamento de partes
Quando você remove um fragmento em um cluster com uma distribuição desigual de fragmentos, o balanceador primeiro remove os fragmentos do fragmento de drenagem e, em seguida, equilibra a distribuição desigual de fragmentos restante.
Escreva preocupação
mongos converts the write concern of the removeShard command to "majority".
Fluxos de alterações
Uma remoção de fragmento pode fazer com que um cursor de fluxo de alteração aberto feche e o cursor de fluxo de alteração fechado pode não ser totalmente retomável.
Exemplo
From mongosh, the removeShard operation resembles the following:
db.adminCommand( { removeShard : "bristol01" } )
Replace bristol01 with the name of the shard to remove. When you run removeShard, the command returns with a message that resembles the following:
{ "msg" : "draining started successfully", "state" : "started", "shard" : "bristol01", "note" : "you need to drop or movePrimary these databases", "dbsToMove" : [ "fizz", "buzz" ], "ok" : 1, "operationTime" : Timestamp(1575398919, 2), "$clusterTime" : { "clusterTime" : Timestamp(1575398919, 2), "signature" : { "hash" : BinData(0,"Oi68poWCFCA7b9kyhIcg+TzaGiA="), "keyId" : Long("6766255701040824328") } } }
O balanceador começa a migrar ("drenar") blocos do fragmento denominado bristol01 para outros fragmentos no cluster. Essas migrações acontecem lentamente para evitar a colocação de carga inadequada no cluster.
A saída inclui o campo dbsToMove indicando o reconhecimento de data center para os quais bristol01 é o fragmento primário. Depois que todos os chunks tiverem sido drenados do fragmento, você deverá movePrimary para o(s) banco(s) de dados ou, alternativamente, drop esses bancos de dados.
Observação
If the shard you are removing is not the primary shard for any database, the dbsToMove array will be empty and removeShard can complete the migration without intervention.
If you run the command again, removeShard returns the current status of the process. For example, if the operation is in an ongoing state, the command returns an output that resembles the following:
{ "msg" : "draining ongoing", "state" : "ongoing", "remaining" : { "chunks" : Long(2), "dbs" : Long(2), "jumboChunks" : Long(0) }, "note" : "you need to drop or movePrimary these databases", "dbsToMove" : [ "fizz", "buzz" ], "ok" : 1, "operationTime" : Timestamp(1575399086, 1655), "$clusterTime" : { "clusterTime" : Timestamp(1575399086, 1655), "signature" : { "hash" : BinData(0,"XBrTmjMMe82fUtVLRm13GBVtRE8="), "keyId" : Long("6766255701040824328") } } }
Na saída, o campo remaining inclui os seguintes campos:
Campo | Descrição |
|---|---|
| Número total de chunks restantes atualmente no shard. |
| Número total de bancos de dados cujo shard primário é o shard. Estes bancos de dados são especificados no campo de saída |
| Do número total de Se o Depois que a sinalização |
Continue checking the status of the removeShard command (i.e. rerun the command) until the number of chunks remaining is 0.
{ "msg" : "draining ongoing", "state" : "ongoing", "remaining" : { "chunks" : Long(0), // All chunks have moved "dbs" : Long(2), "jumboChunks" : Long(0) }, "note" : "you need to drop or movePrimary these databases", "dbsToMove" : [ "fizz", "buzz" ], "ok" : 1, "operationTime" : Timestamp(1575400343, 1), "$clusterTime" : { "clusterTime" : Timestamp(1575400343, 1), "signature" : { "hash" : BinData(0,"9plu5B/hw4uWAgEmjjBP3syw1Zk="), "keyId" : Long("6766255701040824328") } } }
Depois que todas as partes tiverem sido drenadas do fragmento, se você tiver dbsToMove, você poderá movePrimary para esses reconhecimento de data center ou, alternativamente, drop os reconhecimento de data center (o que exclui os Data Federation associados).
After the balancer completes moving all chunks off the shard and you have handled the dbsToMove, removeShard can finish. Running removeShard again returns output that resembles the following:
{ "msg" : "removeshard completed successfully", "state" : "completed", "shard" : "bristol01", "ok" : 1, "operationTime" : Timestamp(1575400370, 2), "$clusterTime" : { "clusterTime" : Timestamp(1575400370, 2), "signature" : { "hash" : BinData(0,"JjSRciHECXDBXo0e5nJv9mdRG8M="), "keyId" : Long("6766255701040824328") } } }