moveChunk

On this page本页内容

Definition定义

moveChunk

Internal administrative command. Moves chunks between shards. 内部管理命令。在分片之间移动Issue the moveChunk command via a mongos instance while using the admin database. 使用admin数据库时,通过mongos实例发出moveChunk命令。Use the following forms:使用以下表格:

db.adminCommand( { moveChunk : <namespace> ,
                 find : <query> ,
                 to : <string>,
                 forceJumbo: <boolean>, // Starting in MongoDB 4.4
                 _secondaryThrottle : <boolean>,
                 writeConcern: <document>,
                 _waitForDelete : <boolean> } )

Alternatively:或者:

db.adminCommand( { moveChunk : <namespace> ,
                 bounds : <array> ,
                 to : <string>,
                 forceJumbo: <boolean>, // Starting in MongoDB 4.4
                 _secondaryThrottle : <boolean>,
                 writeConcern: <document>,
                 _waitForDelete : <boolean> } )

The moveChunk command has the following fields:moveChunk命令具有以下字段:

Field字段Type类型Description描述
moveChunkstringThe namespace of the collection where the chunk exists. 区块所在集合命名空间Specify the collection's full namespace, including the database name. 指定集合的完整命名空间,包括数据库名称。
finddocumentAn equality match on the shard key that specifies the shard-key value of the chunk to move. 分片键上的相等匹配,指定要移动的块的分片键值。Specify either the bounds field or the find field but not both. 指定bounds字段或find字段,但不能同时指定两者。Do not use the find field to select chunks in collections that use a hashed shard key. 不要使用find字段来选择集合中使用哈希分片键的块。
boundsarrayThe bounds of a specific chunk to move. 要移动的特定块的边界。The array must consist of two documents that specify the lower and upper shard key values of a chunk to move. 数组必须由两个文档组成,这些文档指定要移动的块的下分片键值和上分片键值。Specify either the bounds field or the find field but not both. 指定bounds字段或find字段,但不能同时指定两者。Use bounds to select chunks in collections that use a hashed shard key. 使用bounds选择集合中使用哈希分片键的块。
tostringThe name of the destination shard for the chunk.块的目标分片的名称。
forceJumboboolean

Optional. 可选。A flag that determines if the command can move a chunk that is too large to migrate. 一个标志,用于确定命令是否可以移动太大而无法迁移的块。The chunk may or may not be labeled as jumbo.块可以被标记为也可以不被标记为jumbo

  • If true, the command can move the chunk.如果为true,则命令可以移动块。
  • If false, the command cannot move the chunk.如果为false,则命令无法移动块。

The default is false.默认值为false

Warning警告

When you run moveChunk with forceJumbo: true, write operations to the collection may block for a long period of time during the migration. 当您使用forceJumbo: true运行moveChunk时,对集合的写入操作可能会在迁移期间阻塞很长一段时间。To migrate these large chunks without this long blocking period, see Balance Chunks that Exceed Size Limit instead.要迁移这些大块而不需要这么长的阻塞期,请参阅超出大小限制的平衡块

New in version 4.4.在版本4.4中新增

_secondaryThrottleboolean

Optional. 可选。Starting in MongoDB 3.4, for WiredTiger, defaults to false.从MongoDB 3.4开始,WiredTiger默认为false

  • If true, then by default, each document move during chunk migration propagates to at least one secondary before the balancer proceeds with the next document. 如果为true,则默认情况下,块迁移期间的每个文档移动都会在平衡器继续下一个文档之前传播到至少一个辅助文档。This is equivalent to a write concern of { w: 2 }.这相当于{ w: 2 }的写入关注。

    Use the writeConcern option to specify a different write concern.使用writeConcern选项指定不同的写入关注点。

  • If false, the balancer does not wait for replication to a secondary and instead continues with the next document.如果为false,则平衡器不会等待复制到辅助文档,而是继续下一个文档。

For more information, see Secondary Throttle.有关详细信息,请参阅辅助节流阀

writeConcerndocument

Optional. 可选。A document that expresses the write concern that the _secondaryThrottle will use to wait for secondaries during the chunk migration.表示在块迁移期间_secondaryThrottle将用于等待辅助设备的写入关注的文档。

writeConcern requires _secondaryThrottle: true.需要_secondaryThrottle: true

_waitForDeletebooleanOptional. 可选。Internal option for testing purposes. 用于测试的内部选项。The default is false. 默认值为falseIf set to true, the delete phase of a moveChunk operation blocks. 如果设置为truemoveChunk操作的删除阶段将停止。

The value of bounds takes the form:bounds值的形式为:

[ { hashedField : <minValue> } ,
  { hashedField : <maxValue> } ]

The chunk migration section describes how chunks move between shards on MongoDB.块迁移部分描述了块如何在MongoDB上的分片之间移动。

Tip提示
See also: 参阅:

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. 仅在特殊情况下使用moveChunk,例如准备分片化集群以进行初始数据摄取或大规模导入操作。In most cases allow the balancer to create and balance chunks in sharded clusters. 在大多数情况下,允许平衡器在分片集群中创建和平衡块。See Create Chunks in a Sharded Cluster for more information.有关详细信息,请参阅在分片集群中创建块

Behavior行为

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.要求在迁移之前目标(即to)分片上存在所有索引,如果不存在所需索引,则返回错误。

Meta Data Error元数据错误

moveChunk returns the following error message if another metadata operation is in progress on the chunks collection:如果chunks集合上正在进行另一个元数据操作,moveChunk将返回以下错误消息:

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. 如果另一个进程(如平衡器进程)在moveChunk运行时更改元数据,则可能会看到此错误。You may retry the moveChunk operation without side effects.您可以在没有副作用的情况下重试moveChunk操作。

maxCatchUpPercentageBeforeBlockingWrites Server Parameter服务器参数

Starting in MongoDB 5.0 (and 4.4.7, 4.2.15, 4.0.26), 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.从MongoDB 5.0(和4.4.7、4.2.15、4.0.26)开始,您可以设置maxCatchUpPercentageBeforeBlockingWrites,以指定在moveChunk操作期间未迁移的数据的最大允许百分比,与正在传输的区块的总大小(以MB为单位)相比较。

←  medianKeymovePrimary →