-
Type: Bug
-
Resolution: Done
-
Priority: Trivial - P5
-
Affects Version/s: 2.8.0-rc1
-
Component/s: Replication
-
None
-
Fully Compatible
-
ALL
-
- Start 2 node replica set
- Wait for members to be primary and secondary
- Connect to secondary
- 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" }
- related to
-
SERVER-15994 listIndexes and listCollections can be run on secondaries without slaveOk bit
- Closed