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

Error message for read-commands on secondary should suggest slaveOk

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Trivial - P5 Trivial - P5
    • 3.1.0
    • Affects Version/s: 2.8.0-rc1
    • Component/s: Replication
    • Labels:
      None
    • Fully Compatible
    • ALL
      1. Start 2 node replica set
      2. Wait for members to be primary and secondary
      3. Connect to secondary
      4. Run listDatabases, listCollections, and listIndexes commands
    • RPL 0 3/13/15

      Since listDatabases, listCollections and listIndexes are commands that can work on a secondary with slaveOk, their error should indicate that.

      Otherwise, the user might mistakenly believe that these commands are completely forbidden on secondaries.

      SERVER-15994 changed the behaviour of listDatabases, listCollections and listIndexes to require the slaveOk bit to be set when run on secondaries. This makes sense: since they are effectively reads that can return stale data, they should require the user to state that this is okay by setting slaveOk.

      However, the error they give is "not master":

      > db.adminCommand("listDatabases")
      { "note" : "from execCommand", "ok" : 0, "errmsg" : "not master" }
      > db.adminCommand("listCollections")
      { "note" : "from execCommand", "ok" : 0, "errmsg" : "not master" }
      > db.adminCommand("listIndexes")
      { "note" : "from execCommand", "ok" : 0, "errmsg" : "not master" }
      

      This is misleading, because it is the error used for operations that only work on the primary, such as writes:

      > db.foo.insert({})
      WriteResult({ "writeError" : { "code" : undefined, "errmsg" : "not master" } })
      

      Operations such as reads, which can work on a secondary if slaveOk is set, usually give the error "not master and slaveOk=false":

      > db.foo.find()
      error: { "$err" : "not master and slaveOk=false", "code" : 13435 }
      

      Note that querying system.namespaces and system.indexes in earlier versions (what listDatabases, listCollections and listIndexes have replaced) also return an error that mentions slaveOk:

      > db.system.namespaces.find()
      error: { "$err" : "not master and slaveOk=false", "code" : 13435 }
      > db.system.indexes.find()
      error: { "$err" : "not master and slaveOk=false", "code" : 13435 }
      

      Thus, the desired behaviour is simply to adjust the error message to include mention of slaveOk=false:

      > db.adminCommand("listDatabases")
      { "note" : "from execCommand", "ok" : 0, "errmsg" : "not master and slaveOk=false" }
      > db.adminCommand("listCollections")
      { "note" : "from execCommand", "ok" : 0, "errmsg" : "not master and slaveOk=false" }
      > db.adminCommand("listIndexes")
      { "note" : "from execCommand", "ok" : 0, "errmsg" : "not master and slaveOk=false" }
      

            Assignee:
            siyuan.zhou@mongodb.com Siyuan Zhou
            Reporter:
            kevin.pulo@mongodb.com Kevin Pulo
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: