Nikhil
Nikhil

Reputation: 1151

In MongoDB, I have a 2 member replicaset. One goes down, and nothing can connect

I have a replicaset that consists of 2 servers. When testing failover, I shut down the primary server. I expected all clients to start hitting the other server. Instead, they keep trying to hit the primary and time out. The secondary never elects itself the primary.

Either I'm configuring the client incorrectly, or a mongo replica set requires three servers to have any failover. Which one is it? Here's my configuration.

var settings = new MongoClientSettings
{
    Credentials = new[] { credential },
    ConnectionMode = ConnectionMode.ReplicaSet,
    WriteConcern = WriteConcern.WMajority,
    WaitQueueTimeout = TimeSpan.FromMinutes(30),
    MaxConnectionPoolSize = 3000

};

string[] hosts = ConfigurationManager.AppSettings["MongoServerIpsSemiColonSeparated"].Split(';');
var servers = hosts.Select(x => new MongoServerAddress(x)).ToList();
settings.Servers = servers;
settings.ReplicaSetName = ConfigurationManager.AppSettings["NameOfReplicaset"];

Client = new MongoClient(settings);

Upvotes: 1

Views: 1080

Answers (1)

profesor79
profesor79

Reputation: 9473

this is a valid behaviour for your scenario.

As per mongo docs a replica set need to be build with minimum of 3 members. As primary fails, then secondary has not a quora to elect himself as a master. Moreover this could lead to harm, just kill secondary and see that primary will step-down, so replica set will be not usable at all.

Add an arbiter to your set up to solve this problem. More here

Upvotes: 2

Related Questions