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

Wrong code for duplicate key error when downconverting update command

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6.0-rc2
    • Affects Version/s: 2.6.0-rc1
    • Component/s: Sharding
    • ALL
    • Hide

      A shard running 2.4, mongos 2.6.

      mongos> db.unique_collection.createIndex({s: 1}, {unique: true})
      WriteResult({ "nInserted" : 1 })
      mongos> db.unique_collection.insert([{s:1}, {s: 2}])
      BulkWriteResult({
      	"writeErrors" : [ ],
      	"writeConcernErrors" : [ ],
      	"nInserted" : 2,
      	"nUpserted" : 0,
      	"nMatched" : 0,
      	"nModified" : 0,
      	"nRemoved" : 0,
      	"upserted" : [ ]
      })
      mongos> db.unique_collection.update({s: 2}, {$set: {s: 1}})
      WriteResult({
      	"nMatched" : 0,
      	"nUpserted" : 0,
      	"nModified" : 0,
      	"writeError" : {
      		"code" : 11001,
      		"errmsg" : "E11000 duplicate key error index: test1.unique_collection.$s_1  dup key: { : 1.0 }"
      	}
      })
      

      If the shard is running 2.6, the error code is the expected 11000.

      Show
      A shard running 2.4, mongos 2.6. mongos> db.unique_collection.createIndex({s: 1}, {unique: true }) WriteResult({ "nInserted" : 1 }) mongos> db.unique_collection.insert([{s:1}, {s: 2}]) BulkWriteResult({ "writeErrors" : [ ], "writeConcernErrors" : [ ], "nInserted" : 2, "nUpserted" : 0, "nMatched" : 0, "nModified" : 0, "nRemoved" : 0, "upserted" : [ ] }) mongos> db.unique_collection.update({s: 2}, {$set: {s: 1}}) WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0, "writeError" : { "code" : 11001, "errmsg" : "E11000 duplicate key error index: test1.unique_collection.$s_1 dup key: { : 1.0 }" } }) If the shard is running 2.6, the error code is the expected 11000.

      When a client executes the "update" command on mongos, and mongos sends OP_UPDATE to a shard, and the shard's GLE responds with a duplicate key error, mongos must convert the error code to 11000. However, mongos allows the code 11001 through to the client.

      Clients written to raise a specific exception class for duplicate key errors in response to write commands only anticipate code 11000.

            Assignee:
            greg_10gen Greg Studer
            Reporter:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: