Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-35605

sh.setBalancerState() should check its argument type to avoid unexpected results

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.1.1
    • Affects Version/s: 3.4.0, 3.6.0, 4.0.0-rc5
    • Component/s: Sharding
    • Labels:
    • Fully Compatible
    • Sharding 2018-07-16

      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 }
      

            Assignee:
            sarah.zhou@mongodb.com Sarah Zhou
            Reporter:
            spencer.brown@mongodb.com Spencer Brown
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: