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

Snapshot queries can miss records if there are concurrent updates

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • None
    • QuInt E (01/11/16)

      "Snapshot" queries (queries using a unique index) can miss records if there are concurrent updates that move the records being queried (even if they don't modify the query keys). It would be useful if this could be improved so that snapshot queries were guaranteed to return all records that existed for the lifetime of the query (neither inserted nor deleted during the query).

      Reproduce as follows:

      function repro() {
      
          // insert 5 records
          db.c.drop()
          for (var i=0; i<5; i++)
              db.c.insert({_id:i, x:[]})
      
          // start query, fetch first batch of 2
          cursor = db.c.find().snapshot().batchSize(2)
          print('got', cursor.next()._id)
              
          // server cursor is now pointing to {_id:2} waiting for our getmore
          // so let's update in a way that requires the {_id:2} record to move
          db.c.update({_id:2}, {$push: {x:0}})
      
          // use our cursor to get the rest; note that {_id:2} is omitted
          while (cursor.hasNext())
              print('got', cursor.next()._id)
      }
      

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            bruce.lucas@mongodb.com Bruce Lucas (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            16 Start watching this issue

              Created:
              Updated:
              Resolved: