简体   繁体   中英

MongoDB : replicaSet : zero downtime

I have a replicaset with 3 nodes. The code is connecting through pymongo to the current master. If the current master goes down, it takes around two seconds to get a new master. What can I do to reduce to zero this downtime ?

Thanks in advance

You need to do 2 things.

  1. Allow for slave reads. In our Java application we get this through PRIMARY_PREFERRED as a ReadPreference. This allows your application to keep reading through the election periods.

  2. You persistence layer needs some sort of transaction queue such that the writes back off during transitional periods when the replset is electing a new PRIMARY. I've seen proposals for this around the Akka framework where the Actor that actually persists stuff maintains its own in memory queue of requests. During transitional periods, the queue builds up as the Actor waits for the replset to go back to read/write.

The "in memory queue of requests" is enough of a concern for me that I have not pulled the trigger and actually implemented this.

As long as no one beats CAP, you cannot be fully available since partition-tolerance is a precondition in distributed systems and MongoDB is consistent. By allowing reads from the secondaries you weaken consistency a bit and trade it for (read) availability.

If your main goal is availability, MongoDB is the wrong choice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM