带有哨兵的 Redis 在脑裂后的表现如何?

How Redis with sentinels behave after split brain?

问题是关于 Redis 服务器和哨兵配置的。

有两个子网,我想总共有4台redis服务器,每个子网2台。由于可能存在连接问题,我想配置哨兵以允许大脑分裂以实现高可用性。

因此,当发生连接问题时,会出现两个独立工作一段时间的 Redis 设置。

现在的问题是子网连接恢复后会发生什么。哨兵会检测脑裂和两个高手?接下来他们将只选举主人,第二个将被降级为奴隶?来自存活主机的数据将被推送到降级的主机,他需要删除在连接问题期间获得的所有数据差异?

我可以配置一些东西以便合并数据吗?

redis中有两种处理HA的方法- sentinel and redis cluster.

哨兵

If a master is not working as expected, Sentinel can start a failover process where a slave is promoted to master, the other additional slaves are reconfigured to use the new master, and the applications using the Redis server informed about the new address to use when connecting

问:由于可能存在连接问题,我想配置哨兵以允许大脑分裂以获得高可用性

这是使用 sentinel 的反模式。这是文档中解释的偶数节点的类似示例

Example 1: just two Sentinels, DON'T DO THIS

In the above configuration we created two masters (assuming S2 could failover without authorization) in a perfectly symmetrical way. Clients may write indefinitely to both sides, and there is no way to understand when the partition heals what configuration is the right one, in order to prevent a permanent split brain condition. So please deploy at least three Sentinels in three different boxes always.

问:现在问题是子网连接恢复后会发生什么。哨兵会检测到大脑分裂和两个主人?

This data will be lost forever since when the partition will heal, the master will be reconfigured as a slave of the new master, discarding its data set.

问:来自幸存主机的数据将被推送到降级主机,他需要删除在连接问题期间获得的所有数据差异?

问:我可以配置一些东西以便合并数据吗? 你不能,redis 永远不会合并任何东西

Redis 集群

这个beast是做什么用的?

The ability to automatically split your dataset among multiple nodes. The ability to continue operations when a subset of the nodes are experiencing failures or are unable to communicate with the rest of the cluster.

所以它基本上是一个多作者解决方案。但是不支持合并操作either

Redis Cluster design avoids conflicting versions of the same key-value pair in multiple nodes as in the case of the Redis data model this is not always desirable. Values in Redis are often very large; it is common to see lists or sorted sets with millions of elements. Also data types are semantically complex. Transferring and merging these kind of values can be a major bottleneck and/or may require the non-trivial involvement of application-side logic, additional memory to store meta-data, and so forth.

回到你的场景

引用自here

Fundamental things to know about Sentinel before deploying

You need at least three Sentinel instances for a robust deployment. The three Sentinel instances should be placed into computers or virtual machines that are believed to fail in an independent way. So for example different physical servers or Virtual Machines executed on different availability zones.

请注意,您也可以在客户端机器上放置哨兵 - 这种方法在 redis 演示中大量使用 https://redis.io/topics/sentinel

您也可以使用 集群 解决方案,但它更难配置 + 它对多键操作有一些限制,您仍然 需要提供大多数节点,以防其中一个子网出现故障以获得某种 HA