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

ensureIndex can abort reIndex and lose indexes

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6.6
    • Affects Version/s: 2.6.5
    • Component/s: Index Maintenance
    • None
    • Fully Compatible
    • ALL

      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.

            Assignee:
            milkie@mongodb.com Eric Milkie
            Reporter:
            bruce.lucas@mongodb.com Bruce Lucas (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: