Noticed on ADS 14-beta-55.
After connecting ADS to a 3 member replica set (with 1 primary and 2 secondaries) with slaveOK=true, I initiated the mongoshell and it displayed
1) rs1:SECONDARY> as the prompt indicating that I am connected to secondary.I further confirmed it by executing db.serverStatus().host that displayed ravi-laptop:27024 which is indeed a secondary. (Pls refer to attached replication_status.png)
2) But when I tried to insert into a collection connected to the secondary:
db.uta.insert({cat:"kids"})
it allowed the operation without complaining that I am not connected to the master(primary). (Pls refer to attached insert_on_sec.png)
If I repeat this same action on real mongo shell, it will not allow me to insert via secondary member and displays 'not master' message even if slaveOk is set to true. (Pls refer to real_shell.png)
Could you please investigate what's happening here? Thanks
|
132 KB
|
139 KB
|
22 KB
It depends on how you connect the native mongodb cli. If you specify a single host in the connect string, then it connects as "stand-alone"; in this mode, you have to be connected to the PRIMARY to insert data. If you specify multiple hosts in the connect string, then it connects as "replicaset" mode; in this mode, between the driver and mongodb, write operations will be directed to the PRIMARY even if the currently connected node is SECONDARY.
Example:
n@nmain:~$ mongo localhost:27019,localhost:27018,localhost:27017/test MongoDB shell version: 2.4.4 connecting to: localhost:27019,localhost:27018,localhost:27017/test Mon Jul 8 13:38:33.545 SyncClusterConnection connecting to [localhost:27019] Mon Jul 8 13:38:33.545 SyncClusterConnection connecting to [localhost:27018] Mon Jul 8 13:38:33.546 SyncClusterConnection connecting to [localhost:27017] rs0:SECONDARY> rs.status() { "set" : "rs0", "date" : ISODate("2013-07-08T20:38:47Z"), "myState" : 2, "syncingTo" : "localhost:27017", "members" : [ { "_id" : 0, "name" : "localhost:27017", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 1608, "optime" : { "t" : 1373315765, "i" : 1 }, "optimeDate" : ISODate("2013-07-08T20:36:05Z"), "lastHeartbeat" : ISODate("2013-07-08T20:38:45Z"), "lastHeartbeatRecv" : ISODate("2013-07-08T20:38:47Z"), "pingMs" : 0 }, { "_id" : 1, "name" : "localhost:27018", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 26, "optime" : { "t" : 1373315765, "i" : 1 }, "optimeDate" : ISODate("2013-07-08T20:36:05Z"), "lastHeartbeat" : ISODate("2013-07-08T20:38:45Z"), "lastHeartbeatRecv" : ISODate("2013-07-08T20:38:47Z"), "pingMs" : 0, "lastHeartbeatMessage" : "syncing to: localhost:27017", "syncingTo" : "localhost:27017" }, { "_id" : 2, "name" : "localhost:27019", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 1608, "optime" : { "t" : 1373315765, "i" : 1 }, "optimeDate" : ISODate("2013-07-08T20:36:05Z"), "self" : true } ], "ok" : 1 } rs0:SECONDARY> db.uta.find() error: { "$err" : "not master and slaveOk=false", "code" : 13435 } rs0:SECONDARY> rs.slaveOk() rs0:SECONDARY> db.uta.find() { "_id" : ObjectId("51db1e16a7d24495cd8d8183"), "cat" : "kids" } { "_id" : ObjectId("51db22b5e929e4646eac126a"), "cat" : "kids 2" } rs0:SECONDARY> db.uta.insert({cat:"kids 3"}) rs0:SECONDARY> db.uta.find() { "_id" : ObjectId("51db1e16a7d24495cd8d8183"), "cat" : "kids" } { "_id" : ObjectId("51db22b5e929e4646eac126a"), "cat" : "kids 2" } { "_id" : ObjectId("51db237392dd55b8782fed20"), "cat" : "kids 3" } rs0:SECONDARY>
Issue #9533 |
Closed |
Invalid |
Resolved |
Completion |
No due date |
No fixed build |
No time estimate |
It depends on how you connect the native mongodb cli. If you specify a single host in the connect string, then it connects as "stand-alone"; in this mode, you have to be connected to the PRIMARY to insert data. If you specify multiple hosts in the connect string, then it connects as "replicaset" mode; in this mode, between the driver and mongodb, write operations will be directed to the PRIMARY even if the currently connected node is SECONDARY.
Example: