[CSHARP-722] Provide a method to inspect the state of a cluster Created: 09/Apr/13  Updated: 18/Aug/14  Resolved: 18/Aug/14

Status: Closed
Project: C# Driver
Component/s: API, Connectivity
Affects Version/s: 1.8
Fix Version/s: 2.0

Type: New Feature Priority: Major - P3
Reporter: Craig Wilson Assignee: Unassigned
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CSHARP-724 MongoServer.IsPrimary Would Error Whe... Closed
Epic Link: Adopt Core Library

 Description   

Currently, there isn't a friendly way to get an up-to-date state of a cluster (single server, replica set, shards). We need to provide a strongly-typed method that will invoke the appropriate server commands and aggregate the results back in an easy to use object model.



 Comments   
Comment by Robert Stam [ 21/May/13 ]

There already are properties to inspect the state of the cluster, though there are some issues to consider (see below).

The MongoServer class represents the cluster, and has the following properties and methods that expose information about the cluster:

  • Arbiters: list of arbiter nodes
  • BuildInfo: version information (taken from the primary)
  • Instances: list of all nodes
  • Passives: list of passive nodes
  • Primary: the current primary node
  • ReplicaSetName: the name of the replica set
  • Secondaries: list of secondary nodes
  • State: overall state of the cluster (Connected, etc...)
  • VerifyState: refresh the state of the cluster by polling all nodes

The MongoServerInstance class represents a node in the cluster, and has the following properties and methods that expose information about the node:

  • InstanceType: the type of node
  • Address: the IP address
  • BuildInfo: version information
  • IsArbiter: true if the node is an arbiter
  • IsMasterResult: the result of the last isMaster command
  • IsPassive: true if the node is passive
  • IsPrimary: true if the node is primary
  • IsSecondary: true if the node is secondary
  • MaxDocumentSize: max document size supported by this node
  • MaxMessageLength: max message length supported by this node
  • State: state of the node (Connected, etc...)
  • VerifyState: refresh the state of the node by polling it

The main issue to consider is that this information is all cached. This is both good and bad. The good part is that it is essentially free to query these properties because there is no round trip to the server. The bad part is that it can be slightly out of date. The driver refreshes this information every 10 seconds. You can also call VerifyState yourself if you want the information to be as current as possible (taking into account that VerifyState requires round trips to the nodes).

Another issue is that there is a bug in VerifyState: if you call VerifyState when the cluster is disconnected it does nothing, so as a work around you currently have to call Connect first to ensure the cluster is in a Connected state before you call VerifyState.

The final issue is that there are some properties of nodes that are not yet exposed. That can be rectified by adding them.

In hindsight I wish the MongoServer and MongoServerInstance classes where called MongoCluster and MongoNode, as those names would be clearer. Perhaps in version 2.0 we can rectify that, although it would be a breaking change. It also would have been better if VerifyState had been named RefreshState to emphasize that it refreshes the cached information.

This JIRA ticket proposes an alternative way of getting information about the cluster which doesn't use cached information, so it would always incur the expense of a round trip to one or more servers.

Another consideration is that as of version 2.4 of the server the replSetGetStatus command requires clusterAdmin privilege, so if the proposed helper method was implemented using replSetGetStatus it couldn't be called by ordinary applications that don't have clusterAdmin privilege.

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