[SERVER-58176] Mongos does not validate readConcern on insert/update/delete commands Created: 30/Jun/21  Updated: 29/Oct/23  Resolved: 15/Oct/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 5.2.0, 4.4.17, 5.0.12

Type: Bug Priority: Major - P3
Reporter: Shane Harvey Assignee: Jonathan Lee
Resolution: Fixed Votes: 1
Labels: sharding-wfbf-day
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Duplicate
is duplicated by SERVER-47915 Write commands silently ignore readCo... Closed
Related
related to SERVER-37523 Call supportsReadConcern for all comm... Backlog
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v5.1, v5.0, v4.4, v4.2
Sprint: Sharding 2021-10-18
Participants:

 Description   

Mongos does not validate readConcern on insert/update/delete commands:

MongoDB Enterprise mongos> db.serverBuildInfo()['version']
5.0.0-rc4
MongoDB Enterprise mongos> db.runCommand({'update': 'test', updates: [{q:{}, u:{'$set': {x:1}}}], readConcern: {level: 'snapshot'}})
{
	"nModified" : 0,
	"n" : 0,
	"ok" : 1
}
MongoDB Enterprise mongos> db.runCommand({'insert': 'test', documents: [{}], readConcern: {level: 'snapshot'}})
{
	"n" : 1,
	"ok" : 1
}
MongoDB Enterprise mongos> db.runCommand({'delete': 'test', deletes: [{q:{}, limit: 1}], readConcern: {level: 'snapshot'}})
{
	"n" : 1,
	"ok" : 1
}

The same commands on mongod result in an error:

PRIMARY> db.runCommand({'insert': 'test', documents: [{}], readConcern: {level: 'snapshot'}})
{
	"ok" : 0,
	"errmsg" : "Command insert does not support { readConcern: { level: \"snapshot\", provenance: \"clientSupplied\" } } :: caused by :: read concern not supported",
	"code" : 72,
	"codeName" : "InvalidOptions"
}

Now you might say "sure, why would it validate readConcern on a write command?" Well, drivers expose snapshot reads support through the sessions api. You can declare a session with "snapshot=True" and then all operations using that session follow the snapshot reads protocol, eg:

# All operations read from the same snapshot.
with client.start_session(snapshot=True) as session:
    # sends readConcern.level=snapshot, the session records atClusterTime response
    docs1 = list(coll1.find({}, session=session))
    # sends readConcern.level=snapshot plus atClusterTime
    docs2 =  list(coll2.aggregate([], session=session))
    # sends readConcern.level=snapshot plus atClusterTime
    values = coll3.distinct('field', session=session)

Drivers would like any operation that doesn't support readConcern.level=snapshot to error. For example, write commands (insert, update, delete, findAndModify, etc) and unsupported read operations like listCollections should error. The plan is to send readConcern.level snapshot with all commands in a snapshot session and rely on the server to report an error when that particular command is not supported. This plan only works if Mongos consistently validates readConcern on all commands (like mongod).



 Comments   
Comment by Githook User [ 17/Aug/22 ]

Author:

{'name': 'Erin Liang', 'email': 'erin.liang@mongodb.com', 'username': 'erl-ang'}

Message: SERVER-58176 Remove override for supportsReadConcern in ClusterWriteCmd
Branch: v5.0
https://github.com/mongodb/mongo/commit/c557a829e725cffdd4f1cd76814e6c2be3672bfb

Comment by Githook User [ 12/Aug/22 ]

Author:

{'name': 'Jonathan Lee', 'email': 'jonathan.lee@mongodb.com', 'username': 'jonatlee'}

Message: SERVER-58176 Remove override for supportsReadConcern in ClusterWriteCmd

(cherry picked from commit db3f81f7f409688b537ccdcf0d7212a8fd7c5d2c)
Branch: v4.4
https://github.com/mongodb/mongo/commit/0f0d3670dc5568157d6230eead322389a8e2d60b

Comment by Githook User [ 15/Oct/21 ]

Author:

{'name': 'Jonathan Lee', 'email': 'jonathan.lee@mongodb.com', 'username': 'jonatlee'}

Message: SERVER-58176 Remove override for supportsReadConcern in ClusterWriteCmd
Branch: master
https://github.com/mongodb/mongo/commit/db3f81f7f409688b537ccdcf0d7212a8fd7c5d2c

Comment by Shane Harvey [ 05/Oct/21 ]

Thanks cheahuychou.mao. As far as drivers are concerned for this ticket, we only care that insert/update/delete commands error when readConcern level "snapshot" is provided.

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