정의
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.참고
제거된 샤드 샤딩된 클러스터 에 다시 추가하려면
storage.dbPath샤드를 다시 추가하기 전에 샤드 의 모든 노드에서 를 지워서 샤드의 파일을 제거 해야 합니다.
호환성
이 명령은 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
참고
이 명령은 MongoDB Atlas에서 지원되지 않습니다. Atlas 클러스터에 샤드를 추가하거나 제거 하려면 Modify your Atlas Sharded Atlas cluster 샤드 클러스터 수정)를 참조하세요.
구문
명령은 다음과 같은 구문을 가집니다:
db.adminCommand( { removeShard : <shardToRemove> } )
행동
샤드 제거 중 cluster 백업 없음
샤드 제거 중에는 cluster 데이터를 백업할 수 없습니다.
동시 removeShard 작업
You can have more than one removeShard operation in progress.
액세스 요구 사항
authorization 을(를) 활성화한 경우 clusterManager 역할 또는 removeShard 작업을 포함하는 역할이 있어야 합니다.
데이터베이스 마이그레이션 요구 사항
cluster의 각 데이터베이스에는 프라이머리 샤드가 있습니다. 제거하려는 샤드가 클러스터 데이터베이스 중 하나의 프라이머리 샤드이기도 한 경우, 샤드에서 모든 데이터를 마이그레이션한 후 데이터베이스를 수동으로 새 샤드로 이동해야 합니다. 자세한 내용은 movePrimary 명령 및 기존 샤드 cluster에서 샤드 제거 를 참조하세요.
청크 밸런싱
청크 분포가 균일하지 않은 클러스터에서 샤드를 제거하면 밸런서는 먼저 드레이닝 샤드에서 청크를 제거한 다음 나머지 불균등 청크 분포를 조정합니다.
쓰기 고려
mongos converts the write concern of the removeShard command to "majority".
변경 스트림
샤드 제거로 인해 열려 있던 변경 스트림 커서가 닫힐 수 있으며, 닫힌 변경 스트림 커서는 완전히 재개되지 않을 수 있습니다.
예시
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") } } }
밸런서는 bristol01 이라는 이름의 샤드의 청크를 cluster의 다른 샤드로 마이그레이션("배출")하기 시작합니다. 이러한 마이그레이션은 cluster에 과도한 부하를 주지 않기 위해 느리게 수행됩니다.
출력에는 bristol01 이 프라이머리 샤드 인 데이터베이스를 나타내는 dbsToMove 필드가 포함됩니다. 샤드에서 모든 청크를 제거한 후에는 데이터베이스에 대해 movePrimary 하거나 이러한 데이터베이스를 삭제해야 합니다.
참고
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") } } }
출력에서 remaining 필드에는 다음 필드가 포함됩니다.
필드 | 설명 |
|---|---|
| 현재 샤드에 남아 있는 청크의 총 개수입니다. |
| 프라이머리 샤드가 샤드인 데이터베이스의 총 개수입니다. 이러한 데이터베이스는 |
| 전체
|
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") } } }
샤드에서 모든 청크를 제거한 후 dbsToMove 이 있는 경우 해당 데이터베이스에 대해 movePrimary 을 수행하거나 데이터베이스를 삭제(관련 데이터 파일 삭제)할 수 있습니다.
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") } } }