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

Expose error code names in mongod responses where mongos does

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor - P4
    • Resolution: Unresolved
    • Affects Version/s: 4.4.2, 4.9.0-alpha4
    • Fix Version/s: Backlog
    • Component/s: None
    • Labels:
      None

      Description

      When I perform an insert that fails due to unique index violation, mongod does not return error code name but mongos does.

      Test program:

      require 'mongo'
      require 'byebug'
       
      def test(port)
        client = Mongo::Client.new(["localhost:#{port}"], database: 'test')
       
        coll = client['foo']
        coll.delete_many
       
        coll.insert_one(_id: 1)
        begin
          coll.insert_one(_id: 1)
        rescue Mongo::Error::OperationFailure => e
          pp e.document
        end
      end
       
      [14400, 14420, 14440, 14900, 14920, 14940].each do |port|
        puts
        puts "Testing #{port}"
        test(port)
      end
      

      Legend:

      14400 4.4 standalone
      14420 4.4 replica set
      14440 4.4 sharded cluster
      14900 4.9 standalone
      14920 4.9 replica set
      14940 4.9 sharded cluster

      Results:

      Testing 14400
      {"n"=>0,
       "writeErrors"=>
        [{"index"=>0,
          "code"=>11000,
          "keyPattern"=>{"_id"=>1},
          "keyValue"=>{"_id"=>1},
          "errmsg"=>
           "E11000 duplicate key error collection: test.foo index: _id_ dup key: { _id: 1 }"}],
       "ok"=>1.0}
       
      Testing 14420
      {"n"=>0,
       "writeErrors"=>
        [{"index"=>0,
          "code"=>11000,
          "keyPattern"=>{"_id"=>1},
          "keyValue"=>{"_id"=>1},
          "errmsg"=>
           "E11000 duplicate key error collection: test.foo index: _id_ dup key: { _id: 1 }"}],
       "opTime"=>
        {"ts"=>
          #<BSON::Timestamp:0x00005567763138b8 @increment=2, @seconds=1616946710>,
         "t"=>1},
       "electionId"=>BSON::ObjectId('7fffffff0000000000000001'),
       "ok"=>1.0,
       "$clusterTime"=>
        {"clusterTime"=>
          #<BSON::Timestamp:0x0000556776313688 @increment=3, @seconds=1616946710>,
         "signature"=>
          {"hash"=><BSON::Binary:0x1660 type=generic data=0x0000000000000000...>,
           "keyId"=>0}},
       "operationTime"=>
        #<BSON::Timestamp:0x0000556776313430 @increment=2, @seconds=1616946710>}
       
      Testing 14440
      {"n"=>0,
       "writeErrors"=>
        [{"index"=>0,
          "code"=>11000,
          "codeName"=>"DuplicateKey",
          "errmsg"=>
           "E11000 duplicate key error collection: test.foo index: _id_ dup key: { _id: 1 }"}],
       "ok"=>1.0,
       "operationTime"=>
        #<BSON::Timestamp:0x00005567761da370 @increment=3, @seconds=1616946710>,
       "$clusterTime"=>
        {"clusterTime"=>
          #<BSON::Timestamp:0x00005567761da000 @increment=4, @seconds=1616946710>,
         "signature"=>
          {"hash"=><BSON::Binary:0x1780 type=generic data=0x0000000000000000...>,
           "keyId"=>0}}}
       
      Testing 14900
      {"n"=>0,
       "writeErrors"=>
        [{"index"=>0,
          "code"=>11000,
          "keyPattern"=>{"_id"=>1},
          "keyValue"=>{"_id"=>1},
          "errmsg"=>
           "E11000 duplicate key error collection: test.foo index: _id_ dup key: { _id: 1 }"}],
       "ok"=>1.0}
       
      Testing 14920
      {"n"=>0,
       "electionId"=>BSON::ObjectId('7fffffff0000000000000001'),
       "opTime"=>
        {"ts"=>
          #<BSON::Timestamp:0x0000556775c21820 @increment=2, @seconds=1616946710>,
         "t"=>1},
       "writeErrors"=>
        [{"index"=>0,
          "code"=>11000,
          "keyPattern"=>{"_id"=>1},
          "keyValue"=>{"_id"=>1},
          "errmsg"=>
           "E11000 duplicate key error collection: test.foo index: _id_ dup key: { _id: 1 }"}],
       "ok"=>1.0,
       "$clusterTime"=>
        {"clusterTime"=>
          #<BSON::Timestamp:0x0000556775c37468 @increment=3, @seconds=1616946710>,
         "signature"=>
          {"hash"=><BSON::Binary:0x2120 type=generic data=0x0000000000000000...>,
           "keyId"=>0}},
       "operationTime"=>
        #<BSON::Timestamp:0x0000556775c37080 @increment=2, @seconds=1616946710>}
       
      Testing 14940
      {"n"=>0,
       "writeErrors"=>
        [{"index"=>0,
          "code"=>11000,
          "codeName"=>"DuplicateKey",
          "errmsg"=>
           "E11000 duplicate key error collection: test.foo index: _id_ dup key: { _id: 1 }"}],
       "ok"=>1.0,
       "$clusterTime"=>
        {"clusterTime"=>
          #<BSON::Timestamp:0x000055677654c080 @increment=10, @seconds=1616946710>,
         "signature"=>
          {"hash"=><BSON::Binary:0x2240 type=generic data=0x0000000000000000...>,
           "keyId"=>0}},
       "operationTime"=>
        #<BSON::Timestamp:0x0000556776533e40 @increment=9, @seconds=1616946710>}
      

      On both 4.4 and 4.9, sharded cluster responses include codeName and neither standalone nor mongos responses do.

      Since the error originates in a mongod, mongod should be able to fill in the code name also?

      Tested on 4.9.0-alpha7.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              backlog-server-servicearch Backlog - Service Architecture
              Reporter:
              oleg.pudeyev Oleg Pudeyev
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated: