[CSHARP-370] Setting a node as Hidden doesn't propagate to C# drivers Created: 22/Dec/11  Updated: 02/Apr/15  Resolved: 20/Mar/12

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.3.1
Fix Version/s: 1.4

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

Windows 7 x64


Issue Links:
Depends
Related
is related to CSHARP-201 When connected to a replica set a bac... Closed

 Description   

While running an application, if you set a replica node as hidden before the thread the application is running on exits, the node will still be listed as a viable secondary.

Steps to reproduce:

  • Create a MongoDB replica set with at least one server on port 27019
  • Run the code here https://gist.github.com/56ca0ad073ed7f2be257
  • While the code is running you should see output of the current secondaries it knows about
  • While the code is running still, connect to the primary MongoDB node and run...
  • rs.status()
  • Find a secondary node and take note of its index (I used 1)
  • config = rs.conf()
  • config.members[1].priority = 0
  • config.members[1].hidden = true
  • rs.reconfig(config)

This will set member 1 to be now hidden. However the application can still see it as a viable secondary as seen by the application output. If you re run the application you will see it's missing from the list of secondary candidates, as it should be.

If you were to take the server offline completely while the app is running you'll see it gets removed from the list of viable secondaries. You can also call server.Reconnect() and this will update the list correctly.



 Comments   
Comment by Robert Stam [ 20/Mar/12 ]

The driver now uses the response to isMaster (from the primary only, that being considered the source of truth) to dynamically detect (without requiring Reconnect to be called) whether members have been added or removed from the replica set.

Comment by Robert Stam [ 20/Mar/12 ]

The server is supposed to reply to isMaster with

{ secondary : false }

when a secondary is in recovering mode. That is enough to keep to the driver from sending queries to that secondary.

If the server is not accurately setting

{ secondary : false }

then we can either address it at the server level, or if necessary the C# driver could call the replSetGetStatus command to get more detailed information about the member status, but that would require an additional round trip to the server.

Comment by Chad Moran [ 23/Dec/11 ]

Robert, I assume this will also fix nodes that go into/come out of Recovery, also?

Comment by Robert Stam [ 23/Dec/11 ]

Chad, I agree with that approach.

Comment by Chad Moran [ 23/Dec/11 ]

I think adding IsHidden and still including it in the list of Secondaries would be best. Then having it know that it's hidden and not to send reads to it.

Comment by Robert Stam [ 23/Dec/11 ]

A similar issue would occur if a replica set member is added or removed while the C# driver is connected to the replica set. The change won't be noticed until the driver reconnects.

A related question is whether a hidden replica set member should be included in the set of server instances returned by MongoServer.Instances. If so, we should add an IsHidden property to MongoServerInstance so client code can tell that it's a hidden replica set member. In other words, is being hidden so absolute that client code can't even see the member, or is hidden just a behavioral mode that means reads shouldn't be sent to it.

Comment by Chad Moran [ 22/Dec/11 ]

Note, this was with server 2.0.2 and driver 1.3.1

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