Jumbo chunks

In rare cases, we may end up with jumbo chunks, chunks that are larger than the chunk size and cannot 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 get split; however, we may decide that we want to manually trigger the split before MongoDB does.

The way to do this is as follows:

  1. Connect via shell to your mongos router and run the following:
> sh.status(true)
  1. Identify the chunk that has jumbo in its description using the following code:
databases:

mongo_books.books
...
chunks:

shardB 2
shardA 2
{ "id" : 7 } -->> { "id" : 9 } on : shardA Timestamp(2, 2) jumbo
  1. Invoke splitAt() or splitFind() manually to split the chunk on the books collection of the mongo_books database at the id that is equal to 8 using the following code:
> sh.splitAt( "mongo_books.books", { id: 8 })
The splitAt() function 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 our chunk, we can use splitFind, as follows:

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

The splitFind phrase 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.

  1. 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, as shown in the following code:
> sh.stopBalancer()
> sh.getBalancerState()
> use config
while( sh.isBalancerRunning() ) {
print("waiting...");
sleep(1000);
}

This should return false 

  1. Wait for any waiting… messages to stop printing, and then find the jumbo flagged chunk in the same way as before.
  2. Then 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 out which document to update and the second argument being the operation to apply to it ($unset: jumbo flag).

  1. After all this is done, we re-enable the balancer, as follows:
> sh.setBalancerState(true)

  1. Then, we connect to the admin database to flush the new configuration to all nodes, as follows:
> 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