Reputation: 13
Im new to mongodb, I have one question:
Im setting up a mongoDB test env, with one mongos, 3 conf server, 2 shards ( 3 server as replication set for a shard ) let's say, for reasons I have a big lag of replication (like secondary is backing up, or network issue. or something else happening. in case it happens) during this time, the primary server is down, what will happen ? Auto fail-over select one secondary db as new primary, how about these data havnt replicated yet ?
are we gonna lost data ? if so, how can we do to get data back and what need to be done, to avoid such issue.
thanks a lot.
Upvotes: 1
Views: 528
Reputation: 43884
during this time, the primary server is down, what will happen ?
No writes will be allowed
Auto fail-over select one secondary db as new primary, how about these data havnt replicated yet ?
If data has no replicated from the primary to the secondary which then becomes primary then a rollback will occur when the primary comes back into the set as a secondary: http://docs.mongodb.org/manual/core/replica-set-rollbacks/
Of course as to whether you lose data or not depends on whether the write went to journal and/or data files and whether the member just left the set or crashed. If the member crashed before the write could go to journal then there is a chance that the write could be lost, yes.
how can we do to get data back and what need to be done, to avoid such issue.
You can use w=majority
for most cases but this will still have certain pitfalls within edge cases that just cannot be taken care of, for example if the primary fails over before the write can be propogated to other members etc.
Upvotes: 3