[JAVA-1049] Ensure that commands and queries set slaveOk bit and readPreference Created: 12/Nov/13  Updated: 31/Mar/15  Resolved: 01/May/14

Status: Closed
Project: Java Driver
Component/s: Query Operations
Affects Version/s: None
Fix Version/s: 3.0.0

Type: Bug Priority: Critical - P2
Reporter: Jeffrey Yemin Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Both queries and "query-like" commands require two things to enable proper application of a non-primary read preference:

  1. set slaveOk bit if slaveOk is set (deprecated) or ReadPreference.isSlaveOk().
  2. Wrap in $query and set $readPreference field (mongos only, and only if read preference is not primary or secondaryPreferred).

Example of an integration test that should pass:

class CountOperationSpecification {
    def 'should run on secondary'() {
        assumeTrue(isDiscoverableReplicaSet())
 
        given:
        def find = new Find().readPreference(ReadPreference.secondary())
        def countOperation = new CountOperation(getNamespace(), find, new DocumentCodec(), bufferProvider, session, true)
 
        when:
        int count = countOperation.execute()
 
        then:
        count == 0
    }
}



 Comments   
Comment by Jeffrey Yemin [ 31/Mar/15 ]

Closing all resolved 3.0.0 issues, as 3.0.0 has been tagged and released.

Comment by Jeffrey Yemin [ 01/May/14 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: Moved extension methods out of OperationHelper and into CommandOperationHelper and QueryOperationHelper
Branch: 3.0.x
https://github.com/mongodb/mongo-java-driver/commit/2e5678b15b20e5ee7a1d5b4d22929bf091b0cf21

Generated at Thu Feb 08 08:53:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.