组复制旨在确保数据库服务持续可用,即使由于计划内维护或意外问题,形成组的一些服务器当前无法参与其中。只要剩余成员占组的多数,他们就可以选举出新的主服务器,并继续作为一个组运行。然而,如果复制组的每个成员都离开了组,并且通过STOP
GROUP_REPLICATION语句或系统关闭在每个成员上停止了组复制,该组现在仅在理论上存在,作为成员上的配置。在这种情况下,要重新创建组,必须通过引导启动,就像首次启动一样。Group Replication is designed to ensure that the database service
is continuously available, even if some of the servers that form
the group are currently unable to participate in it due to planned
maintenance or unplanned issues. As long as the remaining members
are a majority of the group they can elect a new primary and
continue to function as a group. However, if every member of a
replication group leaves the group, and Group Replication is
stopped on every member by a STOP
GROUP_REPLICATION statement or system shutdown, the
group now only exists in theory, as a configuration on the
members. In that situation, to re-create the group, it must be
started by bootstrapping as if it was being started for the first
time.
第一次为一个组引导(bootstrapping)与第二次或随后进行引导的区别在于,在后者情况下,一个已经关闭的组的成员之间可能拥有不同的事务集,这取决于它们被停止或失败的顺序。如果一个成员拥有的事务在其他组成员中不存在,该成员就无法加入该组。对于组复制(Group Replication)来说,这包括已经提交并应用的事务,这些事务在 gtid_executed GTID 集中,以及已认证但尚未应用的事务,这些事务在 group_replication_applier 通道中。事务被提交的具体时间点取决于为组设置的事务一致性级别(参见 第 20.5.3 节,“事务一致性保证”)。然而,组复制的组成员从不移除已经认证的事务,这表示成员有意提交该事务。The difference between bootstrapping a group for the first time
and doing it for the second or subsequent times is that in the
latter situation, the members of a group that was shut down might
have different transaction sets from each other, depending on the
order in which they were stopped or failed. A member cannot join a
group if it has transactions that are not present on the other
group members. For Group Replication, this includes both
transactions that have been committed and applied, which are in
the gtid_executed GTID set, and
transactions that have been certified but not yet applied, which
are in the group_replication_applier channel.
The exact point at which a transaction is committed depends on the
transaction consistency level that is set for the group (see
Section 20.5.3, “Transaction Consistency Guarantees”).
However, a Group Replication group member never removes a
transaction that has been certified, which is a declaration of the
member’s intent to commit the transaction.
因此,复制组必须从最新的成员开始重启,也就是执行和认证事务最多的成员。事务较少的成员随后可以加入,并通过分布式恢复赶上缺失的事务。不能假设组中最后已知的主成员就是组中最新的成员,因为比主成员稍后关闭的成员可能有更多的事务。因此,必须重启每个成员以检查事务,比较所有事务集,并确定最新的成员。然后可以使用该成员来引导组。The replication group must therefore be restarted beginning with the most up to date member, that is, the member that has the most transactions executed and certified. The members with fewer transactions can then join and catch up with the transactions they are missing through distributed recovery. It is not correct to assume that the last known primary member of the group is the most up to date member of the group, because a member that was shut down later than the primary might have more transactions. You must therefore restart each member to check the transactions, compare all the transaction sets, and identify the most up to date member. This member can then be used to bootstrap the group.
在每个成员关闭后,请按照此程序安全地重启复制组。Follow this procedure to restart a replication group safely after every member shuts down.
对于每个组成员,按任意顺序依次进行:For each group member in turn, in any order:
将客户端连接到组成员。如果组复制尚未停止,请执行
STOP GROUP_REPLICATION语句,并等待组复制停止。Connect a client to the group member. If Group Replication is not already stopped, issue aSTOP GROUP_REPLICATIONstatement and wait for Group Replication to stop.编辑 MySQL Server 配置文件(在 Linux 和 Unix 系统上通常名为
my.cnf,在 Windows 系统上名为my.ini),并设置系统变量group_replication_start_on_boot=OFF。此设置可防止 MySQL Server 启动时自动启动组复制,这也是默认设置。Edit the MySQL Server configuration file (typically namedmy.cnfon Linux and Unix systems, ormy.inion Windows systems) and set the system variablegroup_replication_start_on_boot=OFF. This setting prevents Group Replication from starting when MySQL Server is started, which is the default.如果您无法在系统上更改该设置,可以允许服务器尝试启动组复制,但由于组已完全关闭且尚未引导启动,这将失败。如果您采取这种方法,请不要在此阶段在任何服务器上设置
group_replication_bootstrap_group=ON。If you cannot change that setting on the system, you can just allow the server to attempt to start Group Replication, which will fail because the group has been fully shut down and not yet bootstrapped. If you take that approach, do not setgroup_replication_bootstrap_group=ONon any server at this stage.启动 MySQL 服务器实例,并验证组复制尚未启动(或启动失败)。此阶段不要启动组复制。Start the MySQL Server instance, and verify that Group Replication has not been started (or has failed to start). Do not start Group Replication at this stage.
从组成员收集以下信息:Collect the following information from the group member:
gtid_executedGTID 集的内容。您可以通过执行以下语句获取:The contents of thegtid_executedGTID set. You can get this by issuing the following statement:mysql> SELECT @@GLOBAL.GTID_EXECUTED
在
group_replication_applier通道上认证的事务集合。您可以通过发出以下语句来获取:The set of certified transactions on thegroup_replication_applierchannel. You can get this by issuing the following statement:mysql> SELECT received_transaction_set FROM \ performance_schema.replication_connection_status WHERE \ channel_name="group_replication_applier";
当您收集了所有组成员的事务集合后,将它们进行比较,以找出哪个成员的事务集合总体上最大,包括已执行的事务(
gtid_executed)和已认证的事务(在group_replication_applier通道上)。您可以通过查看 GTID 手动完成此操作,或者使用存储函数比较 GTID 集合,如 第 19.1.3.8 节,“操作 GTID 的存储函数示例” 中所述。When you have collected the transaction sets from all the group members, compare them to find which member has the biggest transaction set overall, including both the executed transactions (gtid_executed) and the certified transactions (on thegroup_replication_applierchannel). You can do this manually by looking at the GTIDs, or you can compare the GTID sets using stored functions, as described in Section 19.1.3.8, “Stored Function Examples to Manipulate GTIDs”.使用具有最大事务集的成员来引导组,通过将客户端连接到该组成员并执行以下语句:Use the member that has the biggest transaction set to bootstrap the group, by connecting a client to the group member and issuing the following statements:
mysql> SET GLOBAL group_replication_bootstrap_group=ON; mysql> START GROUP_REPLICATION; mysql> SET GLOBAL group_replication_bootstrap_group=OFF;
重要的是不要在配置文件中存储设置
group_replication_bootstrap_group=ON,否则当服务器再次重启时,会创建一个同名的第二个组。It is important not to store the settinggroup_replication_bootstrap_group=ONin the configuration file, otherwise when the server is restarted again, a second group with the same name is set up.要验证该组现在是否存在并包含该创始成员,请在引导它的成员上执行此语句:To verify that the group now exists with this founder member in it, issue this statement on the member that bootstrapped it:
mysql> SELECT * FROM performance_schema.replication_group_members;
通过在每个其他成员上执行
START GROUP_REPLICATION语句,将它们按任何顺序重新添加到组中:Add each of the other members back into the group, in any order, by issuing aSTART GROUP_REPLICATIONstatement on each of them:mysql> START GROUP_REPLICATION;
要验证每个成员是否已加入组,请对任意成员发出此声明:To verify that each member has joined the group, issue this statement on any member:
mysql> SELECT * FROM performance_schema.replication_group_members;
当成员重新加入组后,如果您编辑了他们的配置文件以设置
group_replication_start_on_boot=OFF,您可以再次编辑它们以设置为ON(或者删除该系统变量,因为ON是默认值)。When the members have rejoined the group, if you edited their configuration files to setgroup_replication_start_on_boot=OFF, you can edit them again to setON(or remove the system variable, sinceONis the default).