Does mongodb read from a secondary member of a replica set when using 'movechunk' to balance a shard cluster?

StackOverflow https://stackoverflow.com/questions/18898609

Question

With the 'movechunk' command (and consequently when the balancer is running), do reads and locks happen on the primary or secondary member of a replica set?

Our application is not currently reading from secondaries, so it would be nice if the shard balancer / movechunk command read from and only locked the secondary member without affecting performance of the primary.

Was it helpful?

Solution

The shard balancer must read from and perform writes to the primary members of shards during a migration. This is necessary to maintain a consistent state of data across shards. However, the locking that happens during reads and writes during migrations is no different from what happens during normal reads and writes to the system. So, these should not have a significant performance impact.

If you do find that migrations are causing noticeable performance slowdowns, this could be a sign that your cluster has other problems. For example, if you've picked a less-than-optimal shard key, that could lead to very frequent migrations, which would be taxing on your system. Or, if your system is already operating under a very heavy load that is close to capacity, a migration might just add enough extra work to slow performance in a notable way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top