[SERVER-46093] Check read preference document for unknown options Created: 12/Feb/20  Updated: 12/Dec/23

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

Type: Improvement Priority: Major - P3
Reporter: Andreas Braun Assignee: Backlog - Cluster Scalability
Resolution: Unresolved Votes: 0
Labels: sa-groomed
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Cluster Scalability
Sprint: Service Arch 2020-03-09, Service Arch 2020-03-23, Service Arch 2020-04-06, Service arch 2020-04-20, Service arch 2020-05-04, Service arch 2020-05-18, Service arch 2020-06-01, Service arch 2020-06-15, Service arch 2020-06-29, Service arch 2020-07-13, Service Arch 2020-07-27, Service Arch 2020-08-10, Service Arch 2020-08-24
Participants:
Story Points: 3

 Description   

While writing the driver spec for hedged reads, we noticed that unsupported read preference options are silently ignored. This can produce unexpected behaviour when a user specifies the hedge option against a non-4.4 server: the option is silently ignored and no read hedging will be performed. For example, this is a read command with hedge option set run against a 4.2 server:

MongoDB Enterprise mongos> db.runCommand({count: 'test', $readPreference: { mode: 'secondary', hedge: {asdf: true} }})
{
	"shards" : {
		
	},
	"n" : 0,
	"ok" : 1,
	"operationTime" : Timestamp(1581060684, 2),
	"$clusterTime" : {
		"clusterTime" : Timestamp(1581060684, 2),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	}
}

In contrast, the server will return an error document if the hedge document contains an unknown option. The following example was run against a 4.3.3 server:

MongoDB Enterprise mongos> db.runCommand({count: 'test', $readPreference: { mode: 'secondary', hedge: {asdf: true} }})
{
	"ok" : 0,
	"errmsg" : "BSON field 'hedge.asdf' is an unknown field.",
	"code" : 40415,
	"codeName" : "Location40415",
	"operationTime" : Timestamp(1581060865, 1),
	"$clusterTime" : {
		"clusterTime" : Timestamp(1581060865, 1),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	}
}

Acceptance criteria:

The server should return an error document when an unknown read preference option is encountered.



 Comments   
Comment by Jeremy Mikola [ 13/Feb/20 ]

In mongodb/specifications#727 for SPEC-1509 (driver support for hedged reads in mongos), I noted that the spec currently says the following under Passing read preference to mongos:

Mongos receiving a query with $readPreference SHOULD validate the mode, tags, and maxStalenessSeconds fields according to rules 1 and 2 above, but SHOULD ignore unrecognized fields for forward-compatibility rather than throwing an error.

This language dates back to an early version of the spec, and also predates more recent SERVER initiatives to add stricter validation of unsupported options in command documents. It likely hints that the current mongos behavior was intentional (going back to earlier server releases when unsupported options were ignored), but I see no reason that cannot be changed if there is consensus that stricter option validation should also apply to $readPreference.

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