[SERVER-5552] adding an index while an update operation yields can result in incorrect index key entries Created: 09/Apr/12  Updated: 11/Jul/16  Resolved: 13/Jun/12

Status: Closed
Project: Core Server
Component/s: Index Maintenance, Write Ops
Affects Version/s: None
Fix Version/s: 2.1.2

Type: Bug Priority: Major - P3
Reporter: Aaron Staple Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-5755 Invalid BSONObj size: ... 0xEEEEEEEE ... Closed
Related
is related to SERVER-5755 Invalid BSONObj size: ... 0xEEEEEEEE ... Closed
Operating System: ALL
Participants:

 Description   

The update implementation determines if a mod is indexed using the set of index keys present when the operation begins running. If an index is added while the update operation yields, fields present in the new index may not be identified as indexed and an in place update on these fields may be applied improperly.

Test:

 
// If an index is added while an update operation is yielding, the updated documents should be
// indexed correctly.
 
t = db.jstests_updatel;
t.drop();
 
// Insert some { a:0 } values.
for( i = 0; i < 50000; ++i ) {
    t.save( { a:0 } );
}
db.getLastError();
 
p = startParallelShell(
                       // Wait until the update operation (below) begins running.
                       'while( db.jstests_updatel.find( { a:1 } ).limit( -1 ).itcount() == 0 );' +
                       // Add an index on { a:1 }.
                       'db.jstests_updatel.ensureIndex( { a:1 } );'
                       );
 
// Update all documents to { a:1 }.
t.update( {}, { $set: { a:1 } }, false, true );
 
p();
 
// Check that the { a:1 } index contains all { a:1 } values.
assert.eq( 50000, t.find( { a:1 } ).hint( { a:1 } ).itcount() );



 Comments   
Comment by auto [ 13/Jun/12 ]

Author:

{u'date': u'2012-06-13T05:23:53-07:00', u'email': u'eliot@10gen.com', u'name': u'Eliot Horowitz'}

Message: SERVER-5552 - fix possible npe
Branch: master
https://github.com/mongodb/mongo/commit/e55e9b51215712123994d00036e6e6179a03c821

Comment by auto [ 13/Jun/12 ]

Author:

{u'date': u'2012-06-12T20:59:44-07:00', u'email': u'eliot@10gen.com', u'name': u'Eliot Horowitz'}

Message: SERVER-5552 - fix multi-update when index is finished being built in the middle
Branch: master
https://github.com/mongodb/mongo/commit/fe8816c7644eb1c89c7dce43083abb0d7c65c41c

Comment by auto [ 13/Jun/12 ]

Author:

{u'date': u'2012-06-12T20:25:05-07:00', u'email': u'eliot@10gen.com', u'name': u'Eliot Horowitz'}

Message: SERVER-5552 - prep by reducing redundant yields
Branch: master
https://github.com/mongodb/mongo/commit/86bc0d2c3d6a820776fd093f9473e700ffbb2982

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