Domanda

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

È stato utile?

Soluzione

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.

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top