[SERVER-45897] mongos should forward WriteConcernError errInfo from shards Created: 31/Jan/20  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Querying, Sharding
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Kevin Pulo Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-45623 RWC provenance Closed
Assigned Teams:
Query Optimization
Backwards Compatibility: Minor Change
Participants:

 Description   

When mongod returns a WriteConcernError, there may be additional info in an errInfo field:

> db.test.insert({}, {writeConcern: {w: "majority", wtimeout: 1}})
WriteResult({
        "nInserted" : 1,
        "writeConcernError" : {
                "code" : 64,
                "codeName" : "WriteConcernFailed",
                "errmsg" : "waiting for replication timed out",
>>>             "errInfo" : {
>>>                     "wtimeout" : true
>>>             }
        }
})

However, when mongos gathers and merges WriteResults from shards, this info gets serialised to JSON and concatenated into the errmsg:

> db.test.insert({}, {writeConcern: {w: "majority", wtimeout: 1}})
WriteResult({
        "nInserted" : 1,
        "writeConcernError" : {
                "code" : 64,
                "codeName" : "WriteConcernFailed",
                "errmsg" : "waiting for replication timed out; Error details: { wtimeout: true } at shard01"
                                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        }
})

Better would be if the errInfo from the shards was available in the top-level errInfo, eg:

> db.test.insert({}, {writeConcern: {w: "majority", wtimeout: 1}})
WriteResult({
        "nInserted" : 1,
        "writeConcernError" : {
                "code" : 64,
                "codeName" : "WriteConcernFailed",
                "errmsg" : "waiting for replication timed out; Error details: { wtimeout: true } at shard01",
>>>             "errInfo" : {
>>>                     "wtimeout" : true,
>>>                     "shards" : {
>>>                         "shard01" : {
>>>                             "wtimeout" : true,
>>>                         }
>>>                     }
                }
        }
})

(The existing errmsg format should be preserved for backwards compatibility.)


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