DBAtlas · 数据库运维图谱

查找 jumbo chunk、拆分并清除标记

MongoDB分片

命令

// Chunks flagged as jumbo (5.0+ config.chunks links to the collection by uuid):
const uuid = db.getSiblingDB("config").collections.findOne({ _id: "shop.musteri" }).uuid;
db.getSiblingDB("config").chunks.find({ uuid: uuid, jumbo: true }, { min: 1, max: 1, shard: 1 })
// If the chunk can be split, split it at the median:
sh.splitFind("shop.musteri", { musteriId: 1000 })
// Last resort for an indivisible chunk, clear the flag manually (a successful split already clears it):
db.adminCommand({ clearJumboFlag: "shop.musteri", find: { musteriId: 1000 } })
// If a single key value is too large, refine the key (4.4+):
db.adminCommand({ refineCollectionShardKey: "shop.musteri", key: { musteriId: 1, siparisId: 1 } })

作用

列出因 balancer 无法移动而被标记为 jumbo 的 chunk,拆分可拆分的 chunk 并清除 jumbo 标记;说明如何为巨大的单值 chunk 细化分片键。

适用场景

某个分片明显大于其他分片、sh.status() 输出中出现 jumbo,或 balancer 报告迁移错误时。

注意

所有文档共享相同分片键值的 chunk 无法拆分;唯一持久的解决办法是用 refineCollectionShardKey 或 reshardCollection 更改分片键。refineCollectionShardKey 要求事先存在支持新键的索引。不拆分就清除 jumbo 标记,会使 balancer 重试同一 chunk 并再次失败。

在 DBAtlas 中打开 →

相关内容