[SERVER-12540] GLE doesn't set error for failed index builds Created: 29/Jan/14  Updated: 03/Feb/14  Resolved: 03/Feb/14

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

Type: Bug Priority: Major - P3
Reporter: Jeremy Mikola Assignee: Jeremy Mikola
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-12215 createIndex and ensureIndex do not re... Closed
Related
is related to SERVER-12538 Possible to create indexes with inval... Closed
Operating System: ALL
Participants:

 Description   

On the latest 2.5.x nightly, 92cf0713b74ce2f8b011e6768a66c4e99d75a8ea, failed index builds appear to be NOOPS:

> db.foo.ensureIndex({a:'woohoo'});
> db.getLastErrorObj()
{
	"connectionId" : 15,
	"n" : 0,
	"syncMillis" : 0,
	"writtenTo" : null,
	"err" : null,
	"err" : null,
	"ok" : 1
}

Note that the nightly above is prior to the new createIndexes command for SERVER-1627.

On 2.4.9, failed index builds yield an error:

> db.foo.ensureIndex({a:"ok"})
{
	"err" : "Unknown index plugin 'ok' in index { a: \"ok\" }",
	"code" : 16734,
	"n" : 0,
	"connectionId" : 1,
	"ok" : 1
}
> db.foo.ensureIndex({a:[1,2]})
{
	"err" : "bad index key pattern { a: [ 1.0, 2.0 ] }",
	"code" : 10098,
	"n" : 0,
	"connectionId" : 1,
	"ok" : 1
}
> db.foo.ensureIndex({a:{"ORLY":"YARLY"}})
{
	"err" : "bad index key pattern { a: { ORLY: \"YARLY\" } }",
	"code" : 10098,
	"n" : 0,
	"connectionId" : 1,
	"ok" : 1
}
>



 Comments   
Comment by Jeremy Mikola [ 03/Feb/14 ]

renctan: I retested with 2.5.5:

> db.foo.ensureIndex({a:"ok"})
{
	"ok" : 0,
	"errmsg" : "Unknown index plugin 'ok' in index { a: \"ok\" }",
	"code" : 67
}
> db.foo.ensureIndex({a:[1,2]})
{
	"createdCollectionAutomatically" : true,
	"numIndexesBefore" : 1,
	"ok" : 0,
	"errmsg" : "bad index key pattern { a: [ 1.0, 2.0 ] }",
	"code" : 67
}
> db.foo.ensureIndex({a:{"ORLY":"YARLY"}})
{
	"ok" : 0,
	"errmsg" : "bad index key pattern { a: { ORLY: \"YARLY\" } }",
	"code" : 67
}

Looks like we're all good here.

Comment by Jeremy Mikola [ 30/Jan/14 ]

renctan: I was running the script in the issue description on a nightly before your recent commits, so the index creation was doing an insert operation. And that was likely using the new write command, so it makes sense that GLE wouldn't report anything. The ensureIndex and createIndex methods were as follows:

> db.foo.ensureIndex
function ( keys , options ){
    this.createIndex(keys, options);
    err = this.getDB().getLastErrorObj();
    if (err.err) {
        return err;
    }
    // nothing returned on success
}
> db.foo.createIndex
function ( keys , options ){
    var o = this._indexSpec( keys, options );
    this._db.getCollection( "system.indexes" ).insert( o , 0, true );
}

In light of that, it looks like this is all addressed by https://github.com/mongodb/mongo/commit/22a35b2aa4985cfead698920d015f691b11076f0.

Comment by Randolph Tan [ 30/Jan/14 ]

I don't think it is valid to call getLastError to get errors after ensureIndex in the shell (when talking to a new server) anymore. The correct way to get the error is to examine the return value of the ensureIndex method (which used to call the insert write command and switched to call the createIndexes command) - no return value if no error and returns the command response object otherwise.

Comment by Jeremy Mikola [ 30/Jan/14 ]

dan@10gen.com: The latest nightly is mongodb-linux-x86_64-2014-01-23. renctan's fix for SERVER-12215 was committed on January 28th (it shows up in this diff), so this may already be fixed in master. I can retest when the nightly is updated.

Comment by Daniel Pasette (Inactive) [ 30/Jan/14 ]

looks like a duplicate of SERVER-12215. Can you check latest?

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