[SERVER-35605] sh.setBalancerState() should check its argument type to avoid unexpected results Created: 14/Jun/18  Updated: 29/Oct/23  Resolved: 12/Jul/18

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 3.4.0, 3.6.0, 4.0.0-rc5
Fix Version/s: 4.1.1

Type: Improvement Priority: Major - P3
Reporter: Spencer Brown Assignee: Sarah Zhou
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Sharding 2018-07-16
Participants:
Case:

 Description   

The sh.setBalancerState() function in the mongo shell is coded thus:

sh.setBalancerState = function(isOn) {
    if (isOn) {
        return sh.startBalancer();
    } else {
        return sh.stopBalancer();
    }
};

As a consequence, running sh.setBalancerState("true") actually stops the balancer, as does sh.setBalancerState(). These are surprising results.

Suggest adding a type check to the code before the if statement:

  if ((typeof isOn) != "boolean") { print error message and exit }



 Comments   
Comment by Githook User [ 12/Jul/18 ]

Author:

{'name': 'Sarah Zhou', 'email': 'sarah.zhou@10gen.com'}

Message: SERVER-35605 sh.setBalancerState() should check its argument type to avoid unexpected results
Branch: master
https://github.com/mongodb/mongo/commit/2e975546f4676e1ba65e3376c08bd43bee14305f

Generated at Thu Feb 08 04:40:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.