[CSHARP-128] find(..) query with MongoServer.Create("...?slaveok=true") will always throw "not master" Created: 07/Dec/10  Updated: 02/Apr/15  Resolved: 01/Feb/11

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 0.9
Fix Version/s: 0.11

Type: Bug Priority: Major - P3
Reporter: huy nguyen Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 7 C# .net 3.5 driver version 10gen driver v0.9.
MongoDB server for linux version 1.6.3 running in a 2 nodes replica set with 2 arbiters (all running on centOS 5.5 VM)



 Description   

//begin code
var m = MongoServer.Create("mongodb://192.168.1.110:27117,192.168.1.112:27117/cache?replicaset=cacheset&slaveok=true");

var col = m["cache"]["flatdoc"];
var q = Query.In("_id", BsonArray.Create(new[]

{ 1,2,3 }

));

//this will throw: not master
var res = (from d in col.Find(q) select d).ToList();

//this will also throw: not master
res = (from d in col.Find(q).SetFlags(QueryFlags.SlaveOk) select d).ToList();

//end code
/*
The only way for this to not throw is to exclude slaveok=true from mongo url and
calling SetFlags(QueryFlags.SlaveOk) on the cursor before use.

I hope this helps
*/



 Comments   
Comment by Robert Stam [ 01/Feb/11 ]

Please reopen this issue if you are able to reproduce it.

Comment by Robert Stam [ 27/Dec/10 ]

Are you still seeing this? The rs.status() looks normal. We would have to see the rs.status() values at the time of a failure.

Comment by huy nguyen [ 07/Dec/10 ]

Just in case, here's the status of arbiter 1:

connecting to: 192.168.1.110:27118/test
> rs.isMaster()
{
"setName" : "cacheset",
"ismaster" : false,
"secondary" : false,
"hosts" : [
"192.168.1.112:27117",
"192.168.1.110:27117"
],
"arbiters" : [
"192.168.1.110:27118",
"192.168.1.112:27118"
],
"primary" : "192.168.1.110:27117",
"arbiterOnly" : true,
"ok" : 1
}
> rs.status()
{
"set" : "cacheset",
"date" : "Tue Dec 07 2010 09:55:40 GMT-0800 (Pacific Standard Time)",
"myState" : 7,
"members" : [

{ "_id" : 2, "name" : "192.168.1.110:27117", "health" : 1, "state" : 1, "uptime" : 2833486, "lastHeartbeat" : "Tue Dec 07 2010 09:55:40 GMT-0800 (Pacific Standard Time)" }

,

{ "_id" : 3, "name" : "vm-jcorb-1.docstoc.corp:27118", "health" : 1, "state" : 7, "self" : true }

,

{ "_id" : 4, "name" : "192.168.1.112:27118", "health" : 1, "state" : 7, "uptime" : 4131052, "lastHeartbeat" : "Tue Dec 07 2010 09:55:39 GMT-0800 (Pacific Standard Time)" }

,

{ "_id" : 5, "name" : "192.168.1.112:27117", "health" : 1, "state" : 2, "uptime" : 2833354, "lastHeartbeat" : "Tue Dec 07 2010 09:55:39 GMT-0800 (Pacific Standard Time)" }

],
"ok" : 1
}

and for arbiter 2:

connecting to: 192.168.1.112:27118/test
> rs.isMaster()
{
"setName" : "cacheset",
"ismaster" : false,
"secondary" : false,
"hosts" : [
"192.168.1.112:27117",
"192.168.1.110:27117"
],
"arbiters" : [
"192.168.1.112:27118",
"192.168.1.110:27118"
],
"primary" : "192.168.1.110:27117",
"arbiterOnly" : true,
"ok" : 1
}
> rs.status()
{
"set" : "cacheset",
"date" : "Tue Dec 07 2010 09:47:03 GMT-0800 (Pacific Standard Time)",
"myState" : 7,
"members" : [

{ "_id" : 2, "name" : "192.168.1.110:27117", "health" : 1, "state" : 1, "uptime" : 2833166, "lastHeartbeat" : "Tue Dec 07 2010 09:47:02 GMT-0800 (Pacific Standard Time)" }

,

{ "_id" : 3, "name" : "192.168.1.110:27118", "health" : 1, "state" : 7, "uptime" : 4130536, "lastHeartbeat" : "Tue Dec 07 2010 09:47:02 GMT-0800 (Pacific Standard Time)" }

,

{ "_id" : 4, "name" : "vm-sandbox-1.docstoc.local:27118", "health" : 1, "state" : 7, "self" : true }

,

{ "_id" : 5, "name" : "192.168.1.112:27117", "health" : 1, "state" : 2, "uptime" : 2833035, "lastHeartbeat" : "Tue Dec 07 2010 09:47:01 GMT-0800 (Pacific Standard Time)" }

],
"ok" : 1
}

Comment by huy nguyen [ 07/Dec/10 ]

Robert,

On the master of this replica (192.168.1.110:27117) set here is what I see:
> rs.isMaster()
{
"setName" : "cacheset",
"ismaster" : true,
"secondary" : false,
"hosts" : [
"192.168.1.110:27117",
"192.168.1.112:27117"
],
"arbiters" : [
"192.168.1.112:27118",
"192.168.1.110:27118"
],
"ok" : 1
}
> rs.status()
{
"set" : "cacheset",
"date" : "Tue Dec 07 2010 09:43:59 GMT-0800 (Pacific Standard Time)",
"myState" : 1,
"members" : [

{ "_id" : 2, "name" : "vm-jcorb-1.docstoc.corp:27117", "health" : 1, "state" : 1, "self" : true }

,

{ "_id" : 3, "name" : "192.168.1.110:27118", "health" : 1, "state" : 7, "uptime" : 2832784, "lastHeartbeat" : "Tue Dec 07 2010 09:43:59 GMT-0800 (Pacific Standard Time)" }

,

{ "_id" : 4, "name" : "192.168.1.112:27118", "health" : 1, "state" : 7, "uptime" : 2832784, "lastHeartbeat" : "Tue Dec 07 2010 09:43:58 GMT-0800 (Pacific Standard Time)" }

,

{ "_id" : 5, "name" : "192.168.1.112:27117", "health" : 1, "state" : 2, "uptime" : 2832654, "lastHeartbeat" : "Tue Dec 07 2010 09:43:58 GMT-0800 (Pacific Standard Time)" }

],
"ok" : 1
}
> db.stats()
{
"collections" : 5,
"objects" : 6607461,
"avgObjSize" : 660.6603565272652,
"dataSize" : 4365287540,
"storageSize" : 4686907392,
"numExtents" : 32,
"indexes" : 7,
"indexSize" : 2059685632,
"fileSize" : 10666115072,
"ok" : 1
}

On the slave (192.168.1.112:27117), I see this:

> rs.isMaster()
{
"setName" : "cacheset",
"ismaster" : false,
"secondary" : true,
"hosts" : [
"192.168.1.112:27117",
"192.168.1.110:27117"
],
"arbiters" : [
"192.168.1.112:27118",
"192.168.1.110:27118"
],
"primary" : "192.168.1.110:27117",
"ok" : 1
}
> rs.status()
{
"set" : "cacheset",
"date" : "Tue Dec 07 2010 09:41:41 GMT-0800 (Pacific Standard Time)",
"myState" : 2,
"members" : [

{ "_id" : 2, "name" : "192.168.1.110:27117", "health" : 1, "state" : 1, "uptime" : 2832712, "lastHeartbeat" : "Tue Dec 07 2010 09:41:40 GMT-0800 (Pacific Standard Time)" }

,

{ "_id" : 3, "name" : "192.168.1.110:27118", "health" : 1, "state" : 7, "uptime" : 2832712, "lastHeartbeat" : "Tue Dec 07 2010 09:41:40 GMT-0800 (Pacific Standard Time)" }

,

{ "_id" : 4, "name" : "192.168.1.112:27118", "health" : 1, "state" : 7, "uptime" : 2832712, "lastHeartbeat" : "Tue Dec 07 2010 09:41:39 GMT-0800 (Pacific Standard Time)" }

,

{ "_id" : 5, "name" : "vm-sandbox-1.docstoc.local:27117", "health" : 1, "state" : 2, "self" : true }

],
"ok" : 1
}
> db.stats()
{
"collections" : 5,
"objects" : 6607461,
"avgObjSize" : 668.0890799052768,
"dataSize" : 4414372540,
"storageSize" : 6874664448,
"numExtents" : 37,
"indexes" : 7,
"indexSize" : 1850229696,
"fileSize" : 12812550144,
"ok" : 1
}

I will continue to investigate this issue on my side (reboot all the mongo nodes) and do additional tests. I'll keep you posted.

--Huy

Comment by Robert Stam [ 07/Dec/10 ]

I cannot reproduce this. I have a similar test program with a 2 node replica set, and verified just now that it is still working (that reads are routed to the secondary and that no exception is thrown).

When you remove "slaveok=true" from the URL it no longer uses the secondaries at all (even if you set SlaveOk on the cursor). So I suspect your secondary may be in some unusual state that is preventing it from responding to queries.

Can you repeat this test and call "rs.status()" from the mongo shell (from two shells actually, one for each node) so that we can see what state the replica set nodes are in? I don't think we need the state of the arbiters, but it wouldn't hurt.

Generated at Wed Feb 07 21:35:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.