简体   繁体   English

MongoDB:replicateSet:零停机时间

[英]MongoDB : replicaSet : zero downtime

I have a replicaset with 3 nodes. 我有一个3个节点的副本集。 The code is connecting through pymongo to the current master. 该代码通过pymongo连接到当前主机。 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. 在我们的Java应用程序中,我们通过PRIMARY_PREFERRED作为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. 持久层需要某种事务队列,以便在replset选择新的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. 我已经在Akka框架周围看到了有关此问题的建议,在该框架中,实际保留内容的Actor在请求的内存队列中保持其自身的地位。 During transitional periods, the queue builds up as the Actor waits for the replset to go back to read/write. 在过渡期间,当Actor等待replset返回读/写时,队列会建立。

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. 只要没有人能胜过CAP,您就不可能完全可用,因为分区容忍是分布式系统中的前提,并且MongoDB是一致的。 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. 如果您的主要目标是可用性,那么MongoDB是错误的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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