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

Error message for read-commands on secondary should suggest slaveOk

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Trivial - P5
    • Resolution: Fixed
    • Affects Version/s: 2.8.0-rc1
    • Fix Version/s: 3.1.0
    • Component/s: Replication
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Steps To Reproduce:
      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
    • Sprint:
      RPL 0 3/13/15

      Description

      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" }

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: