-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 2.11.1
-
Component/s: Cluster Management, Connection Management
-
None
Although slaveOk() is deprecated, if it is in use the expectation is it should behave the same as setting ReadPreference.secondaryPreferred();
Instead the queries are seen with { $readPreference:
{ mode: "primary" }} explicitly set when going through a mongos
Under 2.6 the following java sample will correctly result in a query to a Secondary. The same code in 2.7 or above will result with the primary $readPreference set.
import com.mongodb.*; import java.net.UnknownHostException; public class TestSlaveOK{ public static void main(String[] args){ Mongo m = null; DB db = null; DBCollection coll = null; try{ MongoOptions mongoOptions = new MongoOptions(); mongoOptions.slaveOk = true; m = new Mongo("localhost:27017", mongoOptions); db = m.getDB("test"); } catch(UnknownHostException uhe){ System.out.println("UnknownHostException:" + uhe); } coll = db.getCollection("test"); DBObject query = new BasicDBObject("x", "100"); DBObject obj = coll.findOne(query, null); } }
Looking at the highest verbosity logs (or capturing the query in another way) under 2.11.1 will show the query executed with { $readPreference:
{ mode: "primary" }} on both the mongos and the Primary node:
Tue Apr 23 16:37:37 [conn28] shard query: test.test { $query: { x: "100" }, $readPreference: { mode: "primary" } }