Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-1049

Ensure that commands and queries set slaveOk bit and readPreference

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Critical - P2 Critical - P2
    • 3.0.0
    • None
    • Query Operations
    • None

    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
          }
      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            jeff.yemin@mongodb.com Jeffrey Yemin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: