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

mongos should not establish a tailable cursor over an empty capped collection

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.2.0-rc0
    • Affects Version/s: 3.1.8
    • Component/s: Querying, Sharding
    • None
    • Fully Compatible
    • ALL
    • QuInt A (10/12/15)

      This is a bug in the new mongos read path, and therefore affects only the master branch.

      If a capped collection is empty, mongod will refuse to establish a tailable cursor since the position of the tailable cursor cannot be established. In this case, mongod will return a cursor id of 0 to the client. Mongos is expected to exhibit the same behavior. However, the new mongos read path establishes a broken tailable cursor that will never return any results:

      mongos> db.c.drop()
      mongos> db.createCollection("c", {capped: true, size: 1024})
      
      // This should return a cursor id of 0, but instead returns a non-zero id.
      mongos> db.runCommand({find: "c", tailable: true})
      {
      	"cursor" : {
      		"id" : NumberLong("3460288308744221894"),
      		"ns" : "test.c",
      		"firstBatch" : [ ]
      	},
      	"ok" : 1
      }
      
      // If documents are inserted into the capped collection, they will not be returned by subsequent getMores against the mongos cursor.
      mongos> db.c.insert({a: 1})
      mongos> db.c.insert({a: 1})
      mongos> db.c.insert({a: 1})
      mongos> db.c.insert({a: 1})
      mongos> db.runCommand({getMore: NumberLong("3460288308744221894"), collection: "c"})
      {
      	"cursor" : {
      		"id" : NumberLong("3460288308744221894"),
      		"ns" : "test.c",
      		"nextBatch" : [ ]
      	},
      	"ok" : 1
      }
      

            Assignee:
            yunhe.wang YunHe Wang
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: