[SERVER-14920] CreateIndexes command fails when building duplicate entries. Created: 15/Aug/14  Updated: 09/Jul/16  Resolved: 20/Aug/14

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: 2.7.5
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Mathias Stearn Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Minor Change
Operating System: ALL
Participants:

 Description   

In 2.6 the first index would succeed and the later builds would be skipped since the index now exists. In master this fails because the code to skip existing indexes happens before we build any indexes, so we attempt to build both indexes and fail:

db = db.getSiblingDB("createIndexes");
db.dropDatabase();
db.test.runCommand( "createIndexes", { indexes : [ { name : "x_1", key : { "x" : 1 }, ns: "createIndexes.test" }, 
                                                   { name : "x_1", key : { "x" : 1 }, ns: "createIndexes.test" } ] } );
 
// 2.6.3 result:
  {
  	"createdCollectionAutomatically" : true,
  	"numIndexesBefore" : 1,
  	"note" : "index already exists",
  	"numIndexesAfter" : 2,
  	"ok" : 1
  }
// 2.7 Nightly Result
  {
  	"createdCollectionAutomatically" : true,
  	"numIndexesBefore" : 1,
  	"errmsg" : "exception: x_1",
  	"code" : 68, // IndexAlreadyExists
  	"ok" : 0
  }



 Comments   
Comment by Mathias Stearn [ 20/Aug/14 ]

Discussed with Eliot and decided that the new behavior is ok. Users shouldn't try to build multiple copies of the same index in a single createIndexes command.

Generated at Thu Feb 08 03:36:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.