Search code examples
windowsmongodbreplication

MongoDB conf in absence of Arbiter to host election to choosing a primary


Let me explain the scenario in the first step.

Case 1: I have a Primary Replica set on localhost:27017 and 2 replications of primary on ports 27018 & 27019. all these are on the same set.

localhost:27017 as Master

When i shutdown the server on port 27017, one of the two secondary servers on ports 27018 & 27019 will be made Master(from the election).

Case 2: I have a Primary Replica set on localhost:27017 and 2 replications of primary on 27018 & 27019 along with a arbiter on 27020. all these are on the same group.

With arbiter

Now, When i shutdown arbiter(:27020) and the primary(:27017) nodes, I see the below message in log on :27018 & :27019 Message: 2016-04-03T12:26:19.035-0700 I REPL [ReplicationExecutor] Not starting an election, since we are not electable

How do i conf my secondary nodes to host an election by them self(as in the case 1) and choose one of them to be a primary.

Commends used to create these nodes are: **mongod --port 27017 --dbpath F:\mongodb\replication\rs0-0 --replSet rs0 --smallfiles --oplogSize 128 --logpath F:\data\log\devr0.log --logappend

mongod --port 27018 --dbpath F:\mongodb\replication\rs0-1 --replSet rs0 --smallfiles --oplogSize 128 --logpath F:\data\log\devr1.log --logappend

mongod --port 27019 --dbpath F:\mongodb\replication\rs0-2 --replSet rs0 --smallfiles --oplogSize 128 --logpath F:\data\log\devr2.log --logappend

mongod --port 27020 --dbpath F:\mongodb\replication\arbiter --replSet rs0 --smallfiles --oplogSize 128 --logpath F:\data\log\devarb.log --logappend**


Solution

  • Your case 2 is flawed. As shown you added an arbiter to a working replica set consisting of three members. Since no elections happen while adding a member, everything worked fine. After the shutdown however, the replica set found that there is an even number of members and hence refused to start the election process, even while in theory a quorum of members could be found.

    It is safe to assume that this is a security measure to prevent stale elections early on.

    You always need the replica set consisting of an uneven number of members, so that in a worst case scenario, a qualified majority of the original members can elect a primary. Adding an arbiter to a replica set consisting of three data bearing nodes holds no value, hence.