Browse Source

When Ping is called and MongoServer is connected to a replica set, Ping now pings all members of the replica set one at a time, instead of just the Primary. Also added a Ping method to MongoServerInstance, so individual instances can be pinged if desired.

pull/66/merge
rstam 14 years ago
parent
commit
b5a3ef9bc1
  1. 7
      Driver/Core/MongoServer.cs
  2. 15
      Driver/Core/MongoServerInstance.cs

7
Driver/Core/MongoServer.cs

@ -811,11 +811,12 @@ namespace MongoDB.Driver {
}
/// <summary>
/// Checks whether the server is alive (throws an exception if not).
/// Checks whether the server is alive (throws an exception if not). If server is a replica set, pings all members one at a time.
/// </summary>
public virtual void Ping() {
var command = new CommandDocument("ping", 1);
RunAdminCommand(command);
foreach (var instance in instances.ToArray()) {
instance.Ping();
}
}
/// <summary>

15
Driver/Core/MongoServerInstance.cs

@ -187,6 +187,21 @@ namespace MongoDB.Driver {
}
#endregion
#region public method
/// <summary>
/// Checks whether the server is alive (throws an exception if not).
/// </summary>
public void Ping() {
var connection = connectionPool.AcquireConnection(null);
try {
var pingCommand = new CommandDocument("ping", 1);
connection.RunCommand("admin.$cmd", QueryFlags.SlaveOk, pingCommand);
} finally {
connection.ConnectionPool.ReleaseConnection(connection);
}
}
#endregion
#region internal methods
internal MongoConnection AcquireConnection(
MongoDatabase database

Loading…
Cancel
Save