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

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 14 函数和运算符 / 14.18 复制函数 / 14.18.3 异步复制通道故障转移功能
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 87%

14.18.3 异步复制通道故障转移函数14.18.3 Asynchronous Replication Channel Failover Functions

以下函数使您能够将复制源服务器添加到或从复制通道的源列表中移除,以及清除给定服务器的源列表。The following functions enable you to add or remove replication source servers to or from the source list for a replication channel, as well as clear the source list for a given server.

表 14.27 故障转移通道功能Table 14.27 Failover Channel Functions

名称Name 说明Description
asynchronous_connection_failover_add_managed() 将组成员源服务器配置信息添加到复制通道源列表Add group member source server configuration information to a replication channel source list
asynchronous_connection_failover_add_source() 将源服务器配置信息服务器添加到复制通道源列表Add source server configuration information server to a replication channel source list
asynchronous_connection_failover_delete_managed() 从复制通道源列表中移除托管组Remove a managed group from a replication channel source list
asynchronous_connection_failover_delete_source() 从复制通道源列表中移除源服务器Remove a source server from a replication channel source list
asynchronous_connection_failover_reset() 删除所有与组复制异步故障切换相关的设置Remove all settings relating to group replication asynchronous failover

异步连接故障转移机制会在副本到其源的现有连接失败后,自动从适当的列表中建立新的源的异步(源到副本)复制连接。如果当前连接的源在组中没有最高权重优先级,也会更换连接。对于作为托管组一部分定义的组复制源服务器,如果当前连接的源离开组或不再属于多数,也会将连接故障转移到另一个组成员。有关该机制的更多信息,请参阅 第 19.4.9 节,“使用异步连接故障转移切换源和副本”。The asynchronous connection failover mechanism automatically establishes an asynchronous (source to replica) replication connection to a new source from the appropriate list after the existing connection from the replica to its source fails. The connection is also changed if the currently connected source does not have the highest weighted priority in the group. For Group Replication source servers that are defined as part of a managed group, the connection is also failed over to another group member if the currently connected source leaves the group or is no longer in the majority. For more information on the mechanism, see Section 19.4.9, “Switching Sources and Replicas with Asynchronous Connection Failover”.

源列表存储在 mysql.replication_asynchronous_connection_failover 和 mysql.replication_asynchronous_connection_failover_managed 表中,并且可以在性能模式的 replication_asynchronous_connection_failover 表中查看。Source lists are stored in the mysql.replication_asynchronous_connection_failover and mysql.replication_asynchronous_connection_failover_managed tables, and can be viewed in the Performance Schema replication_asynchronous_connection_failover table.

如果复制通道位于一个组复制主节点上,并且该组中的副本之间启用了故障切换,则当组成员加入或通过任何方法更新源列表时,源列表会广播到所有组成员。副本之间的故障切换由 mysql_start_failover_channels_if_primary 成员操作控制,该操作默认启用,可以使用 group_replication_disable_member_action 函数禁用。If the replication channel is on a Group Replication primary for a group where failover between replicas is active, the source list is broadcast to all the group members when they join or when it is updated by any method. Failover between replicas is controlled by the mysql_start_failover_channels_if_primary member action, which is enabled by default, and can be disabled using the group_replication_disable_member_action function.

  • asynchronous_connection_failover_add_managed()

    将属于受管理组(组复制组成员)的复制源服务器的配置信息添加到复制通道的源列表中。您只需添加一个组成员。副本会自动从当前组成员中添加其余成员,然后根据成员变更保持源列表的更新。Add configuration information for a replication source server that is part of a managed group (a Group Replication group member) to the source list for a replication channel. You only need to add one group member. The replica automatically adds the rest from the current group membership, then keeps the source list updated in line with membership change.

    语法:Syntax:

    asynchronous_connection_failover_add_managed(channel, managed_type, managed_name, host, port, network_namespace, primary_weight, secondary_weight)

    参数:Arguments:

    • channel:此复制源服务器属于源列表的复制通道。channel: The replication channel for which this replication source server is part of the source list.

    • managed_type:异步连接切换机制必须为该服务器提供的托管服务类型。目前唯一接受的值是 GroupReplication。managed_type: The type of managed service that the asynchronous connection failover mechanism must provide for this server. The only value currently accepted is GroupReplication.

    • managed_name:服务器所属托管组的标识符。对于 GroupReplication 托管服务,该标识符是 group_replication_group_name 系统变量的值。managed_name: The identifier for the managed group that the server is a part of. For the GroupReplication managed service, the identifier is the value of the group_replication_group_name system variable.

    • host:此复制源服务器的主机名。host: The host name for this replication source server.

    • port: 此复制源服务器的端口号。port: The port number for this replication source server.

    • network_namespace: 此复制源服务器的网络命名空间。请指定为空字符串,因为此参数保留以备将来使用。network_namespace: The network namespace for this replication source server. Specify an empty string, as this parameter is reserved for future use.

    • primary_weight: 当该复制源服务器作为托管组的主服务器时,在复制通道的源列表中的优先级。权重范围为 1 到 100,100 为最高。对于主服务器,80 是适当的权重。如果当前连接的源不是组中权重最高的,异步连接故障转移机制将会激活。假设你为托管组设置了更高的权重给主服务器,较低的权重给备份服务器,当主服务器发生变化时,其权重会增加,副本会切换连接到它。primary_weight: The priority of this replication source server in the replication channel's source list when it is acting as the primary for the managed group. The weight is from 1 to 100, with 100 being the highest. For the primary, 80 is a suitable weight. The asynchronous connection failover mechanism activates if the currently connected source is not the highest weighted in the group. Assuming that you set up the managed group to give a higher weight to a primary and a lower weight to a secondary, when the primary changes, its weight increases, and the replica changes over the connection to it.

    • secondary_weight:当该复制源服务器作为托管组中的辅助节点时,它在复制通道的源列表中的优先级。权重范围为 1 到 100,其中 100 最高。对于辅助节点,60 是一个合适的权重。secondary_weight: The priority of this replication source server in the replication channel's source list when it is acting as a secondary in the managed group. The weight is from 1 to 100, with 100 being the highest. For a secondary, 60 is a suitable weight.

    返回值:Return value:

    一个包含操作结果的字符串,例如操作是否成功。A string containing the result of the operation, for example whether it was successful or not.

    示例:Example:

    SELECT asynchronous_connection_failover_add_managed('channel2', 'GroupReplication', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '127.0.0.1', 3310, '', 80, 60);
    +----------------------------------------------------------------------------------------------------------------------------------------------------+
    | asynchronous_connection_failover_add_source('channel2', 'GroupReplication', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '127.0.0.1', 3310, '', 80, 60) |
    +----------------------------------------------------------------------------------------------------------------------------------------------------+
    | Source managed configuration details successfully inserted.                                                                                        |
    +----------------------------------------------------------------------------------------------------------------------------------------------------+
    

    有关更多信息,请参见 第 19.4.9 节,“使用异步连接故障转移切换源和副本”。For more information, see Section 19.4.9, “Switching Sources and Replicas with Asynchronous Connection Failover”.

  • asynchronous_connection_failover_add_source()

    将复制源服务器的配置信息添加到复制通道的源列表中。Add configuration information for a replication source server to the source list for a replication channel.

    语法:Syntax:

    asynchronous_connection_failover_add_source(channel, host, port, network_namespace, weight)

    参数:Arguments:

    • channel:此复制源服务器属于源列表的复制通道。channel: The replication channel for which this replication source server is part of the source list.

    • host:此复制源服务器的主机名。host: The host name for this replication source server.

    • port: 此复制源服务器的端口号。port: The port number for this replication source server.

    • network_namespace: 此复制源服务器的网络命名空间。请指定为空字符串,因为此参数保留以备将来使用。network_namespace: The network namespace for this replication source server. Specify an empty string, as this parameter is reserved for future use.

    • weight:此复制源服务器在复制通道源列表中的优先级。优先级范围为 1 到 100,其中 100 为最高,50 为默认值。当异步连接故障切换机制激活时,从通道源列表中列出的替代源中优先级最高的源会被选择进行第一次连接尝试。如果该尝试失败,副本会按照优先级从高到低对所有列出的源进行尝试,然后从最高优先级的源重新开始。如果多个源具有相同的优先级,副本会随机排序它们。如果当前连接的源不是组中权重最高的源,异步连接故障切换机制会被激活。weight: The priority of this replication source server in the replication channel's source list. The priority is from 1 to 100, with 100 being the highest, and 50 being the default. When the asynchronous connection failover mechanism activates, the source with the highest priority setting among the alternative sources listed in the source list for the channel is chosen for the first connection attempt. If this attempt does not work, the replica tries with all the listed sources in descending order of priority, then starts again from the highest priority source. If multiple sources have the same priority, the replica orders them randomly. The asynchronous connection failover mechanism activates if the source currently connected is not the highest weighted in the group.

    返回值:Return value:

    一个包含操作结果的字符串,例如操作是否成功。A string containing the result of the operation, for example whether it was successful or not.

    示例:Example:

    SELECT asynchronous_connection_failover_add_source('channel2', '127.0.0.1', 3310, '', 80);
    +-------------------------------------------------------------------------------------------------+
    | asynchronous_connection_failover_add_source('channel2', '127.0.0.1', 3310, '', 80)              |
    +-------------------------------------------------------------------------------------------------+
    | Source configuration details successfully inserted.                                             |
    +-------------------------------------------------------------------------------------------------+
    

    有关更多信息,请参见 第 19.4.9 节,“使用异步连接故障转移切换源和副本”。For more information, see Section 19.4.9, “Switching Sources and Replicas with Asynchronous Connection Failover”.

  • asynchronous_connection_failover_delete_managed()

    从复制通道的源列表中移除整个管理组。当您使用此功能时,管理组中定义的所有复制源服务器都将从通道的源列表中移除。Remove an entire managed group from the source list for a replication channel. When you use this function, all the replication source servers defined in the managed group are removed from the channel's source list.

    语法:Syntax:

    asynchronous_connection_failover_delete_managed(channel, managed_name)

    参数:Arguments:

    • channel:此复制源服务器属于源列表的复制通道。channel: The replication channel for which this replication source server was part of the source list.

    • managed_name:服务器所属托管组的标识符。对于 GroupReplication 托管服务,该标识符是 group_replication_group_name 系统变量的值。managed_name: The identifier for the managed group that the server is a part of. For the GroupReplication managed service, the identifier is the value of the group_replication_group_name system variable.

    返回值:Return value:

    一个包含操作结果的字符串,例如操作是否成功。A string containing the result of the operation, for example whether it was successful or not.

    示例:Example:

    SELECT asynchronous_connection_failover_delete_managed('channel2', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa');
    +-----------------------------------------------------------------------------------------------------+
    | asynchronous_connection_failover_delete_managed('channel2', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa') |
    +-----------------------------------------------------------------------------------------------------+
    | Source managed configuration details successfully deleted.                                          |
    +-----------------------------------------------------------------------------------------------------+
    

    有关更多信息,请参见 第 19.4.9 节,“使用异步连接故障转移切换源和副本”。For more information, see Section 19.4.9, “Switching Sources and Replicas with Asynchronous Connection Failover”.

  • asynchronous_connection_failover_delete_source()

    从复制通道的源列表中删除复制源服务器的配置信息。Remove configuration information for a replication source server from the source list for a replication channel.

    语法:Syntax:

    asynchronous_connection_failover_delete_source(channel, host, port, network_namespace)

    参数:Arguments:

    • channel:此复制源服务器属于源列表的复制通道。channel: The replication channel for which this replication source server was part of the source list.

    • host:此复制源服务器的主机名。host: The host name for this replication source server.

    • port: 此复制源服务器的端口号。port: The port number for this replication source server.

    • network_namespace: 此复制源服务器的网络命名空间。请指定为空字符串,因为此参数保留以备将来使用。network_namespace: The network namespace for this replication source server. Specify an empty string, as this parameter is reserved for future use.

    返回值:Return value:

    一个包含操作结果的字符串,例如操作是否成功。A string containing the result of the operation, for example whether it was successful or not.

    示例:Example:

    SELECT asynchronous_connection_failover_delete_source('channel2', '127.0.0.1', 3310, '');
    +------------------------------------------------------------------------------------------------+
    | asynchronous_connection_failover_delete_source('channel2', '127.0.0.1', 3310, '')              |
    +------------------------------------------------------------------------------------------------+
    | Source configuration details successfully deleted.                                             |
    +------------------------------------------------------------------------------------------------+
    

    有关更多信息,请参见 第 19.4.9 节,“使用异步连接故障转移切换源和副本”。For more information, see Section 19.4.9, “Switching Sources and Replicas with Asynchronous Connection Failover”.

  • asynchronous_connection_failover_reset()

    删除与异步连接故障切换机制相关的所有设置。该函数会清空 Performance Schema 表 replication_asynchronous_connection_failover 和 replication_asynchronous_connection_failover_managed。Remove all settings relating to the asynchronous connection failover mechanism. The function clears the Performance Schema tables replication_asynchronous_connection_failover and replication_asynchronous_connection_failover_managed.

    asynchronous_connection_failover_reset() 只能用于当前不属于任何组且没有运行任何复制通道的服务器。您可以使用此函数来清理不再被管理组使用的服务器。asynchronous_connection_failover_reset() can be used only on a server that is not currently part of a group, and that does not have any replication channels running. You can use this function to clean up a server that is no longer being used in a managed group.

    语法:Syntax:

    STRING asynchronous_connection_failover_reset()
    

    参数:Arguments:

    无。None.

    返回值:Return value:

    一个包含操作结果的字符串,例如操作是否成功。A string containing the result of the operation, for example whether it was successful or not.

    示例:Example:

    mysql> SELECT asynchronous_connection_failover_reset();
    +-------------------------------------------------------------------------+
    | asynchronous_connection_failover_reset()                                |
    +-------------------------------------------------------------------------+
    | The UDF asynchronous_connection_failover_reset() executed successfully. |
    +-------------------------------------------------------------------------+
    1 row in set (0.00 sec)
    

    有关更多信息,请参见 第 19.4.9 节,“使用异步连接故障转移切换源和副本”。For more information, see Section 19.4.9, “Switching Sources and Replicas with Asynchronous Connection Failover”.