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

ensureIndex can abort reIndex and lose indexes

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.6.5
    • Fix Version/s: 2.6.6
    • Component/s: Indexing
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL

      Description

      Executing ensureIndex on an existing index while a reIndex operation is in process may terminate the reIndex operation early with an error 68 (index already exists), and the remaining indexes will have been dropped and never get rebuilt. Reproduce as follows:

      setup.js

          db.c.drop()
          db.c.ensureIndex({a:1}, {background:true})
          db.c.ensureIndex({b:1}, {background:true})
          db.c.ensureIndex({c:1}, {background:true})
          db.c.ensureIndex({d:1}, {background:true})
          db.c.ensureIndex({e:1}, {background:true})
          for (var i=0; i<500; i++)
              db.c.insert({})

      ensure.js:

          while (true) {
              db.c.ensureIndex({c:1})
          }

      reindex.js:

          while (true) {
              result = db.c.reIndex()
              if ('nIndexes' in result) {
                  print('nIndexes', result.nIndexes)
              }
              if ('errmsg' in result) {
                  printjson(result)
              }
              sleep(100)
          }

      repro:

      mongo test setup.js
      (sleep 1; mongo test ensure.js) &
      mongo test reindex.js

      After 1 second when the ensureIndexes start the reIndexes will error out with code 68 and the number of indexes will drop to 3.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: