本节提供有关 MySQL 组复制的背景信息。This section provides background information on MySQL Group Replication.
创建容错系统的最常见方法是通过使组件冗余来实现,换句话说,组件可以被移除,系统仍应按预期继续运行。这会产生一系列挑战,使这类系统的复杂性提升到一个全新的水平。具体来说,复制数据库必须处理它们需要维护和管理多个服务器而不仅仅是一个服务器的问题。此外,由于服务器需要协同工作以形成组,还必须处理一些经典的分布式系统问题,例如网络分区或脑裂情况。The most common way to create a fault-tolerant system is to resort to making components redundant, in other words the component can be removed and the system should continue to operate as expected. This creates a set of challenges that raise complexity of such systems to a whole different level. Specifically, replicated databases have to deal with the fact that they require maintenance and administration of several servers instead of just one. Moreover, as servers are cooperating together to create the group several other classic distributed systems problems have to be dealt with, such as network partitioning or split brain scenarios.
因此,最终的挑战是将数据库和数据复制的逻辑与多个服务器以一致且简单的方式协调的逻辑融合。换句话说,就是让多个服务器就系统的状态以及系统经历的每一次数据变化达成一致。这可以概括为让服务器就每一次数据库状态的转换达成一致,从而使它们作为一个单一的数据库共同前进,或者最终收敛到相同的状态。这意味着它们需要作为一个(分布式)状态机来运作。Therefore, the ultimate challenge is to fuse the logic of the database and data replication with the logic of having several servers coordinated in a consistent and simple way. In other words, to have multiple servers agreeing on the state of the system and the data on each and every change that the system goes through. This can be summarized as having servers reaching agreement on each database state transition, so that they all progress as one single database or alternatively that they eventually converge to the same state. Meaning that they need to operate as a (distributed) state machine.
MySQL 群组复制提供了具有服务器之间强协调能力的分布式状态机复制。当服务器属于同一组时,它们会自动进行协调。该组可以以单主模式运行,具有自动主节点选举功能,此时一次只有一台服务器接受更新。或者,对于更高级的用户,群组可以部署在多主模式下,所有服务器都可以接受更新,即使这些更新是同时发出的。这种能力的代价是应用程序必须绕过此类部署所带来的限制。MySQL Group Replication provides distributed state machine replication with strong coordination between servers. Servers coordinate themselves automatically when they are part of the same group. The group can operate in a single-primary mode with automatic primary election, where only one server accepts updates at a time. Alternatively, for more advanced users the group can be deployed in multi-primary mode, where all servers can accept updates, even if they are issued concurrently. This power comes at the expense of applications having to work around the limitations imposed by such deployments.
有一个内置的组成员服务,它可以在任何时候保持组的视图一致,并对所有服务器可用。服务器可以离开和加入组,视图会相应更新。有时服务器可能会意外离开组,在这种情况下,故障检测机制会检测到这一情况并通知组视图已更改。这一切都是自动完成的。There is a built-in group membership service that keeps the view of the group consistent and available for all servers at any given point in time. Servers can leave and join the group and the view is updated accordingly. Sometimes servers can leave the group unexpectedly, in which case the failure detection mechanism detects this and notifies the group that the view has changed. This is all automatic.
为了使事务提交,群组的大多数成员必须同意该事务在全局事务序列中的顺序。决定提交或中止事务由每个服务器单独完成,但所有服务器都会做出相同的决定。如果发生网络分区,导致成员无法达成一致意见,则系统在问题解决之前不会继续进行。因此,系统还内置了一个自动的分脑保护机制。For a transaction to commit, the majority of the group have to agree on the order of a given transaction in the global sequence of transactions. Deciding to commit or abort a transaction is done by each server individually, but all servers make the same decision. If there is a network partition, resulting in a split where members are unable to reach agreement, then the system does not progress until this issue is resolved. Hence there is also a built-in, automatic, split-brain protection mechanism.
所有这些都是由提供的组通信系统(GCS)协议支持的。这些协议提供了故障检测机制、组成员服务以及安全且完全有序的消息传递。所有这些特性对于创建一个确保数据在服务器组中一致复制的系统至关重要。在这项技术的核心是 Paxos 算法的实现。它充当组通信引擎。All of this is powered by the provided Group Communication System (GCS) protocols. These provide a failure detection mechanism, a group membership service, and safe and completely ordered message delivery. All these properties are key to creating a system which ensures that data is consistently replicated across the group of servers. At the very core of this technology lies an implementation of the Paxos algorithm. It acts as the group communication engine.