Reputation: 93
when I stop one of my secondary servers, the replica set works fine as another secondary node has replica data. But when I stop Primary node all crashed.
How can to use two servers as Primary or more and how will it work along with the seconday nodes in the replica setup? Please help me. Thank you!
Upvotes: 2
Views: 3731
Reputation: 10053
No, Firstly you can have only one primary mongodb server, Primary server is used for write operations
so it has to be one. Secondary servers are used for read only operations
and hence can be any. Keeping odd no of servers will help in voting mechanism when one of the primary or secondary servers go down.
You can force a member to become primary node by giving high priority. Force a Member to be Primary by Setting its Priority High
Upvotes: 0
Reputation: 43884
MongoDB replica sets are a single primary cluster, there is NO multiple primaries. Your diagram (from the docs) shows this very well.
Added to that you can only write to the primary, in other words if your set has no primary you cannot write to it, however, you can still read providing your read preference is manually set to either:
But when I stop Primary node all crashed.
This all comes down to failover handling, decided upon your write handling (catching exceptions from the cluster and retrying writes) and your read preferences.
It can take upto 10 seconds for a primary to be elected. What seems like a crashed set is not actually crashed, it is merely waiting for a new primary.
Now this also comes down to an important note about how replica sets work. If you use 2 members your set will "crash" this is because MongoDB must have the majority of the configured (in your rs.status()
) set online.
You can find more details in the doc: http://docs.mongodb.org/manual/core/replica-set-elections/
You do not need an "odd" number of members online unless you are dealing with network partitions, a replica set can vote for a primary with an even number of members provided all those members can talk to each other.
Upvotes: 0
Reputation: 5747
The main use of replication is for fail over . if a secondary failed then there won't be big change. But if a primary failed then mongodb will perform election to select new primary. You select a primary. It needs half no of votes in total nodes. So it don't have half no of votes then all node Ll b remain secondary. Then we can ltmy read the data..
We can have only one primary..
Upvotes: 0