Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-51835

Mongos readPreferenceTags are not working as expected

    XMLWordPrintable

    Details

    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      Reproduce from mongo shell:

      1. db.getMongo().setReadPref('nearest', [ { "something": "x", "region": "a" } ])
      2. db.getMongo().setReadPref('nearest', [ { "something": "x", "region": "a" }, {"something": "x"} ])

      db.getCollection('mytest').find({ _id: ObjectId("my-object-id") });

      Get expected results with 1. option. While using 2. setting, I can see that query is executed in random node matching second tag.
      Works as expected (as documentation says) with MongoDB version 4.2 but not starting with 4.4

      Show
      Reproduce from mongo shell: 1 . db.getMongo().setReadPref( 'nearest' , [ { "something" : "x" , "region" : "a" } ]) 2 . db.getMongo().setReadPref( 'nearest' , [ { "something" : "x" , "region" : "a" }, { "something" : "x" } ]) db.getCollection( 'mytest' ).find({ _id: ObjectId( "my-object-id" ) }); Get expected results with 1. option. While using 2. setting, I can see that query is executed in random node matching second tag. Works as expected (as documentation says) with MongoDB version 4.2 but not starting with 4.4

      Description

      From documentation:

      Order matters when using multiple readPreferenceTags. The readPreferenceTags are tried in order until a match is found. Once found, that specification is used to find all eligible matching members and any remaining readPreferenceTags are ignored.

      This isn't true in 4.4 anymore when using multiple readPreferenceTags as a fallback. 

      Seems part of code location has shifted and that is the reason that readPreferenceTags behavior has changed. Or there could be other major changes with the code how matching is done regard with tags.

      In 4.4 >

      https://github.com/mongodb/mongo/blob/v4.4/src/mongo/client/scanning_replica_set_monitor.cpp#L1236-L1250 
      In 4.2 >
      https://github.com/mongodb/mongo/blob/v4.2/src/mongo/client/replica_set_monitor.cpp#L1149 

        Attachments

          Activity

            People

            Assignee:
            backlog-server-sharding-nyc Backlog - Sharding NYC
            Reporter:
            andres.pihlak@heathmont.net Andres P
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Dates

              Created:
              Updated: