今天 DBA 同事问了一个问题,MySQL在半同步复制的场景下,当关闭从节点时使得从节点的数量 < rpl_semi_sync_master_wait_for_slave_count时,show full processlist 的结果不同,具体表现如下:
AFTER_SYNC表现如下:
可以发现,只有一个查询线程处于 Waiting for semi-sync ACK from slave 状态,其他查询线程处于 query end 状态。
AFTER_COMMIT 表现如下:
和 AFTER_SYNC 不同, 所有的查询线程处于 Waiting for semi-sync ACK from slave 状态;
之前已经了解过 MySQL半同步复制,这次从源码的角度来解析MySQL半同步复制到底是如何进行的,同时分析原因。
首先,让我们来看看事务提交流程。整个提交过程太长了。我们以前研究过源代码。这里,我们只对半同步复制的相关部分进行深入分析:
[En]
First of all, let's take a look at the transaction commit process. The overall submission process is too long. We have studied the source code before. Here, we only make an in-depth analysis of the parts related to semi-synchronous replication:
```
int MYSQL_BIN_LOG::ordered_commit(THD *thd, bool all, bool skip_commit)