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

slaveOk bit ignored for unsharded aggregate

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.4.7, 2.5.3
    • Component/s: Aggregation Framework
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      With this script the aggregate command is always sent to the primary:

      var st = new ShardingTest({ shards: { rs0: { oplogSize: 10, verbose: 1 }}});                                                                                                                                                                 
                                                                                                                                                                                                                                                   
      var testDB = st.s.getDB('test');                                                                                                                                                                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                   
      testDB.user.insert({ x: 10 });                                                                                                                                                                                                               
                                                                                                                                                                                                                                                   
      testDB.setSlaveOk(true);                                                                                                                                                                                                                     
      var res = testDB.runCommand({ aggregate: 'user', pipeline: [{ $project: { x: 1 }}]});                                                                                                                                                        
      jsTest.log(tojson(res));                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                   
      st.stop();

      Sharding the collection causes mongos to respect the slaveOk bit.

      var st = new ShardingTest({ shards: { rs0: { oplogSize: 10, verbose: 1 }}});                                                                                                                                                                 
                                                                                                                                                                                                                                                   
      var testDB = st.s.getDB('test');                                                                                                                                                                                                             
      testDB.adminCommand({ enableSharding: 'test' });                                                                                                                                                                                             
      testDB.adminCommand({ shardCollection: 'test.user', key: { x: 1 }});                                                                                                                                                                         
                                                                                                                                                                                                                                                   
      testDB.user.insert({ x: 10 });                                                                                                                                                                                                               
                                                                                                                                                                                                                                                   
      testDB.setSlaveOk(true);                                                                                                                                                                                                                     
      var res = testDB.runCommand({ aggregate: 'user', pipeline: [{ $project: { x: 1 }}]});                                                                                                                                                        
      jsTest.log(tojson(res));                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                   
      st.stop();      

      Show
      With this script the aggregate command is always sent to the primary: var st = new ShardingTest({ shards: { rs0: { oplogSize: 10, verbose: 1 }}}); var testDB = st.s.getDB('test'); testDB.user.insert({ x: 10 }); testDB.setSlaveOk(true); var res = testDB.runCommand({ aggregate: 'user', pipeline: [{ $project: { x: 1 }}]}); jsTest.log(tojson(res)); st.stop(); Sharding the collection causes mongos to respect the slaveOk bit. var st = new ShardingTest({ shards: { rs0: { oplogSize: 10, verbose: 1 }}}); var testDB = st.s.getDB('test'); testDB.adminCommand({ enableSharding: 'test' }); testDB.adminCommand({ shardCollection: 'test.user', key: { x: 1 }}); testDB.user.insert({ x: 10 }); testDB.setSlaveOk(true); var res = testDB.runCommand({ aggregate: 'user', pipeline: [{ $project: { x: 1 }}]}); jsTest.log(tojson(res)); st.stop();

      Description

      Issue Status as of October 9th, 2013

      ISSUE SUMMARY
      The aggregate command only respects the slaveOk bit if the collection the aggregate command is run against is sharded. For unsharded collections aggregate is always sent to the primary.

      USER IMPACT
      This only impacts unsharded collections in a sharded cluster. A user can inadvertently send aggregate commands via mongos to unsharded collections to a primary replica set member when they were intended for a secondary member. This could cause unexpected load on the shard primary node and impact performance. It is present in versions of MongoDB prior to and including v2.4.6.

      SOLUTION
      Pass the query options to the aggregate command

      WORKAROUNDS
      No workaround.

      PATCHES
      Production release v2.4.7 contains the fix for this issue, and production release v2.6.0 will contain the fix as well.

      Original Description

      The summary says it all. The aggregate command only respects the slaveOk bit if the collection the aggregate command is run against is sharded. For unsharded collections aggregate is always sent to the primary.

      The problem only seems to exist with the aggregate command. Commands like count and distinct seem to respect slaveOk properly.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              renctan Randolph Tan
              Reporter:
              behackett Bernie Hackett
              Participants:
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: