Database Reference
In-Depth Information
While the balancer does all this work automatically on your behalf, you do have some say in when itoperates.
You can stop and start the balancer on demand and set a window in which it can operate. To stop the balancer, you
connect to the MongoS and issue the sh.stopBalancer() command:
> sh.stopBalancer();
Waiting for active hosts...
Waiting for the balancer lock...
Waiting again for active hosts after balancer is off...
As you can see, the balancer is now off; the command has set the balancer state to off and waited and confirmed
that the balancer has completed any migrations that were running. To start the balancer is the same process; we run
the sh.startBalancer() command:
> sh.startBalancer();
Now, both of these commands can take a few moments to complete and return, as they both wait to confirm that
the balancer is up and actually moving. If you are having trouble or wish to confirm the state for yourself manually,
you can perform the following checks. First, you can check what the balancer flag is set to. This is the document that
acts as the on/off switch for the balancer and it is located in the config database.
> use config
switched to db config
db.settings.find({_id:"balancer"})
{ "_id" : "balancer", "stopped" : true }
Now you can see that the document here with an _id value of balancer is set to stopped : true , which means
that the balancer is not running (stopped). This, however, does not mean that there aren't already migrations running;
to confirm that, we need to check out the “balancer lock.”
The balancer lock exists to ensure that only one balancer can perform balancing actions at a given time. You can
find the balancer lock with the following command:
> use config
switched to db config
> db.locks.find({_id:"balancer"});
{ "_id" : "balancer", "process" : "Pixl.local:40000:1372325678:16807", "state" : 0, "ts" :
ObjectId("51cc11c57ce3f0ee9684caff"), "when" : ISODate("2013-06-27T10:19:49.820Z"), "who" :
"Pixl.local:40000:1372325678:16807:Balancer:282475249", "why" : "doing balance round" }
You can see that this is a significantly more complex document than the settings document. The most important
things, however, are the state entry, which says whether the lock is taken, with 0 meaning “free” or “not taken,” and
anything else meaning “in use.” You should also pay attention to the timestamp, which says when the lock was taken
out. Compare the “free” lock just shown with the “taken” lock next, which shows the balancer was active.
> db.locks.find({_id:"balancer"});
{ "_id" : "balancer", "process" : "Pixl.local:40000:1372325678:16807", "state" : 1, "ts" :
ObjectId("51cc11cc7ce3f0ee9684cb00"), "when" : ISODate("2013-06-27T10:19:56.307Z"), "who" :
"Pixl.local:40000:1372325678:16807:Balancer:282475249", "why" : "doing balance round" }
Search WWH ::




Custom Search