MySQL 群组复制确保事务只有在群组中多数成员已接收并同意所有并发发送事务的相对顺序后才会提交。如果群组的总写入量不超过群组中任何成员的写入能力,这种方法效果良好。如果超过了,并且某些成员的写入吞吐量低于其他成员——尤其是低于写入成员——这些成员可能会开始落后于写入者。MySQL Group Replication ensures that a transaction commits only after a majority of the members in a group have received it and agreed on the relative order amongst all transactions sent concurrently. This approach works well if the total number of writes to the group does not exceed the write capacity of any member in the group. If it does, and some members have less write throughput than others—particularly less than the writer members—these members may start lagging behind the writers.
当某些成员落后于群组其余成员时,在这些成员上的读取可能会外显非常旧的数据。根据成员落后的原因,群组中的其他成员可能需要保存更多或更少的复制上下文,以便能够满足来自慢成员的潜在数据传输请求。When some members lag behind the rest of the group, reads on such members may externalize very old data. Depending on why the member is lagging behind, other members in the group may have to save more or less of the replication context to be able to fulfil potential data transfer requests from the slow member.
复制协议提供了一种机制,以避免快速成员和慢速成员之间在应用事务方面产生过大差距。这被称为流量控制机制,其目标如下:The replication protocol provides a mechanism to avoid having too much distance, in terms of transactions applied, between fast and slow members. This is known as the flow control mechanism, which has the following objectives:
保持成员之间的接近,尽量减少它们之间的缓冲和不同步To keep members close, to minimize buffering and desynchronization between them
快速适应变化的条件,例如不同的工作负载或组中更多的写入者To adapt quickly to changing conditions like different workloads or more writers in the group
为每个成员提供可用写入能力的一部分To give each member a share of the available write capacity
在避免浪费资源的前提下,不将吞吐量降低超过严格必要的程度Not to reduce throughput more than strictly necessary to avoid wasting resources
鉴于组复制的设计,是否进行限流的决策可能会考虑两个工作队列:认证队列和二进制日志应用队列。每当其中一个队列的大小超过用户定义的阈值时,限流机制就会被触发。Given the design of Group Replication, the decision whether to throttle, or not, may be made taking into account two work queues, the certification queue, and the binary log applier queue. Whenever the size of one of these queues exceeds the user-defined threshold, the throttling mechanism is triggered.
流量控制依赖于两种基本机制:Flow control depends on two basic mechanisms:
对成员进行监控,以收集有关所有组成员的吞吐量和队列大小的统计数据,从而对每个成员应承受的最大写入压力做出合理猜测Monitoring of members to collect statistics on throughput and queue sizes of all group members to make educated guesses concerning the maximum write pressure to which each member should be subjected
对试图写入超过其在每一时刻可用容量分配份额的成员进行限制Throttling of members that are trying to write beyond their alloted shares of the available capacity at each moment in time