If MongoDB cannot split a chunk that exceeds the specified range size, MongoDB labels the chunk as jumbo.如果MongoDB无法分割超过指定范围大小的块,MongoDB会将该块标记为jumbo。
The following procedures outline the steps to manually clear the 以下过程概述了手动清除jumbo flag.jumbo标志的步骤。
Procedures过程
Divisible Chunks可分割块
The preferred manual way to clear the 从块中清除jumbo flag from a chunk is to attempt to split the chunk. If the chunk is divisible, MongoDB removes the flag upon successful split of the chunk.jumbo标志的首选手动方法是尝试分割块。如果块是可分割的,MongoDB会在成功分割块时删除标记。
Find the jumbo Chunk.找到jumbo块。
jumbo Chunk.Run 运行sh.status(true) to find the chunk labeled jumbo.sh.status(true)(true)以查找标记为jubo的块。
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)
3
Split the jumbo Chunk.将jumbo块拆开。
Use either sh.splitAt() or sh.splitFind() to split the jumbo chunk.使用sh.splitAt()或sh.splitFind()分割巨型块。
sh.splitAt( "test.foo", { x: 3 })
MongoDB removes the jumbo flag upon successful split of the chunk.MongoDB在成功分割块时删除了jumbo标志。
Indivisible Chunks不可分割的块
In some instances, MongoDB cannot split the no-longer jumbo chunk, such as a chunk with a range of single shard key value. As such, you cannot split the chunk to clear the flag.在某些情况下,MongoDB无法分割不再是jumbo的块,例如具有单个分片键值范围的块。因此,您无法分割块以清除标记。
In such cases, you can either change the shard key so that the chunk can become divisible or manually clear the flag.在这种情况下,您可以更改分片键,使块可以被分割,也可以手动清除标记。
Refine the Shard Key优化分片键
MongoDB provides the refineCollectionShardKey command. MongoDB提供了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.通过在分片键中添加新字段,不可分割的巨型块可以被分割。
2
Find the 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)
3
Refine the Shard Key for 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.也就是说,分片键的细化不会立即影响块在分片或区域之间的分布。任何未来的块分割或迁移都是常规分片操作的一部分。
Tip
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.在细化分片键之前,如果可能的话,确保集合中的所有或大多数文档都有后缀字段,以避免以后填充字段。
Manually Clear the jumbo Flag for an Indivisible Chunk手动清除不可分割块的jumbo标志
To manually clear the jumbo flag, you can use the clearJumboFlag command. 要手动清除jumbo标志,可以使用clearJumboFlag命令。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。
Important
Only use this method if the preferred method is not applicable.仅当首选方法不适用时才使用此方法。
To manually clear the flag, use the following steps:要手动清除标记,请使用以下步骤:
2
Find the 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.例如,shstatus(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 the clearJumboFlag, passing in the namespace of the sharded collection and either:从admin数据库中,运行clearJumboFlag,传入分片集合的命名空间,然后执行以下操作之一:
the bounds of the jumbo 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 with clearJumboFlag. 如果集合使用哈希分片键,请不要将find字段与clearJumboFlag一起使用。For hashed shard keys, use the bounds field instead.对于哈希分片键,请使用bounds字段。