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

Don't cache ensureIndex in the shell

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 2.3.1
    • None
    • JavaScript, Shell
    • None
    • Fully Compatible
    • ALL

    Description

      It should test getLastError == null rather than ""

      > db.asdf.ensureIndex
      function (keys, options) {
          var name = this._indexSpec(keys, options).name;
          this._indexCache = this._indexCache || {};
          if (this._indexCache[name]) {
              return;
          }
          this.createIndex(keys, options);
          if (this.getDB().getLastError() == "") {
              this._indexCache[name] = true;
          }
      }
       
      > db.asdf.ensureIndex({a:1}); db.getLastError()
      null
      > db.asdf.ensureIndex({a:1}); db.getLastError() == ""
      false

      Note that if we fix this we need to make sure that the _indexCache does not persist across calls to db.eval() as the cache won't be invalidated at the necessary times.

      Also, it may be best to just not cache ensureIndex in the shell. If someone runs a script that drops an index, they would expect ensureIndex in an admin shell to rebuild it, even if the shell had been open a while.

      Attachments

        Activity

          People

            mathias@mongodb.com Mathias Stearn
            mathias@mongodb.com Mathias Stearn
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: