Docs 菜单

Docs 主页开发应用程序MongoDB Manual

清除 jumbo标记

在此页面上

  • 步骤

如果 MongoDB 无法分割超过指定大小范围的数据块,则 MongoDB 会将该数据块标记为jumbo。

以下过程概述了手动清除jumbo标志的步骤。

清除数据块中jumbo标志的首选手动方法是尝试分割数据块。如果数据块可分,则 MongoDB 会在成功分割数据块后删除该标志。

1

mongosh连接到mongos

2

运行sh.status(true)以查找标记为jumbo的数据段。

sh.status(true)

例如,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

使用sh.splitAt()sh.splitFind()分割jumbo数据段。

sh.splitAt( "test.foo", { x: 3 })

成功分割数据块后,MongoDB 会删除jumbo标志。

在某些情况下,MongoDB 无法分割不再是jumbo的数据段,例如具有一系列单个分片键值的数据段。 因此,您无法分割数据段以清除标志。

在这种情况下,您可以更改分片键以使数据块可以整除,也可以手动清除该标志。

MongoDB 提供了refineCollectionShardKey命令。使用refineCollectionShardKey命令,您可以通过向现有键添加一个或多个后缀字段来优化collection的分片键。通过向分片键添加新字段,不可分割的巨型块可以变为可分割的。

1

mongosh连接到mongos

2

运行sh.status(true)以查找标记为jumbo的数据段。

sh.status(true)

例如, sh.status(true)的以下输出显示,对于分片collectiontest.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

要解决键status关联基数低的问题,请优化test.orders集合的键。 例如,将order_idcustomer_id字段作为后缀添加到当前分片键中;即优化后分片键将为{ status: 1, order_id: 1, customer_id: 1 }

  1. 首先,如果索引尚不存在,则create the index支持分片键{ status: 1, order_id: 1, customer_id: 1 }

    db.orders.createIndex( { status: 1, order_id: 1, customer_id: 1 } )

    有关优化分片键的其他索引注意事项,请参阅索引注意事项。

  2. admin数据库中,运行refineCollectionShardKey命令以将order_idcustomer_id字段作为后缀添加到现有密钥:

    db.adminCommand( {
    refineCollectionShardKey: "test.orders",
    key: { status: 1, order_id: 1, customer_id: 1 }
    } )

refineCollectionShardKey命令会更新数据块范围区域范围以包含新字段,而无需修改现有键字段的范围值。也就是说,分片键的细化不会立即影响跨分片或区域的数据块分布。任何未来的数据块分割或迁移都会作为常规分片操作的一部分发生。

提示

优化分片键后,可能并非集合中的所有文档都具有后缀字段。要填充缺失的分片键字段,请参阅缺失的分片键字段。

在优化分片键之前,如果可能,请确保集合中的所有或大多数文档都具有后缀字段,以避免事后必须填充该字段。

要手动清除jumbo标志,可以使用clearJumboFlag命令。如果清除仍然超过数据段大小的数据段的jumbo标志,则当 MongoDB 尝试移动该数据段时,MongoDB 会将该数据段重新标记为jumbo

重要

仅当首选方法适用时才使用此方法。

要手动清除该标志,请执行以下步骤:

1

mongosh连接到mongos

2

运行sh.status(true)以查找标记为jumbo的数据段。

sh.status(true)

例如,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

admin数据库运行clearJumboFlag ,传入分片collection的命名空间和以下任一项:

  • jumbo数据块的边界

    db.adminCommand( {
    clearJumboFlag: "test.foo",
    bounds: [{ "x" : 2 }, { "x" : 3 }]
    })
  • 查找文档,其分片键和值包含在jumbo数据块中:

    db.adminCommand( {
    clearJumboFlag: "test.foo",
    find: { "x" : 2 }
    })

    注意

    如果collection使用哈希分片键,请勿将字段与find clearJumboFlag一起使用。对于哈希分片键,请改用bounds字段。

提示

另请参阅:

← 从现有分片集群删除分片

在此页面上