Four steps to split a MongoDB chunk


This is the second part of the post What is a MongoDB chunk?

What are the steps for splitting a chunk?

  1. All the mongos store information about the size of the chunks of all of the shards. When a mongos realizes that a chunk has been written a lot, it asks its shard if the chunk needs to be split.
  2. The shard returns a list of possible split points. If it is empty it will not be necessary to split the chunk and mongos will do nothing, otherwise the list will be filled up with the points the chunk could be split at.
  3. The mongos will choose one point to split the chunk and will update the metadata at the config servers.
  4. Finally, the mongos will refresh its cache.

The configdb.changelog collection stores a log of every split that has been made. In the next example a chunk with documents which shard key varies from 0 to $maxKey is split in two chunks. The range for the first one varies from 0 to 49999 and the second one from 50000 to $maxKey.

Split disabling

The split process can be initiated by any of the mongos, hence, if for some reason we don’t want automatic chunk splitting in our cluster we must disabling it in all of the mongos. So, we must use this option at the moment of starting each of our mongos:

Please, I will try to explain everything you need!

Leave a comment

Your email address will not be published. Required fields are marked *

11 + 4 =