Config database and shard


from the docs:
The config database contains the collections that contain the sharded cluster metadata. MongoDB writes data to the config database when the metadata changes, such as after a chunk migration or a chunk split.

How does config db knows about metadata changes?
How does it knows about chunk migration?
How config DB knows about shards? I see that: Mongos knows about configs (defined in configuration file). Mongos also knows about shard - we add them using addShard. But there is no direct link between config and shards? Is this all handled mongos?

Hi @Michal_Szkudlarek,

The config database lives on the config server and all the communications with the config server are handled internally by MongoDB. The individual shards and mongoses can talk to the config server.

When the mongos routes an update or insert to a chunk, the chunk may grow beyond the configured chunk size and trigger an auto-split, which partitions the oversized chunk into smaller chunks. The shard that houses the chunk is responsible for several things such as determining if the chunk should be auto-split, selecting the split points, committing the split points to the config server etc.

Also the balancer thread responsible for chunk migrations runs on the config server primary in order to achieve an even chunk distribution across the shards.

Hope it helps!

~ Shubham