[SERVER-55582] Expose error code names in mongod responses where mongos does Created: 28/Mar/21  Updated: 03/Jan/24

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: 4.4.2, 4.9.0-alpha4
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Oleg Pudeyev (Inactive) Assignee: Backlog - Service Architecture
Resolution: Unresolved Votes: 0
Labels: sa-remove-fv-backlog-22
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to RUBY-2509 Expose server error code name in Oper... Closed
related to RUBY-3107 Add error code_name for all known errors Closed
Assigned Teams:
Service Arch
Participants:

 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.



 Comments   
Comment by Johnny Shields [ 03/Jan/24 ]

Hi, what is the status of this ticket? If there is any unification of mongod and mongos behavior, can this be considered?

Comment by Kyle Suarez [ 30/Mar/21 ]

The Query Team took a quick look during the triage meeting and we think this might be more appropriate for Service Arch to take a look.

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