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

adding an index while an update operation yields can result in incorrect index key entries

    • ALL

      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() );
      

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            aaron Aaron Staple
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: