0

I need to distribute mongo nodes over 2 data centers.

I am bit confused by the fault-tolerance table :

Number of Members = 4

Majority Required to Elect a New Primary = 3

Does the number 4 mean I need total 5 voting members or can I have 3 voting members + 1 priority 0 hidden member ?

For example :

  • DC1 : P, H (priority=0)
  • DC2 : S, S

If DC1 is down , will DC2 elect a primary ?

If DC2 is down , do I need to convert H to arbitrer or it will remain Primary ?

Essentially, it would be great if someone can provide few recommended configuration of replicaset for 2 DCs that ensures automatic primary selection (selection with minimum manual effort) upon DC failure.

Thanks in advance, Kaniska

kaniska Mandal
  • 189
  • 1
  • 12

1 Answers1

0

Does the number 4 mean I need total 4 voting members or can I have 3 voting members + 1 priority 0 hidden member

A priority 0 member is a voting member. Priority 0 means the node cannot become primary (and it can't trigger elections).

Your sample setup shows only 4 total nodes split evenly between two data centers. The majority is still 3 and so, if either data center goes down, the replica set will be unhealthy and become read-only (no primary).

To create a 2 DC setup where failure of one DC will cause an automated failover to a primary in the other DC, there must be a node outside of either data center. With all nodes split between two data centers (and an odd number of nodes), at least one data center has a majority of the nodes. If that data center goes down, the replica set cannot automatically recover a healthy state while the majority-holding data center is down. Given this situation, a common pattern is to split nodes evenly between two data centers and have an arbiter outside of either.

kaniska Mandal
  • 189
  • 1
  • 12
wdberkeley
  • 11,531
  • 1
  • 28
  • 23
  • -Unfortunately we have to work with 2 DCs. - _After diving deep into Mongo replicaset tutorial, it looks like, if DC1 has 3 nodes and DC2 has 2 nodes, then we can achieve automatic failover only if DC2 goes down_. - _But if DC1 goes down , we have to manually force a node in DC2 to be Primary !_ - **Can you please review if my understanding is correct ?** – kaniska Mandal Feb 10 '15 at 03:41
  • One more question ? If I have a hidden / delayed/ standby member will that also participate in voting and be counted to find majority for primary selection ? – kaniska Mandal Feb 10 '15 at 03:51
  • In the first comment, your understanding is correct. If DC1 goes down and only 2 replica set members are up, the replica set will be unhealthy, will not accept writes, and will be read-only. You cannot force a node in DC2 to become primary except by reconfiguring the replica set, kicking out some nodes so that the 2 DC2 nodes are now a majority and can elect a primary. For the second comment, hidden and delayed members do, by default, vote in elections and count towards a majority. You change this by setting `votes` to zero. – wdberkeley Feb 10 '15 at 15:07
  • Thats Great ! -- Just to reconfirm, will **nodes with votes zero** still be counted for Majority ? -- _Will they help achieve automatic failover ?_ -- _In which situation should I use non_voting members ?_ – kaniska Mandal Feb 10 '15 at 16:03
  • For elections, only nodes with votes count towards the majority. [Members with zero votes](http://docs.mongodb.org/manual/core/replica-set-elections/#non-voting-members) can't vote and so don't really help with failover, but they can veto an election and can become primary (unless they are hidden/priority 0). Generally, don't add non-voting members unless you want to increase the number of replica set members beyond the maximum number of voting members (7 as of MongoDB 2.6). Perhaps the kind of node you're looking for is an [arbiter](http://docs.mongodb.org/manual/core/replica-set-arbiter/)? – wdberkeley Feb 10 '15 at 16:49
  • Great ! now I have a more pin-pointed question .... _my goal is to find the best strategy that requires minimum manual interaction to activate a primary when DC1 fails_ .... **DC1 (3 nodes) , DC2 (2 nodes)** --- _In DC2, should I beforehand add a standby node which is not part of replicaset ?_ ... _and the moment DC1 fails , should I turn the standby node into an arbiter (so that DC2 now have 3 voting nodes) and reconfig the replicaset ?_ ... **Is this the best solution for manual failover ?** ... _Is this something can be automated through scripts ?_ – kaniska Mandal Feb 10 '15 at 17:14