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

Mongos readPreferenceTags are not working as expected

    • Sharding NYC
    • Fully Compatible
    • ALL
    • v6.3, v6.0, v5.0, v4.4
    • 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
    • Sharding NYC 2023-03-06

      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 

        1. read_pref_with_tag_order.js
          4 kB
        2. mongo.png
          mongo.png
          48 kB

            Assignee:
            max.hirschhorn@mongodb.com Max Hirschhorn
            Reporter:
            andres.pihlak@heathmont.net Andres P
            Votes:
            2 Vote for this issue
            Watchers:
            26 Start watching this issue

              Created:
              Updated:
              Resolved: