文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

MySQL 8.4 参考手册 / 25 MySQL NDB 集群 8.4 / 25.7 NDB 集群复制 / 25.7.8 使用 NDB Cluster 复制实现故障转移
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

25.7.8 使用 NDB 集群复制实现故障切换25.7.8 Implementing Failover with NDB Cluster Replication

如果主集群复制进程发生故障,可以切换到次要复制通道。以下过程描述了完成此操作所需的步骤。In the event that the primary Cluster replication process fails, it is possible to switch over to the secondary replication channel. The following procedure describes the steps required to accomplish this.

  1. 获取最近的全局检查点(GCP)时间。也就是说,你需要确定副本集群中 ndb_apply_status 表中的最新纪元,可以使用以下查询找到: Obtain the time of the most recent global checkpoint (GCP). That is, you need to determine the most recent epoch from the ndb_apply_status table on the replica cluster, which can be found using the following query:

    mysqlR'> SELECT @latest:=MAX(epoch)
          ->        FROM mysql.ndb_apply_status;
    

    在循环复制拓扑中,每个主机上运行一个源服务器和一个副本,当你使用 ndb_log_apply_status=1 时,NDB Cluster 的时期会写入副本的二进制日志中。这意味着 ndb_apply_status 表包含了该主机上的副本信息,以及作为该主机上运行的复制源服务器的副本的任何其他主机的信息。In a circular replication topology, with a source and a replica running on each host, when you are using ndb_log_apply_status=1, NDB Cluster epochs are written in the replicas' binary logs. This means that the ndb_apply_status table contains information for the replica on this host as well as for any other host which acts as a replica of the replication source server running on this host.

    在这种情况下,您需要确定此副本上的最新纪元,而不考虑此副本二进制日志中任何其他副本的纪元,这些纪元未在用于设置此副本的 CHANGE REPLICATION SOURCE TO 语句的 IGNORE_SERVER_IDS 选项中列出。排除这些纪元的原因是,mysql.ndb_apply_status 表中其服务器 ID 与用于准备该副本源的 IGNORE_SERVER_IDS 语句中的 CHANGE REPLICATION SOURCE TO 列表匹配的行,也被认为来自本地服务器,此外还包括具有副本自身服务器 ID 的行。您可以通过 SHOW REPLICA STATUS 的输出将此列表检索为 Replicate_Ignore_Server_Ids。我们假设您已获取此列表,并将其替换为此处查询中的 ignore_server_ids,如同前一个查询版本一样,该查询将最大的纪元选择到名为 @latest 的变量中:In this case, you need to determine the latest epoch on this replica to the exclusion of any epochs from any other replicas in this replica's binary log that were not listed in the IGNORE_SERVER_IDS options of the CHANGE REPLICATION SOURCE TO statement used to set up this replica. The reason for excluding such epochs is that rows in the mysql.ndb_apply_status table whose server IDs have a match in the IGNORE_SERVER_IDS list from the CHANGE REPLICATION SOURCE TO statement used to prepare this replicas's source are also considered to be from local servers, in addition to those having the replica's own server ID. You can retrieve this list as Replicate_Ignore_Server_Ids from the output of SHOW REPLICA STATUS. We assume that you have obtained this list and are substituting it for ignore_server_ids in the query shown here, which like the previous version of the query, selects the greatest epoch into a variable named @latest:

    mysqlR'> SELECT @latest:=MAX(epoch)
          ->        FROM mysql.ndb_apply_status
          ->        WHERE server_id NOT IN (ignore_server_ids);
    

    在某些情况下,使用要包含的服务器 ID 列表以及在前一个查询的 WHERE 条件中使用 server_id IN server_id_list 可能更简单或更高效(或两者兼而有之)。In some cases, it may be simpler or more efficient (or both) to use a list of the server IDs to be included and server_id IN server_id_list in the WHERE condition of the preceding query.

  2. 使用第 1 步查询中获取的信息,从源集群的 ndb_binlog_index 表中获取相应的记录。 Using the information obtained from the query shown in Step 1, obtain the corresponding records from the ndb_binlog_index table on the source cluster.

    您可以使用以下查询从源的 ndb_binlog_index 表中获取所需记录:You can use the following query to obtain the needed records from the ndb_binlog_index table on the source:

    mysqlS'> SELECT
        ->     @file:=SUBSTRING_INDEX(next_file, '/', -1),
        ->     @pos:=next_position
        -> FROM mysql.ndb_binlog_index
        -> WHERE epoch = @latest;
    

    这些是自主复制通道失败以来在源端保存的记录。我们在这里使用了一个用户变量@latest来表示步骤 1 中获取的值。当然,一个mysqld实例无法直接访问在另一个服务器实例上设置的用户变量。这些值必须手动或通过应用程序“插入”到第二个查询中。These are the records saved on the source since the failure of the primary replication channel. We have employed a user variable @latest here to represent the value obtained in Step 1. Of course, it is not possible for one mysqld instance to access user variables set on another server instance directly. These values must be “plugged in” to the second query manually or by an application.

    Important

    您必须确保在执行 --replica-skip-errors=ddl_exist_errors 之前,副本 mysqld 是使用 START REPLICA 启动的。否则,复制可能会因重复的 DDL 错误而停止。You must ensure that the replica mysqld is started with --replica-skip-errors=ddl_exist_errors before executing START REPLICA. Otherwise, replication may stop with duplicate DDL errors.

  3. 现在可以通过在次级副本服务器上运行以下查询来同步次级通道:Now it is possible to synchronize the secondary channel by running the following query on the secondary replica server:

    mysqlR'> CHANGE REPLICATION SOURCE TO
          ->     SOURCE_LOG_FILE='@file',
          ->     SOURCE_LOG_POS=@pos;

    在这里我们再次使用了用户变量(在本例中为 @file 和 @pos)来表示在步骤 2 中获得并在步骤 3 中应用的值;在实际操作中,这些值必须手动插入,或使用能够访问两个服务器的应用程序来插入。Again we have employed user variables (in this case @file and @pos) to represent the values obtained in Step 2 and applied in Step 3; in practice these values must be inserted manually or using an application that can access both of the servers involved.

    Note

    @file 是一个字符串值,例如 '/var/log/mysql/replication-source-bin.00001',因此在 SQL 或应用程序代码中使用时必须加引号。然而,@pos 所表示的值 不能 加引号。虽然 MySQL 通常会尝试将字符串转换为数字,但此情况是个例外。@file is a string value such as '/var/log/mysql/replication-source-bin.00001', and so must be quoted when used in SQL or application code. However, the value represented by @pos must not be quoted. Although MySQL normally attempts to convert strings to numbers, this case is an exception.

  4. 现在,您可以通过在辅助副本 mysqld 上发出相应命令来启动辅助通道的复制:You can now initiate replication on the secondary channel by issuing the appropriate command on the secondary replica mysqld:

    mysqlR'> START REPLICA;
    

一旦辅助复制通道激活,您可以调查主通道的故障并进行修复。具体需要采取的操作取决于主通道失败的原因。Once the secondary replication channel is active, you can investigate the failure of the primary and effect repairs. The precise actions required to do this depend upon the reasons for which the primary channel failed.

Warning

只有在主复制通道发生故障时,才应启动辅助复制通道。与此同时运行多个复制通道可能导致副本上产生不必要的重复记录。The secondary replication channel is to be started only if and when the primary replication channel has failed. Running multiple replication channels simultaneously can result in unwanted duplicate records being created on the replicas.

如果故障仅限于单个服务器,理论上应该可以从 S 复制到 R',或者从 S' 复制到 R。If the failure is limited to a single server, it should in theory be possible to replicate from S to R', or from S' to R.