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

Secondaries execute distinct/aggregate commands irrespective of slaveOk bit

    • ALL
    • Hide

      I have a test.foo database, which contains a single document, in a replica set. I then connect to a secondary of that replica set in standalone mode:

      REPLICASET:SECONDARY> db.runCommand({distinct:"foo",key:"x"})
      {
      	"values" : [
      		NumberLong(1)
      	],
      	"stats" : {
      		"n" : 1,
      		"nscanned" : 1,
      		"nscannedObjects" : 1,
      		"timems" : 0,
      		"cursor" : "BasicCursor"
      	},
      	"ok" : 1
      }
      
      REPLICASET:SECONDARY> db.runCommand({aggregate:"foo",pipeline:[{$match:{x:1}}]})
      {
      	"result" : [
      		{
      			"_id" : ObjectId("5176e98ce84df1db0e30f327"),
      			"x" : NumberLong(1)
      		}
      	],
      	"ok" : 1
      }
      

      Map/reduce and count commands both fail unless I set slaveOk:

      REPLICASET:SECONDARY> db.runCommand({count:"foo"})
      { "errmsg" : "not master", "note" : "from execCommand", "ok" : 0 }
      
      REPLICASET:SECONDARY> db.runCommand({mapReduce:"foo",map:function(){},reduce:function(){},out:{inline:true}})
      { "errmsg" : "not master", "note" : "from execCommand", "ok" : 0 }
      
      REPLICASET:SECONDARY> rs.slaveOk(true)
      
      REPLICASET:SECONDARY> db.runCommand({count:"foo"})
      { "n" : 1, "ok" : 1 }
      
      REPLICASET:SECONDARY> db.runCommand({mapReduce:"foo",map:function(){},reduce:function(){},out:{inline:true}})
      {
      	"results" : [ ],
      	"timeMillis" : 17,
      	"counts" : {
      		"input" : 1,
      		"emit" : 0,
      		"reduce" : 0,
      		"output" : 0
      	},
      	"ok" : 1
      }
      
      Show
      I have a test.foo database, which contains a single document, in a replica set. I then connect to a secondary of that replica set in standalone mode: REPLICASET:SECONDARY> db.runCommand({distinct: "foo" ,key: "x" }) { "values" : [ NumberLong(1) ], "stats" : { "n" : 1, "nscanned" : 1, "nscannedObjects" : 1, "timems" : 0, "cursor" : "BasicCursor" }, "ok" : 1 } REPLICASET:SECONDARY> db.runCommand({aggregate: "foo" ,pipeline:[{$match:{x:1}}]}) { "result" : [ { "_id" : ObjectId( "5176e98ce84df1db0e30f327" ), "x" : NumberLong(1) } ], "ok" : 1 } Map/reduce and count commands both fail unless I set slaveOk: REPLICASET:SECONDARY> db.runCommand({count: "foo" }) { "errmsg" : "not master" , "note" : "from execCommand" , "ok" : 0 } REPLICASET:SECONDARY> db.runCommand({mapReduce: "foo" ,map:function(){},reduce:function(){},out:{inline: true }}) { "errmsg" : "not master" , "note" : "from execCommand" , "ok" : 0 } REPLICASET:SECONDARY> rs.slaveOk( true ) REPLICASET:SECONDARY> db.runCommand({count: "foo" }) { "n" : 1, "ok" : 1 } REPLICASET:SECONDARY> db.runCommand({mapReduce: "foo" ,map:function(){},reduce:function(){},out:{inline: true }}) { "results" : [ ], "timeMillis" : 17, "counts" : { "input" : 1, "emit" : 0, "reduce" : 0, "output" : 0 }, "ok" : 1 }

          Assignee:
          randolph@mongodb.com Randolph Tan
          Reporter:
          jmikola@mongodb.com Jeremy Mikola
          Votes:
          0 Vote for this issue
          Watchers:
          5 Start watching this issue

            Created:
            Updated:
            Resolved: