Thoughts on the processing of equalizer information in "Toolsformongo" mongo_detail.py
Let's look at the output of several typical scenarios db.settings.find({‘_id‘:‘balancer‘})
:
1. When balancer is never set after MONGOs is created:
mongos> var x = db.settings.findOne({‘_id‘:‘balancer‘})mongos> x == nulltruemongos> sh.getBalancerState()true
2. After the MONGOs has been created, the balancer is manually closed for any reason
mongos> db.settings.findOne({‘_id‘:‘balancer‘}){ "_id" : "balancer", "mode" : "off", "stopped" : true }mongos> sh.getBalancerState()false
3. Set the run time period of the Balancer, 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. Set the run time period of the Balancer, where the current time
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
And 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. The case that CONFIGDB is not the default Config library is processed first.
2. x == null
represents the above never set balancer, the default open condition
3. Reverse the. Stopped entry in the return value to get it 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;}
Thoughts on the processing of equalizer information in "NoSQL" mongo_detail.py