Jumbo chunks

In some edge cases, we may end up with jumbo chunks, chunks that are larger than the chunk size and can not be split by MongoDB. We may also run into the same situation if the number of documents in our chunk exceeds the maximum document limit.

These chunks will have the jumbo flag enabled. Ideally MongoDB will keep track of whether it can split the chunk, and as soon as it can, it will. However, we may decide that we want to manually trigger the split before MongoDB does.

The way to do so is as follows.

Connect via shell to your mongos router and run the following:

> sh.status(true)

Identify the chunk that has jumbo in its description:

databases:

mongo_books.books
...
chunks:

shardB 2
shardA 2
{ "id" : 7 } -->> { "id" : 9 } on : shardA Timestamp(2, 2) jumbo

Invoke splitAt() or splitFind() manually to split the chunk on the books collection of database mongo_books at id=8:

> sh.splitAt( "mongo_books.books", { id: 8 })
splitAt() will split based on the split point we define. The two new splits may or may not be balanced.

Alternatively, if we want to leave it to MongoDB to find where to split in our chunk, we can use splitFind:

> sh.splitFind("mongo_books.books", {id: 7})

splitFind now will try to find the chunk that the id:7 query belongs to and automatically define the new bounds for the split chunks so that they are roughly balanced.

In both cases, MongoDB will try to split the chunk, and if successful, it will remove the jumbo flag from it.

If the preceding operation is unsuccessful, then and only then should we try stopping the balancer first, while also verifying the output and waiting for any pending migrations to finish first:

> sh.stopBalancer()
> sh.getBalancerState()

This should return false:

> use config
while( sh.isBalancerRunning() ) {
print("waiting...");
sleep(1000);
}

Wait for any waiting… messages to stop printing. Then find the jumbo flagged chunk in the same way as before.

Finally update the chunks collection in your config database of the mongos router, like this:

> db.getSiblingDB("config").chunks.update(
{ ns: "mongo_books.books", min: { id: 7 }, jumbo: true },
{ $unset: { jumbo: "" } }
)

The preceding command is a regular update() command, with the first argument being the find() part to find which document to update and the second argument being the operation to apply to it ($unset: jumbo flag).

After all this is done, we re-enable the balancer:

> sh.setBalancerState(true)

And connect to the admin database to flush the new configuration to all nodes:

> db.adminCommand({ flushRouterConfig: 1 } )
Always back up the config database before modifying any state manually.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.131.214