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

documents can't be find with secondary readPref from mongos after create an sharded collection

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.4 Required
    • Component/s: None
    • None
    • ALL
    • Hide
      1. Prepare a sharded mongodb4.4 cluster with two mongos and two shards
      2.  Login mongosA,
      3.  sh.enableSharding("yc");  sh.shardCollection("yc.coll1", {a:"hashed"});
      4. insert some data; db.coll1.insert({a:1} ;db.coll1.insert({a:2} ;db.coll1.insert({a:3} ;
      5.  login mongosB,
      6. run find command to flush route of  'yc' db.
      7. use yc; db.coll1.find({a:1}); db.coll1.find({a:2}); db.coll1.find({a:3}); 
      8. Login mongosA, shard another collection
      9. sh.shardCollection("yc.coll2", {a:"hashed"}); // shard another collection
      10. insert some data; db.coll2.insert({a:1}); db.coll2.insert({a:2});db.coll2.insert({a:3})
      11. login mongosB
      12. db.getMongo().setReadPref("secondary")
      13. use yc; db.coll2.find({a:1}); db.coll2.find({a:2}); db.coll2.find({a:3}). some documents could not be found
      Show
      Prepare a sharded mongodb4.4 cluster with two mongos and two shards  Login mongosA,  sh.enableSharding("yc");  sh.shardCollection("yc.coll1", {a:"hashed"}); insert some data; db.coll1.insert({a:1} ;db.coll1.insert({a:2} ;db.coll1.insert({a:3} ;  login mongosB, run find command to flush route of  'yc' db. use yc; db.coll1.find({a:1}); db.coll1.find({a:2}); db.coll1.find({a:3});  Login mongosA, shard another collection sh.shardCollection("yc.coll2", {a:"hashed"}); // shard another collection insert some data; db.coll2.insert({a:1}); db.coll2.insert({a:2});db.coll2.insert({a:3}) login mongosB db.getMongo().setReadPref("secondary") use yc; db.coll2.find({a:1}); db.coll2.find({a:2}); db.coll2.find({a:3}). some documents could not be found

      After creating a sharded collection and inserting some documents, thoese documents  may not be read from other mongos with secondary readPref, even by setting local readConcern.

      Another mongos thinks that the table is a unsharded unshared collection and sends the request to the primaryshard, but the data may be distributed on another shard.

      And if secondary readpref is set, the request sent to the shard will not carry routing information, and will not check whether the route is dirty, so the route cannot be refreshed.

      https://github.com/mongodb/mongo/blob/r4.4.13/src/mongo/db/service_entry_point_common.cpp#L1157

       

      https://github.com/mongodb/mongo/blob/r4.4.13/src/mongo/db/s/collection_sharding_runtime.cpp#L328

       

      With local readconcern, this phenomenon still exists.

      Although the routing information is carried, the routing is empty and can pass the inspection.

       

      5.0 does not have this problem, it seems that because the code of the route cache is modified, mongos will refresh the route after receiving the first request.

       

       

       

            Assignee:
            yuan.fang@mongodb.com Yuan Fang
            Reporter:
            1321280378feng@gmail.com Chao Yin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: