Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three nodes using replica-set in MongoDb and 2 are down

in a 3-node replicaSet why when 2 are down the third become SECONDARY and not PRIMARY?

I want to have 2 mongod inside a DataCenter and one outside, so if the Datacenters fails I wanna the third outside mongod becomes the Primary.

It's possible without and arbiter?

like image 824
Wiliam Avatar asked Aug 26 '12 11:08

Wiliam


People also ask

How many maximum nodes are allowed in the replica set?

MongoDB supports replica sets, which can have up to 50 nodes.

How does MongoDB replica set work?

MongoDB achieves replication by the use of replica set. A replica set is a group of mongod instances that host the same data set. In a replica, one node is primary node that receives all write operations. All other instances, such as secondaries, apply operations from the primary so that they have the same data set.

How does replica set connect to MongoDB?

To connect to a replica set deployment, specify the hostname and port numbers of each instance, separated by commas, and the replica set name as the value of the replicaSet parameter in the connection string. In the following example, the hostnames are host1 , host2 , and host3 , and the port numbers are all 27017 .


2 Answers

Ok, found response:

http://tebros.com/2010/11/mongodb-arbiters-with-only-two-replicas/

What happend?! It turns out that when a mongod instance is isolated, it cannot vote for itself to be primary. This makes sense when you think about it. If a network link went down and separated your two replicas, you wouldn’t want them both to elect themselves as primary. So in my case, when rep1-1 noticed that it was isolated from the rest of the replica set, it made itself secondary and stopped accepting writes.

like image 185
Wiliam Avatar answered Sep 22 '22 12:09

Wiliam


Always you end up with (cluster_participants/2) + 1 nodes down (assuming you have odd number of participants), the cluster enters in read only mode. A candidate noDe needs the majority of all nodes to be elected as primary.

For example, if you have 5 noDe cluster and 3 nodes blow away, the others will stay as secondary, because none of them are able to get 3 votes.

For more information: http://docs.mongodb.org/manual/core/replication-internals/#replica-set-election-internals

like image 34
Samuel García Avatar answered Sep 21 '22 12:09

Samuel García