Definition定义
moveChunkInternal administrative command. Moves chunks between shards.内部行政指挥。在分片之间移动块。Issue the在使用moveChunkcommand via amongosinstance while using the admin database. Use the following forms:admin数据库时,通过mongos实例发出moveChunk命令。使用以下表格:Tip
In在mongosh, this command can also be run through thesh.moveChunk()helper method.mongosh中,此命令也可以通过sh.moveChunk()辅助方法运行。Helper methods are convenient for助手方法对mongoshusers, but they may not return the same level of information as database commands.mongosh用户来说很方便,但它们可能不会返回与数据库命令相同级别的信息。In cases where the convenience is not needed or the additional return fields are required, use the database command.如果不需要便利性或需要额外的返回字段,请使用database命令。db.adminCommand( { moveChunk : <namespace> ,
find : <query> ,
to : <ID of the recipient shard>,
forceJumbo: <boolean>,
_secondaryThrottle : <boolean>,
writeConcern: <document>,
_waitForDelete : <boolean> } )Alternatively:或者:db.adminCommand( { moveChunk : <namespace> ,
bounds : <array> ,
to : <ID of the recipient shard>,
forceJumbo: <boolean>,
_secondaryThrottle : <boolean>,
writeConcern: <document>,
_waitForDelete : <boolean> } )Note
Use the使用listShardscommand to retrieve the ID of the recipient shard.listShards命令检索收件人分片的ID。ThemoveChunkcommand has the following fields:moveChunk命令有以下字段:Field字段Type类型Description描述moveChunkstring字符串The namespace of the collection where the chunk exists. Specify the collection's full namespace, including the database name.块所在集合的命名空间。指定集合的完整命名空间,包括数据库名称。finddocument文档An equality match on the shard key that specifies the shard-key value of the chunk to move. Specify either the分片键上的相等匹配,指定要移动的块的分片键值。指定boundsfield or thefindfield but not both.bounds字段或find字段,但不能同时指定两者。Do not use the不要使用findfield to select chunks in collections that use a hashed shard key.find字段来选择使用哈希分片键的集合中的块。boundsarray数组The 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指定boundsfield or thefindfield but not both. Useboundsto select chunks in collections that use a hashed shard key.bounds字段或find字段,但不能同时指定两者。使用bounds在使用哈希分片键的集合中选择块。tostring字符串The ID of the recipient shard for the chunk.块的接收方分片的ID。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.一个标志,用于确定命令是否可以移动太大而无法迁移的块。该块可能被标记为巨型,也可能没有。If如果为true, the command can move the chunk.true,则该命令可以移动块。If如果为false, the command cannot move the chunk.false,则该命令无法移动块。
The default is默认值为false.false。WARNING:警告:The带有moveChunkcommand withforceJumbo=trueblocks write operations on the collection.forceJumbo=true的moveChunk命令阻止对集合的写入操作。This option causes the shard to migrate chunks even when they are larger than the configured chunk size. The collection remains unavailable for writes for the duration of the migration.此选项会导致分片迁移块,即使它们大于配置的块大小。在迁移期间,该集合仍不可用于写入。To migrate these large chunks without this long blocking period, see Balance Ranges that Exceed Size Limit instead.要迁移这些大块而不需要这么长的阻塞期,请参阅超过大小限制的平衡范围。_secondaryThrottleboolean布尔值Optional.可选。For WiredTiger, defaults to对于WiredTiger,默认值为false.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使用writeConcernoption 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一个文档,表示_secondaryThrottlewill use to wait for secondaries during the chunk migration._sesecondaryThrottle在块迁移期间将用于等待二级的写入关注。writeConcernrequires_secondaryThrottle: true._waitForDeleteboolean布尔值Optional.可选。If set to如果设置为true, the delete phase of amoveChunkoperation is blocking.true,则moveChunk操作的删除阶段将被阻塞。_waitForDeletedefaults to默认为false.false。When the当设置_waitForDeletefield is set, MongoDB does not wait on theorphanCleanupDelaySecsdelay before performing the range deletion._waitForDelete字段时,MongoDB在执行范围删除之前不会等待orphanCleanupDelaySecs延迟。If you use the如果使用_waitForDeleteparameter and have any read operations occurring on secondaries, the read might terminate due to the migration's delete phase._waitForDelete参数并在次服务器上进行任何读取操作,则读取可能会因迁移的删除阶段而终止。To learn more, see要了解更多信息,请参阅terminateSecondaryReadsOnOrphanCleanup.terminateSecondaryReadsOnOrphanCleanup。The value ofboundstakes the form:bounds值的形式如下:[ { hashedField : <minValue> } ,
{ hashedField : <maxValue> } ]The chunk migration section describes how chunks move between shards on MongoDB.块迁移部分描述了块如何在MongoDB上的分片之间移动。
Compatibility兼容性
This command is available in deployments hosted in the following environments:此命令在以下环境中托管的部署中可用:
- MongoDB Atlas
: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
- MongoDB Enterprise
: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本 - MongoDB Community
: The source-available, free-to-use, and self-managed version of MongoDB: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.moveChunk,例如为初始数据摄取或大批量导入操作准备分片集群。在大多数情况下,允许平衡器在分片集群中创建和平衡块。有关详细信息,请参阅在分片群集中创建范围。
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集合上正在进行另一个元数据操作,则返回以下错误消息:
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.moveChunk运行时更改元数据,您可能会看到此错误。您可以在没有副作用的情况下重试moveChunk操作。
maxCatchUpPercentageBeforeBlockingWrites Server Parameter服务器参数
Starting in MongoDB 5.0, you can set the 从MongoDB 5.0开始,您可以设置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.maxCatchUpPercentageBeforeBlockingWrites,以指定与正在传输的块的总大小(以MB为单位)相比,在moveChunk操作期间尚未迁移的数据的最大允许百分比。