定義
moveChunkInternal administrative command. Moves chunks between shards. Issue the
moveChunkcommand via amongosinstance while using the admin database. Use the following forms:Tip
In
mongosh, this command can also be run through thesh.moveChunk()helper method.Helper methods are convenient for
mongoshusers, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.db.adminCommand( { moveChunk : <namespace> , find : <query> , to : <ID of the recipient shard>, forceJumbo: <boolean>, _secondaryThrottle : <boolean>, writeConcern: <document>, _waitForDelete : <boolean> } ) あるいは、
db.adminCommand( { moveChunk : <namespace> , bounds : <array> , to : <ID of the recipient shard>, forceJumbo: <boolean>, _secondaryThrottle : <boolean>, writeConcern: <document>, _waitForDelete : <boolean> } ) 注意
listShards受信者シャードのIDを取得するには、 コマンドを使用します。The
moveChunkcommand has the following fields:フィールドタイプ説明moveChunkstring
findドキュメント
移動するチャンクのシャードキー値を指定する、シャードキーの等価一致。
boundsフィールドとfindフィールドのいずれかを指定しますが、両方は指定しないでください。findハッシュされたシャードキー を使用するコレクション内のチャンクを選択するために、 フィールドを使用し ない でください。bounds配列
移動する特定のチャンクの境界。 配列は、移動するチャンクのシャードキーの下限と上限のシャードキー値を指定する 2 つのドキュメントで構成されている必要があります。
boundsフィールドとfindフィールドのいずれかを指定しますが、両方は指定しないでください。 ハッシュされたシャードキーを使用するコレクション内のチャンクを選択するには、boundsを使用します。tostring
チャンクの受信者シャードのID 。
ブール値
任意。 コマンドが 移行するには大きすぎるチャンクを移動できるかどうかを決定するフラグです。 そのチャンクにはジャンボ というラベルが付いている場合と付いていない場合があります。
trueの場合、コマンドはチャンクを移動できます。falseの場合、コマンドはチャンクを移動できません。
デフォルトは
falseです。警告:
forceJumbo=trueとmoveChunkコマンドは、コレクションに対する書込み操作をブロックします。このオプションを指定すると、シャードは、設定された チャンク サイズ よりも大きい場合でも、チャンクを移行します。 コレクションは、 移行中は書き込みができなくなります。
この長いブロッキング期間なしでこれらの大きなチャンクを移行するには、代わりに「サイズ制限を超えるバランス範囲」を参照してください。
_secondaryThrottleブール値
任意。 WiredTigerの場合、 はデフォルトで
falseになります。trueの場合、デフォルトでは、チャンクの移行中に移動された各ドキュメントは、バランサーが次のドキュメントに進む前に少なくとも 1 つのセカンダリに伝播します。 これは{ w: 2 }の書込み保証 (write concern) と同等です。別の書込み保証 (write concern) を指定するには、
writeConcernオプションを使用します。falseの場合、バランサーはセカンダリへのレプリケーションを待たずに次のドキュメントに進みます。
詳細については、「セカンダリ スロットル 」を参照してください。
writeConcernドキュメント
任意。 チャンクの移行中に
_secondaryThrottleがセカンダリを待機するために使用する 書込み保証 ( write concern ) を表すドキュメント。writeConcernには_secondaryThrottle: trueが必要です。_waitForDeleteブール値
Optional. If set to
true, the delete phase of amoveChunkoperation is blocking._waitForDeletedefaults tofalse._waitForDeleteフィールドがtrueに設定されている場合、 MongoDB は範囲削除を実行する前にorphanCleanupDelaySecs遅延を待たなくなります。_waitForDeleteパラメーターを使用しており、セカンダリで読み取り操作が発生している場合、移行の削除するフェーズによって読み取りが終了する可能性があります。詳しくはterminateSecondaryReadsOnOrphanCleanupを参照してください。boundsの値は次の形式をとります。[ { hashedField : <minValue> } , { hashedField : <maxValue> } ] 「チャンク移行」セクションでは、MongoDB 上のシャード間でチャンクがどのように移動されるかについて説明します。
互換性
このコマンドは、次の環境でホストされている配置で使用できます。
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
Considerations
Only use the moveChunk in special circumstances such as preparing your sharded cluster for an initial ingestion of data, or a large bulk import operation. In most cases allow the balancer to create and balance chunks in sharded clusters. See Create Ranges in a Sharded Cluster for more information.
動作
Indexes
moveChunk requires that all indexes exist on the target (i.e. to ) shard before migration and returns an error if a required index does not exist.
Meta Data Error
moveChunk returns the following error message if another metadata operation is in progress on the chunks collection:
errmsg: "The collection's metadata lock is already taken."
If another process, such as a balancer process, changes meta data while moveChunk is running, you may see this error. You may retry the moveChunk operation without side effects.
maxCatchUpPercentageBeforeBlockingWrites Server Parameter
Starting in MongoDB 5.0, you can set the maxCatchUpPercentageBeforeBlockingWrites to specify the maximum allowed percentage of data not yet migrated during a moveChunk operation when compared to the total size (in MBs) of the chunk being transferred.