[SERVER-20022] Upsert errors with "duplicate key error" Created: 18/Aug/15  Updated: 19/Aug/15  Resolved: 19/Aug/15

Status: Closed
Project: Core Server
Component/s: Storage
Affects Version/s: 3.0.5
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Igor Canadi Assignee: Unassigned
Resolution: Duplicate Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-14322 Retry on predicate unique index viola... Closed
Operating System: ALL
Steps To Reproduce:

load('jstests/libs/parallelTester.js'); // for ScopedThread
 
var t = db.getSiblingDB("upsert_bug").getCollection("col");
 
t.drop();
 
var upsertFn = function() {
  for (var i = 0; i < 100; ++i) {
    var c = db.getSiblingDB("upsert_bug").getCollection("col");
    var x = c.update({_id:3}, {$set: {a:'123', b: Math.random()}}, true)
    assert(!x.getWriteError(), tojson(x));
    c.remove({"_id":3});
  }
}
 
var threads = [];
for (var i = 0; i < 2; ++i) {
  var thread = new ScopedThread(upsertFn, db);
  threads.push(thread);
  thread.start();
}
 
threads.forEach(function(t) {
    t.join();
});

Result:

./mongo < ~/tmp/upsert_bug.js
MongoDB shell version: 3.0.5
connecting to: test
true
true
connecting to: test
connecting to: test
assert failed : {
        "nMatched" : 0,
        "nUpserted" : 0,
        "nModified" : 0,
        "writeError" : {
                "code" : 11000,
                "errmsg" : "E11000 duplicate key error collection: upsert_bug.col index: _id_ dup key: { : 3.0 }"
        }
}
Error: assert failed : {
        "nMatched" : 0,
        "nUpserted" : 0,
        "nModified" : 0,
        "writeError" : {
                "code" : 11000,
                "errmsg" : "E11000 duplicate key error collection: upsert_bug.col index: _id_ dup key: { : 3.0 }"
        }
}
    at Error (<anonymous>)
    at doassert (src/mongo/shell/assert.js:11:14)
    at assert (src/mongo/shell/assert.js:20:5)
    at ____MongoToV8_newFunction_temp (<anonymous>:5:5)
2015-08-18T16:34:39.075-0700 I -        js thread raised js exception: Error: assert failed : {
        "nMatched" : 0,
        "nUpserted" : 0,
        "nModified" : 0,
        "writeError" : {
                "code" : 11000,
                "errmsg" : "E11000 duplicate key error collection: upsert_bug.col index: _id_ dup key: { : 3.0 }"
        }
}
    at Error (<anonymous>)
    at doassert (src/mongo/shell/assert.js:11:14)
    at assert (src/mongo/shell/assert.js:20:5)
    at ____MongoToV8_newFunction_temp (<anonymous>:5:5) at src/mongo/shell/assert.js:13
bye
 

Participants:

 Description   

Hello there.

We're seeing an upsert command erroring with "duplicate key error". We managed to get a consistent reproduction and it reproduces for both WiredTiger and RocksDB storage engines.



 Comments   
Comment by Ramon Fernandez Marina [ 19/Aug/15 ]

No worries igor – thanks for the concise repro!

Comment by Igor Canadi [ 19/Aug/15 ]

Looks like a duplicate of SERVER-14322 and SERVER-19600, sorry about that.

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