Skip to content

Conversation

@ShaneHarvey
Copy link
Member

This PR requires drivers to send readConcern with all commands in a snapshot session (even writes). This effectively bans all unsupported operations in a snapshot session because the server will reject commands that do not support readConcern.level "snapshot". For example:

MongoDB Enterprise repl0:PRIMARY> db.runCommand({'listCollections': 'test', readConcern: {level: 'snapshot'}})
{
"ok" : 0,
"errmsg" : "Command listCollections does not support { readConcern: { level: \"snapshot\", provenance: \"clientSupplied\" } } :: caused by :: read concern not supported",
"code" : 72,
"codeName" : "InvalidOptions"
}
MongoDB Enterprise repl0: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"
}

I've added tests for a variety of methods to ensure we send readConcern.level correctly and that the server rejects the field. I can add tests for more operations once we decide this approach is reasonable.

Copy link
Contributor

@jyemin jyemin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the approach. I implemented the changes in the Java driver, though, and some of the test fail on sharded 5.0 clusters. For example "Server returns an error on insertOne with snapshot" fails because the server does not throw an exception. I confirmed in the shell:

MongoDB Enterprise mongos> db.runCommand({'insert': 'test', documents: [{}], readConcern: {level: 'snapshot'}})
{
	"n" : 1,
	"ok" : 1,
	"$clusterTime" : {
		"clusterTime" : Timestamp(1625064185, 7),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	},
	"operationTime" : Timestamp(1625064185, 7)
}

Not sure what we should do. I suppose we could disable these tests on sharded clusters and report this as a server bug.

Update: I just noticed that 4 of the 9 tests in snapshot-sessions-unsupported-ops pass (findOneAndUpdate, listDatabase, listCollections, listIndexes), so the server is not consistent with this enforcement.

@ShaneHarvey
Copy link
Member Author

ShaneHarvey commented Jun 30, 2021

Ah that's 100% correct. I had forgot to check the sharded test results. I also see mongos not validating readConcern on insert, update, and delete commands. I just opened SERVER-58176.

@jyemin
Copy link
Contributor

jyemin commented Jun 30, 2021

Cool. Can you re-arrange the tests so that they are skipped on sharded clusters for now?

@ShaneHarvey
Copy link
Member Author

Can you re-arrange the tests so that they are skipped on sharded clusters for now?

Done.

@ShaneHarvey
Copy link
Member Author

ShaneHarvey commented Jun 30, 2021

@ajdavis Does this approach look good to you? For more background see the description in SERVER-58176.

@ShaneHarvey ShaneHarvey requested a review from ajdavis June 30, 2021 19:26
@jyemin jyemin self-requested a review June 30, 2021 20:56
Copy link
Contributor

@jyemin jyemin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This required a change in approach for the implementation, but it wasn't too big a deal in the end. All the tests are passing.

LGTM

=================================================

Drivers MUST set the readConcern ``level`` and ``atClusterTime`` fields (as
outlined above) on all commands in a snapshot session.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add, "even commands like insert and update that do not accept a readConcern. This ensures the server will return an error for invalid operations, such as writes, within a session configured for snapshot reads." Make the implicit explicit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@ajdavis
Copy link
Member

ajdavis commented Jun 30, 2021

Yeah, if we can fix SERVER-58176 in time, then I like this approach a lot.

Copy link
Member Author

@ShaneHarvey ShaneHarvey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick reviews!

=================================================

Drivers MUST set the readConcern ``level`` and ``atClusterTime`` fields (as
outlined above) on all commands in a snapshot session.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@rstam rstam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. LGTM

@ShaneHarvey ShaneHarvey merged commit 8ade331 into mongodb:master Jun 30, 2021
@ShaneHarvey ShaneHarvey deleted the DRIVERS-1819 branch July 1, 2021 03:09
p-mongo pushed a commit to p-mongo/specifications that referenced this pull request Jul 13, 2021
* upstream/master:
  DRIVERS-1836 Skip tests with $out stage on serverless (mongodb#1036)
  DRIVERS-1816 Test redaction of replies to security sensitive commands (mongodb#1026)
  DRIVERS-1828: Remove insertedCount and improve use of $$unsetOrMatches (mongodb#1034)
  DRIVERS-1819 Disable writes and other unsupported operations in snapshot reads (mongodb#1033)
kevinAlbs pushed a commit to kevinAlbs/specifications that referenced this pull request Nov 9, 2021
…hot reads (mongodb#1033)

Rely on the server to report an error for unsupported snapshot read
operations by sending readConcern with all commands, even writes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants