Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion ReplicaSet configuration for reads/writes
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Nik Kolev  
View profile  
 More options Oct 30 2012, 3:11 pm
From: Nik Kolev <nko...@gmail.com>
Date: Tue, 30 Oct 2012 12:11:37 -0700 (PDT)
Local: Tues, Oct 30 2012 3:11 pm
Subject: Re: [mongodb-csharp] ReplicaSet configuration for reads/writes

OK. Couldn't get to it on Monday - it was Sandy times. Anyways after some
breakpointing and messing with the status of the nodes in my replca set I
am pretty sure I know what's going on.
- To recap my env, I have a 3-node replica set with 2 "real" nodes and 1
"arbiter". I am using a 1.6.0.4624 driver and a 2.2.0 mongo.
- The problem occurs with the same underlying reason regardless of whether
the ReadPreference is Primary or PrimaryPreferred.
- The problem occurs when the first instance of the MongoServerAddress-es
enumerable I am passing as the value to the Servers property of the
MongoServerSettings the MongoServer is created with is the secondary mongod.
- In both readPreference cases, the Instances array of the MongoServer
object contained just one MongoServerInstance which was pointing to the
secondary mongod. The InstanceType was ReplicaSetMember. The
ReplicaSetInformation was correctly identifying the replica set name, how
many members there were in the replica set, and what the primary member
was. I can post a screenshot of the state I am describing here later today
(as certain things are blocked at w$rk).

Unfortunately things did not get better with the 1.6.1 version of the
driver. The same issue exists there.

On Friday, October 26, 2012 2:39:37 PM UTC-4, Nik Kolev wrote:

> Thanks Robert. I'll try to get to this in the next couple of hours. If I
> don't I'll send update with my findings on Monday.

> On Friday, October 26, 2012 10:09:58 AM UTC-4, Robert Stam wrote:

>> In 1.6 it was possible for ReadPreference.PrimaryPreferred to use a
>> Secondary even if the Primary was available if the primary's ping time was
>> more than 15 ms slower than the primary. In 1.6.1 PrimaryPreferred will
>> always use the Primary if possible, and only use a Secondary if there is no
>> Primary (regardless of ping times). That could explain your first result.

>> The second result is harder to explain. It looks like you are connecting
>> directly to a secondary, because the ReadPreference appears to be ignored,
>> which only happens when connecting directly to a server.

>> Can you make sure you are actually connecting to the replica set in
>> replica set mode? One way you could do that is to put a breakpoint on your
>> call that is throwing the exception and checking the MongoServer.Instances
>> property and reporting back how many entries the Instances array has and
>> what the InstanceType is for each instance.

>> You could also check your MongoCursor.ReadPreference just before
>> executing the query to verify that the cursor has the ReadPreference you
>> wanted. In order to examine the cursor you might have to introduce an
>> intermediate variable.

>> Let me know what you find and we can proceed from there.

>> On Thu, Oct 25, 2012 at 5:39 PM, Nik Kolev <nko...@gmail.com> wrote:

>>> Environment:
>>> - host: Windows 7
>>> - mongod: v2.2 (mongodb-win32-x86_64-2008plus-2.2.0)
>>> - mongo setup: 3 mongod processes running on the same host in a replica
>>> set, 2 real and 1 arbiter
>>> - csharp driver: v.1.6.0.4624

>>> I create a MongoServer by providing a MongoServerSetings with the
>>> following properties:
>>> - SafeMode = SafeMode.True
>>> - Servers = a collecttion of all 3 mongods' MongoServerAddress-es
>>> - ReadPreference = PrimaryPrefered

>>> I have a function that asks the MongoServer for a collection
>>> (MongoCollection) of a database, first does a read on the collection and
>>> then attempts to do a write. The read succeeds but the write fails with the
>>> following stack trace (wrapped as JSON doc as Mongo in this case is backing
>>> a web service - please excuse the ugliness):
>>> ===
>>> {"responseStatus":{"errorCode":"MongoSafeModeException","message":"Safemode
>>> detected an error 'not master'. (Response was { \"err\" : \"not master\",
>>> \"code\" : 10056, \"n\" : 0, \"lastOp\" : { \"$timestamp\" : NumberLong(0)
>>> }, \"connectionId\" : 1569, \"ok\" : 1.0 }).","stackTrace":"[ById:
>>> 10/25/2012 8:53:40 PM]:\n[REQUEST:
>>> {id:1}]MongoDB.Driver.MongoSafeModeException: Safemode detected an error
>>> 'not master'. (Response was { \"err\" : \"not master\", \"code\" : 10056,
>>> \"n\" : 0, \"lastOp\" : { \"$timestamp\" : NumberLong(0) },
>>> \"connectionId\" : 1569, \"ok\" : 1.0 }).\r\n   at
>>> MongoDB.Driver.Internal.MongoConnection.SendMessage(MongoRequestMessage
>>> message, SafeMode safeMode, String databaseName) in
>>> C:\\work\\rstam\\mongo-csharp-driver\\Driver\\Internal\\MongoConnection.cs: line
>>> 549\r\n   at MongoDB.Driver.MongoCollection.Remove(IMongoQuery query,
>>> RemoveFlags flags, SafeMode safeMode) in
>>> C:\\work\\rstam\\mongo-csharp-driver\\Driver\\Core\\MongoCollection.cs:line
>>> 1312\r\n   at MongoDB.Driver.MongoCollection.Remove(IMongoQuery query) in
>>> C:\\work\\rstam\\mongo-csharp-driver\\Driver\\Core\\MongoCollection.cs:line
>>> 1272
>>> ===

>>> What's

>>> Guessing here the collection when initially obtained was backed by a
>>> connection to the slave replica and that's why the read succeeded but the
>>> write did not. If that's the case how would one use the driver for such
>>> scenarios?

>>> Moreover, going with my guess I changed the read preference to Primary
>>> (just Primary). Then even more weirdness happened. I got an exception even
>>> before the write was attempted, but when the function was trying to do the
>>> read:
>>> ===
>>> {"responseStatus":{"errorCode":"MongoQueryException","message":"QueryFailur e
>>> flag was not master and slaveOk=false (response was { \"$err\" : \"not
>>> master and slaveOk=false\", \"code\" : 13435 }).","stackTrace":"[ById:
>>> 10/25/2012 9:05:30 PM]:\n[REQUEST:
>>> {id:1}]MongoDB.Driver.MongoQueryException: QueryFailure flag was not master
>>> and slaveOk=false (response was { \"$err\" : \"not master and
>>> slaveOk=false\", \"code\" : 13435 }).\r\n   at
>>> MongoDB.Driver.Internal.MongoReplyMessage`1.ReadFrom(BsonBuffer buffer,
>>> IBsonSerializationOptions serializationOptions) in
>>> C:\\work\\rstam\\mongo-csharp-driver\\Driver\\Internal\\MongoReplyMessage.c s:line
>>> 99\r\n   at
>>> MongoDB.Driver.Internal.MongoConnection.ReceiveMessage[TDocument](BsonBinar yReaderSettings
>>> readerSettings, IBsonSerializationOptions serializationOptions) in
>>> C:\\work\\rstam\\mongo-csharp-driver\\Driver\\Internal\\MongoConnection.cs: line
>>> 475\r\n   at
>>> MongoDB.Driver.MongoCursorEnumerator`1.GetReply(MongoConnection connection,
>>> MongoRequestMessage message) in
>>> C:\\work\\rstam\\mongo-csharp-driver\\Driver\\Core\\MongoCursorEnumerator.c s:line
>>> 296\r\n   at MongoDB.Driver.MongoCursorEnumerator`1.GetFirst() in
>>> C:\\work\\rstam\\mongo-csharp-driver\\Driver\\Core\\MongoCursorEnumerator.c s:line
>>> 253\r\n   at MongoDB.Driver.MongoCursorEnumerator`1.MoveNext() in
>>> C:\\work\\rstam\\mongo-csharp-driver\\Driver\\Core\\MongoCursorEnumerator.c s:line
>>> 141
>>> ===

>>> I see the error in the mongod's log (this is the SECONDARY mongod's log):
>>> ===
>>> Thu Oct 25 22:05:30 [conn1665] assertion 13435 not master and
>>> slaveOk=false ns:mdm.policies query:{ ids: "1" }
>>> Thu Oct 25 22:05:30 [conn1665] problem detected during query over
>>> mdm.policies : { $err: "not master and slaveOk=false", code: 13435 }
>>> ===
>>> FWIW I don't see the first error I discussed captured in one shape or
>>> another in the mongod's logs - I checked in the logs for all 3 of my mongod
>>> processes.

>>> I assumed that setting the ReadPreference to Primary would let the
>>> driver know that all connections need to be asked of the primary mongod. I
>>> guess that's not what happened here for me?

>>> Ideas/Suggestions/Recs would be greatly appreciated.

>>> Thanks, -nik


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.