MongoDB – Understanding sh.getBalancerState() vs sh.isBalancerRunning

linuxmigrationmongodb

During upgrading config servers to use WiredTIger, I stopped balancer using sh.setBalancerState(false), and then I run sh.getBalancerState(). The output is false. Does this mean the balancer is not running? After this, I just started to upgrade the config servers to use WiredTiger. But after reading the document carefully, I am not sure whether no migrations are in progress after running sh.setBalancerState(false)? If some migrations are running, but I backup the config data and stopped the config servers one by one. What is the bad effect? Now the config servers are all up with WiredTiger, how to check whether the config servers have the same data, especially config data, meta data….?

Best Answer

You can verify that no migrations are running by checking the balance with

 sh.isBalancerRunning()

which is true if chunks are being migrated and false if not. Using BalancerState only shows you if it is enabled or disabled, not its current run state. While it depends on what the specific documentation says, I'd probably feel safer setting the balancer state to false, checking the migration status with the above command, and then stopping it:

 sh.stopBalancer()

So now that we have the proper method clarified,

What is the bad effect?

I'm not too sure how gracefully MongoDB would potentially handle this issue. However, you should be able to find the steps that occur during a migration in your log.

Always check the logs!

Update: As specified by the OP, you can also use sh.status() if this work occurred in the last 24 hours to check if there are any recorded errors in migrations from the balancer. If > 24 hours, go check the logs.

Update 2: Marcus clarified in the comments that partial migrations are not possible, so this should not be a concern.