[CSHARP-450] SlaveOk and connection pooling Created: 19/Apr/12  Updated: 05/Apr/19  Resolved: 19/Apr/12

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.4.2
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Aristarkh Zagorodnikov Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: question
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Currently, servers are "pooled" (MongoServer.__servers) by MongoServerSettings. This leads to separate MongoServer instances to be created for different SlaveOk values, leading to having two connection pools for one server that was initialized with different slaveOk values. This by itself is perfectly fine. But, it appears that server "slaveOk" parameter is not used when appropriate connection is searched. Let me illustrate with an example.
I create server 1 with connection string that specifies slaveOk as "false" (the default one), then create a database, collection, and then open a cursor that has slaveOk set to true. This leads to connection pool of server that is marked as "not slaveOk" to contain connection that is "slaveOk". While this is not an error, I still would like to ask if this is intentional, since this is a bit misleading when debugging.



 Comments   
Comment by Aristarkh Zagorodnikov [ 19/Apr/12 ]

Thanks for the clarification and for the recommendation, Robert. We already set slaveOk on operation basis in about 80% of the cases, so it won't be an issue.

Comment by Robert Stam [ 19/Apr/12 ]

Yes, it is intentional. There is nothing about a connection (a socket) that is related to slaveOk. SlaveOk is simply used to pick which server to send the query to.

Since slaveOk reads are less frequent than regular reads, I would recommend setting slaveOk to false on the connection string (the default) and only set slaveOk to true on individual read operations where you want to read from a slave.

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