DBAtlas · Database operations atlas

Find jumbo chunks, split them and clear the flag

MongoDBSharding

Command

// 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 } })

What it does

Lists chunks flagged as jumbo because the balancer could not move them, splits those that can be split and clears the jumbo flag; shows how to refine the shard key for huge single-value chunks.

When to use it

When one shard stays noticeably larger than the others, jumbo appears in sh.status() output, or the balancer reports migration errors.

Caution

A chunk whose documents all share the same shard key value cannot be split; the only lasting fix is to change the shard key with refineCollectionShardKey or reshardCollection. refineCollectionShardKey requires a supporting index for the new key to exist beforehand. Clearing the jumbo flag without splitting makes the balancer retry the same chunk and fail again.

Open in DBAtlas →

Related