Thoughts on the processing of equalizer information in "NoSQL" mongo_detail.py

Source: Internet
Author: User
Tags findone mongo shell

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.