[SERVER-10824] sh.enableBalancing() requires an argument, silently no-ops with no argument Created: 19/Sep/13  Updated: 19/Nov/14  Resolved: 23/Oct/14

Status: Closed
Project: Core Server
Component/s: Shell, Usability
Affects Version/s: 2.5.2
Fix Version/s: 2.8.0-rc0

Type: Bug Priority: Major - P3
Reporter: Asya Kamsky Assignee: Matt Kangas
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Backwards Compatibility: Minor Change
Operating System: ALL
Steps To Reproduce:

mongos> sh.enableBalancing()
mongos> sh.disableBalancing()

Participants:

 Description   

sh.enableBalancing (and disableBalancing) take collection name as an argument. If nothing is passed in, it does not error (probably should!) and then tries to update nobalance flag for collection named "" which of course doesn't exist.

Since it's easy for a user to assume this command enables/disables global cluster balancing, the no op and no warning or error is somewhat dangerous and misleading.



 Comments   
Comment by Githook User [ 23/Oct/14 ]

Author:

{u'username': u'kangas', u'name': u'Matt Kangas', u'email': u'matt.kangas@mongodb.com'}

Message: SERVER-10824 sh.enableBalancing() now requires an argument
Branch: master
https://github.com/mongodb/mongo/commit/602fa05f61b61835b92c8efed2e3354d92ebbe66

Comment by Kevin Pulo [ 18/Aug/14 ]

Based on the phrasing "disable/enable balancing", I would suggest that calling sh.setBalancerState(false/true) (respectively) would give the expected user-intended behaviour, which is to enable/disable the balancer system-wide (in the absence of any argument).

Comment by Asya Kamsky [ 08/May/14 ]

How about something like this:

diff --git a/src/mongo/shell/utils_sh.js b/src/mongo/shell/utils_sh.js
index c567e2d..abe8991 100644
--- a/src/mongo/shell/utils_sh.js
+++ b/src/mongo/shell/utils_sh.js
@@ -259,12 +259,15 @@ sh.waitForBalancer = function( onOrNot, timeout, interval ){
 sh.disableBalancing = function( coll ){
     var dbase = db
     if( coll instanceof DBCollection ) dbase = coll.getDB()
+    else throw "can't find collection with name: " + coll;
+
     dbase.getSisterDB( "config" ).collections.update({ _id : coll + "" }, { $set : { "noBalance" : true } })
 }
 
 sh.enableBalancing = function( coll ){
     var dbase = db
     if( coll instanceof DBCollection ) dbase = coll.getDB()
+    else throw "can't find collection with name: " + coll;
     dbase.getSisterDB( "config" ).collections.update({ _id : coll + "" }, { $set : { "noBalance" : false } })
 }

Generated at Thu Feb 08 03:24:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.