-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
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.