[NoSQL] the place of equalizer information in mongo_detail.py
The idea of processing equalizer information in [ToolsForMongo] mongo_detail.py
First, take a look at the db.settings.find ({'_ id':'balancer'}) output in several typical situations:
1. After creating the mongos, when the balancer is never set:
Mongos > var x = db.settings.findOne ({'_ id':'balancer'}) mongos > x = = nulltruemongos > sh.getBalancerState () true
two。 After creating the mongos, the balancer was manually closed for some reason
Mongos > db.settings.findOne ({'_ id':'balancer'}) {"_ id": "balancer", "mode": "off", "stopped": true} mongos > sh.getBalancerState () false
3. The running time period of balancer is set, but the current time is not in it
Mongos > var x = db.settings.findOne ({'_ id':'balancer'}) mongos > x {"_ id": "balancer", "stopped": true, "activeWindow": {"start": "00:00", "stop": "06:00"} mongos > sh.getBalancerState () false
4. The running time period of balancer is set, in which the current time is
Mongos > var x = db.settings.findOne ({'_ id':'balancer'}) mongos > x {"_ id": "balancer", "stopped": false, "activeWindow": {"start": "00:00", "stop": "22:00"} mongos > sh.getBalancerState () true
Take a look at the js code in the official mongo shell.
Mongos > sh.getBalancerStatefunction (configDB) {if (configDB = = undefined) configDB = sh._getConfigDB (); var x = configDB.settings.findOne ({_ id: "balancer"}); if (x = = null) return true; return! x.stopped;}
1. First deal with the case that configDB is not the default config library
2.x = = null indicates that balancer has never been set above and is enabled by default
3. Invert the .stopped item in the return value to get whether it is running
Mongos > sh.isBalancerRunningfunction (configDB) {if (configDB = = undefined) configDB = sh._getConfigDB (); var x = configDB.locks.findOne ({_ id: "balancer"}); if (x = = null) {print ("config.locks collection empty or missing. Be sure you are connected to a mongos"); return false;} return x.state > 0;}