jumbo
Flagjumbo
标志On this page本页内容
If MongoDB cannot split a chunk that exceeds the specified chunk size, MongoDB labels the chunk as jumbo.如果MongoDB无法分割超过指定块大小的块,MongoDB会将该块标记为jumbo
。
If the chunk size no longer exceeds the specified chunk size, MongoDB automatically clears the 如果块大小不再超过指定的块大小,MongoDB会在jumbo
flag for the chunk when the mongos
rewrites the chunk metadata.mongos
重写块元数据时自动清除块的jumbo
标志。
In cases where you need to clear the flag manually, however, the following procedures outline the steps to manually clear the 但是,在需要手动清除标志的情况下,以下过程概述了手动清除jumbo
flag.jumbo
标志的步骤。
The preferred manual way to clear the 从块中清除jumbo
flag from a chunk is to attempt to split the chunk. jumbo
标志的首选手动方法是尝试分割块。If the chunk is divisible, MongoDB removes the flag upon successful split of the chunk.如果块是可分割的,MongoDB会在成功分割块时删除该标志。
jumbo
Chunk.jumbo
块。Run 运行sh.status(true)
to find the chunk labeled jumbo
.sh.status(true)
以查找标记为jumbo
的块。
sh.status(true)
For example, the following output from sh.status(true) shows that chunk with shard key range 例如,{ "x" : 2 } -->> { "x" : 4 }
is jumbo
.sh.status(true)
的以下输出显示,具有分片键范围{ "x" : 2 } -->> { "x" : 4 }
的块是jumbo
。
--- Sharding Status --- sharding version: { ... } shards: ... databases: ... test.foo shard key: { "x" : 1 } chunks: shard-b 2 shard-a 2 { "x" : { "$minKey" : 1 } } -->> { "x" : 1 } on : shard-b Timestamp(2, 0) { "x" : 1 } -->> { "x" : 2 } on : shard-a Timestamp(3, 1) { "x" : 2 } -->> { "x" : 4 } on : shard-a Timestamp(2, 2) jumbo { "x" : 4 } -->> { "x" : { "$maxKey" : 1 } } on : shard-b Timestamp(3, 0)
jumbo
Chunk.jumbo
块。Use either 使用sh.splitAt()
or sh.splitFind()
to split the jumbo
chunk.sh.splitAt()
或sh.splitFind()
拆分jumbo
块。
sh.splitAt( "test.foo", { x: 3 })
MongoDB removes the MongoDB在成功分割块时删除jumbo
flag upon successful split of the chunk.jumbo
标志。
In some instances, MongoDB cannot split the no-longer 在某些情况下,MongoDB无法分割不再jumbo
chunk, such as a chunk with a range of single shard key value. jumbo
的块,例如具有单个分片键值范围的块。As such, you cannot split the chunk to clear the flag.因此,不能分割块来清除标志。
In such cases, you can either change the shard key so that the chunk can become divisible or manually clear the flag.在这种情况下,您可以更改分片键,使块可以被分割,也可以手动清除标志。
Starting in 4.4, MongoDB provides the 从4.4开始,MongoDB提供了refineCollectionShardKey
command. refineCollectionShardKey
命令。Using the 使用refineCollectionShardKey
command, you can refine a collection's shard key by adding a suffix field or fields to the existing key. refineCollectionShardKey
命令,可以通过向现有键添加一个或多个后缀字段来优化集合的分片键。By adding new field(s) to the shard key, indivisible jumbo chunks can become divisible.通过向分片键添加新字段,不可分割的巨型块可以被分割。
jumbo
Chunk.jumbo
块。Run 运行sh.status(true)
to find the chunk labeled jumbo
.sh.status(true)
以查找标记为jumbo
的块。
sh.status(true)
For example, the following output from 例如,sh.status(true)
shows that for the sharded collection test.orders
, both the chunk with shard key range { "status" : "A" } -->> { "status" : "D" }
and the chunk with range { "status" : "D" }-->> { "status" : "P" }
are jumbo
.sh.status(true)
的以下输出显示,对于分片集合test.orders
,具有分片键范围{ "status" : "A" } -->> { "status" : "D" }
的块和具有范围{ "status" : "D" }-->> { "status" : "P" }
的片都是jumbo
。
--- Sharding Status --- sharding version: { ... } shards: ... databases: ... test.orders shard key: { "status" : 1 } unique: false balancing: true chunks: shardA 2 shardB 2 { "status" : { "$minKey" : 1 } } -->> { "status" : "A" } on : shardB Timestamp(3, 0) { "status" : "A" } -->> { "status" : "D" } on : shardA Timestamp(5, 1) jumbo { "status" : "D" } -->> { "status" : "P" } on : shardA Timestamp(4, 2) jumbo { "status" : "P" } -->> { "status" : { "$maxKey" : 1 } } on : shardB Timestamp(5, 0)
test.orders
Collection.test.orders
集合的分片键。To address the low cardinality of the key 要解决键status
, refine the key for the test.orders
collection. status
的基数较低的问题,请优化test.orders
集合的键。For example, add the 例如,添加order_id
and customer_id
fields as a suffix to the current shard key; i.e. the shard key will be { status: 1, order_id: 1, customer_id: 1 }
after refinement.order_id
和customer_id
字段作为当前分片键的后缀;也就是说,经过优化后,分片键将是{ status: 1, order_id: 1, customer_id: 1 }
。
First, 首先,创建索引以支持分片键create the index
to support the shard key { status: 1, order_id: 1, customer_id: 1 }
if the index does not already exist.{ status: 1, order_id: 1, customer_id: 1 }
(如果该索引尚不存在)。
db.orders.createIndex( { status: 1, order_id: 1, customer_id: 1 } )
For additional index considerations for refining the shard key, see Index Considerations.有关优化分片键的其他索引注意事项,请参阅索引注意事项。
In the 在admin
database, run the refineCollectionShardKey
command to add the order_id
and customer_id
fields as a suffix to the existing key:admin
数据库中,运行refineCollectionShardKey
命令,将order_id
和customer_id
字段添加为现有密钥的后缀:
db.adminCommand( { refineCollectionShardKey: "test.orders", key: { status: 1, order_id: 1, customer_id: 1 } } )
The refineCollectionShardKey
command updates the chunk ranges and zone ranges to incorporate the new fields without modifying the range values of the existing key fields. refineCollectionShardKey
命令更新区块范围和区域范围,以合并新字段,而不修改现有关键字段的范围值。That is, the refinement of the shard key does not immediately affect the distribution of chunks across shards or zones. 也就是说,分片键的细化不会立即影响分片或区域中块的分布。Any future chunk splits or migration occur as part of the routine sharding operations.任何未来的区块分割或迁移都将作为常规分片操作的一部分进行。
After you refine the shard key, it may be that not all documents in the collection have the suffix field(s). 细化分片键后,可能不是集合中的所有文档都有后缀字段。To populate the missing shard key field(s), see Missing Shard Key Fields.要填充缺少的分片键字段,请参阅缺少分片键字段。
Before refining the shard key, ensure that all or most documents in the collection have the suffix fields, if possible, to avoid having to populate the field afterwards.在细化分片键之前,如果可能的话,请确保集合中的所有或大多数文档都有后缀字段,以避免事后填充字段。
jumbo
Flag for an Indivisible Chunkjumbo
标志You can manually clear the flag using the following steps.您可以使用以下步骤手动清除标志。
If you clear the 如果清除仍超过块大小的块的jumbo
flag for a chunk that still exceeds the chunk size, MongoDB will re-label the chunk as jumbo
when MongoDB tries to move the chunk.jumbo
标志,则当MongoDB尝试移动块时,MongoDB会将块重新标记为jumbo
。
Starting in version 4.2.3 (and 4.0.15), MongoDB provides the 从版本4.2.3(和4.0.15)开始,MongoDB提供clearJumboFlag
command to manually clear the jumbo
flag.clearJumboFlag
命令来手动清除jumbo
标志。
Only use this method if the preferred method is not applicable.仅在首选方法不适用时使用此方法。
jumbo
Chunk.jumbo
块。Run 运行sh.status(true)
to find the chunk labeled jumbo
.sh.status(true)
以查找标记为jumbo
的块。
sh.status(true)
For example, the following output from sh.status(true) shows that chunk with shard key range 例如,{ "x" : 2 } -->> { "x" : 3 }
is jumbo
.sh.status(true)
的以下输出显示,具有分片键范围{ "x" : 2 } -->> { "x" : 3 }
的块是jumbo
。
--- Sharding Status --- sharding version: { ... } shards: ... databases: ... test.foo shard key: { "x" : 1 } chunks: shard-b 2 shard-a 2 { "x" : { "$minKey" : 1 } } -->> { "x" : 1 } on : shard-b Timestamp(2, 0) { "x" : 1 } -->> { "x" : 2 } on : shard-a Timestamp(3, 1){ "x" : 2 } -->> { "x" : 3 } on : shard-a Timestamp(2, 2) jumbo { "x" : 3 } -->> { "x" : { "$maxKey" : 1 } } on : shard-b Timestamp(3, 0) 3
Run the运行clearJumboFlag
Command.clearJumboFlag
命令。
From the从admin
database, run theclearJumboFlag
, passing in the namespace of the sharded collection and either:admin
数据库中,运行clearJumboFlag
,传入分片集合的名称空间,然后执行以下操作之一:
the bounds of thejumbo
chunk:jumbo
块的边界:db.adminCommand( { clearJumboFlag: "test.foo", bounds: [{ "x" : 2 }, { "x" : 3 }] })
the find document with a shard key and value contained in the包含分片键和值的jumbo
chunk:find
文档包含在jumbo
块中:db.adminCommand( { clearJumboFlag: "test.foo", find: { "x" : 2 } })Note注意
If the collection uses a hashed shard key, do not use the如果集合使用散列分片键,请不要使用带有find
field withclearJumboFlag
.clearJumboFlag
的find
字段。For hashed shard keys, use the对于散列分片键,请改用bounds
field instead.bounds
字段。
For MongoDB 4.2.2 and earlier (and 4.0.14 and earlier), you must manually clear the对于MongoDB 4.2.2及更低版本(以及4.0.14及更低版本),必须使用以下过程手动清除jumbo
flag using the following procedure.jumbo
标志。Important重要
Only use this method if the preferred method is not applicable.仅在首选方法不适用时使用此方法。
Before modifying the config database, always back up the config database.在修改config
数据库之前,请始终备份config
数据库。1
Stop the balancer.停止平衡器。
Disable the cluster balancer process temporarily, following the steps outlined in Disable the Balancer.按照禁用平衡器中概述的步骤,暂时禁用群集平衡器进程。2
Create a backup of创建config
database.config
数据库的备份。
Use对配置服务器使用mongodump
against a config server to create a backup of theconfig
database.mongodump
来创建config
数据库的备份。For Example:例如mongodump --db=config --port=<config server port> --out=<output file>4
Find the找到jumbo
Chunk.jumbo
块。
Run运行sh.status(true)
to find the chunk labeledjumbo
.sh.status(true)
以查找标记为jumbo
的块。sh.status(true)
For example, the following output from sh.status(true) shows that chunk with shard key range例如,{ "x" : 2 } -->> { "x" : 3 }
isjumbo
.sh.status(true)
的以下输出显示,具有分片键范围{ "x" : 2 } -->> { "x" : 3 }
的块是jumbo
。--- Sharding Status --- sharding version: { ... } shards: ... databases: ... test.foo shard key: { "x" : 1 } chunks: shard-b 2 shard-a 2 { "x" : { "$minKey" : 1 } } -->> { "x" : 1 } on : shard-b Timestamp(2, 0) { "x" : 1 } -->> { "x" : 2 } on : shard-a Timestamp(3, 1){ "x" : 2 } -->> { "x" : 3 } on : shard-a Timestamp(2, 2) jumbo { "x" : 3 } -->> { "x" : { "$maxKey" : 1 } } on : shard-b Timestamp(3, 0) 56
Clear the cached routing information.清除缓存的路由信息。
After the jumbo flag has been cleared out from the从chunks
collection, update the cluster routing metadata cache.chunks
集合中清除jumbo
标志后,更新集群路由元数据缓存。
Starting in MongoDB 4.0.6 (and 3.6.11),从MongoDB 4.0.6(和3.6.11)开始,
You must flush the cache on the config server primary for the namespace.必须刷新名称空间配置服务器primary
上的缓存。This notifies the balancer of the jumbo flag clearance.这将通知平衡器巨型标志的清除。
Connect将mongosh
to the config server primary and runflushRouterConfig
for the collection:mongosh
连接到配置服务器primary
,并为集合运行flushRouterConfig
:db.adminCommand( { flushRouterConfig: "test.foo" } )In earlier versions (MongoDB 3.4-series, MongoDB 3.6.0-3.6.10, MongoDB 4.0.0-4.0.5),在早期版本中(MongoDB 3.4系列、MongoDB 3.6.0-3.6.10、MongoDB4.0.0-4.0.5),Step down the config server primary to clear the routing metadata cache from the config servers.逐步关闭配置服务器主服务器,以从配置服务器中清除路由元数据缓存。Tip提示See also:参阅: