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

Upserts using unidexed query can result in duplicate documents

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.2.0, 2.3.0
    • Component/s: Write Ops
    • None
    • Environment:
      storm 0.8
    • ALL

      using strom, the threads(also in different process) run code:

      myDB("mytable").update(DBObject("key1" -> new ObjectId(myKey), "key2" -> coKey), myUpdates, true, false, WriteConcern.SAFE)
      

      and my storm log as following (node1 and node2 is different machine, the last two columns is using :System.currentTimeMillis(),Thread.currentThread() ):

      on node1: storm-0.8.1/logs/worker-6711.log:2012-09-14 11:18:11 STDIO [INFO] 1347592691476 Thread[Thread-16,5,main]
      on node2: storm-0.8.1/logs/worker-6705.log:2012-09-14 11:18:11 STDIO [INFO] 1347592691456 Thread[Thread-24,5,main]
      

      there is no record in mytable meets the query

      DBObject("key1" -> new ObjectId(myKey), "key2" -> coKey)
      

      before they run, and after they run, there will exist exactly two same records, which I think is quite the opposite of what I know of the meaning of upsert = true.

      from the logs:

      Fri Sep 21 13:18:57 [initandlisten] MongoDB starting : pid=32671 port=27017 dbpath=/home/myuser/mydb 64-bit host=mymachine
      Fri Sep 21 13:18:57 [initandlisten] db version v2.2.0, pdfile version 4.5
      
      ....
       Fri Sep 21 13:35:29 [conn196] update mydb.mytable query: { key1: "k12306", key2: "k86" } update: { field1: "f1", field2: "f2" } nscanned:3341 nupdated:1 upsert:1 keyUpdates:0 numYields: 26 locks(micros) w:7033 333ms
      ...
       Fri Sep 21 13:35:29 [conn192] update mydb.mytable query: { key1: "k12306", key2: "k86" } update: { field1: "f1", field2: "f2" } nscanned:3343 nupdated:1 upsert:1 keyUpdates:0 numYields: 26 locks(micros) w:6906 335ms
      ....
      

      we can see that the commands which cause duplicated records is shown above.

      other conditions is:
      a) when mytable is with index on db.mytable.ensureIndex(

      {"key1":1, "key2":1}

      ), it works ok, no duplicated record generated.
      b) when mytable is without any index, which will cause every mongo command cost much longer time, bang~, the duplicated records appeared..

      original thread:
      https://groups.google.com/forum/?fromgroups=#!topic/mongodb-user/MBafvLXkTYw

        1. dup.js
          0.6 kB
          Randolph Tan

            Assignee:
            Unassigned Unassigned
            Reporter:
            randolph@mongodb.com Randolph Tan
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: