[CDRIVER-1885] Hinted cursors should not set slaveOk bit for primary servers Created: 25/Oct/16  Updated: 02/Nov/16  Resolved: 02/Nov/16

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: 1.4.2
Fix Version/s: 1.5.0

Type: Improvement Priority: Minor - P4
Reporter: Jeremy Mikola Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CDRIVER-1872 mongoc_cursor_set_hint causes seconda... Closed

 Description   

From the server selection spec section on Topology types: ReplicaSetWithPrimary or ReplicaSetNoPrimary: Read Operations:

For all read preferences modes except 'primary', clients MUST set the slaveOK wire protocol flag to ensure that any suitable server can handle the request. Clients MUST NOT set the slaveOK wire protocol flag if the read preference mode is 'primary'.

As mentioned in the code review for CDRIVER-1872, mongoc_cursor_set_hint() currently sets the slaveOK bit even querying a primary, which conflicts with the spec.

Fixing this means that users will now receive a "not master" error if libmongoc thinks the node is a primary, omits the slaveOk bit, and the server is actually in a non-primary state. That said, how would a host transition from a primary to non-primary state without dropping its connections? Would this "not master" edge case even happen in practice, or is this just a theoretical?


As an aside, I'm not familiar with the reasoning behind the spec's rule on not setting slaveOK for primary queries. Apart from mongos, which infers a read preference behavior based on slaveOK, the bit seems like an implementation detail. Would it be worthwhile to revise the spec to simply allow drivers to specify slaveOK as they wish for non-mongos connections?



 Comments   
Comment by Githook User [ 02/Nov/16 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-1885 don't send slaveok to primary after mongoc_cursor_set_hint
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/b368746aa6a64fcdc49af61e287af383c5abe31c

Comment by A. Jesse Jiryu Davis [ 31/Oct/16 ]

We should do this. Hannes pointed out that for PHP to conform to Server Selection Spec, cursors have to act this way.

Comment by A. Jesse Jiryu Davis [ 25/Oct/16 ]

Single threaded: Primary steps down & closes connections, we wait socketCheckIntervalMS (default 5 sec), we try a query. We check the socket, it's closed, we reopen and query the server we thought was primary, without noticing it's a secondary. Currently, we make sure we raise an error in this case by not setting slaveOk, so the stepped-down server complains "not master".

Pooled: Primary steps down & closes connections. We create a new pooled client and open a new socket for a query. Currently, we make sure we raise an error in this case by not setting slaveOk, so the stepped-down server complains "not master".

CDRIVER-562 would be another way to fix both cases.

Generated at Wed Feb 07 21:13:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.