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

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 14 函数和运算符 / 14.18 复制函数 / 14.18.4 基于位置的同步函数
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 82%

14.18.4 基于位置的同步函数14.18.4 Position-Based Synchronization Functions

本节中列出的函数用于控制 MySQL 复制中源服务器和从服务器的基于位置的同步。The functions listed in this section are used for controlling position-based synchronization of source and replica servers in MySQL Replication.

表 14.28 位点同步函数Table 14.28 Positional Synchronization Functions

名称Name 说明Description 已弃用Deprecated
MASTER_POS_WAIT() 阻塞,直到副本已读取并应用到指定位置的所有更新Block until the replica has read and applied all updates up to the specified position 是Yes
SOURCE_POS_WAIT() 阻塞,直到副本已读取并应用到指定位置的所有更新Block until the replica has read and applied all updates up to the specified position

  • MASTER_POS_WAIT(log_name,log_pos[,timeout][,channel])

    已废弃别名,用于 SOURCE_POS_WAIT()。Deprecated alias for SOURCE_POS_WAIT().

  • SOURCE_POS_WAIT(log_name,log_pos[,timeout][,channel])

    此功能用于控制源与副本的同步。它会阻塞,直到副本已读取并应用源二进制日志中指定位置之前的所有更新。This function is for control of source-replica synchronization. It blocks until the replica has read and applied all updates up to the specified position in the source's binary log.

    返回值是副本为了推进到指定位置而必须等待的日志事件数量。如果复制 SQL 线程未启动、副本的源信息未初始化、参数不正确或者发生错误,函数返回 NULL。如果超时,函数返回 -1。如果在 SOURCE_POS_WAIT() 等待期间复制 SQL 线程停止,函数返回 NULL。如果副本已经超过指定位置,函数会立即返回。The return value is the number of log events the replica had to wait for to advance to the specified position. The function returns NULL if the replication SQL thread is not started, the replica's source information is not initialized, the arguments are incorrect, or an error occurs. It returns -1 if the timeout has been exceeded. If the replication SQL thread stops while SOURCE_POS_WAIT() is waiting, the function returns NULL. If the replica is past the specified position, the function returns immediately.

    如果二进制日志文件位置已被标记为无效,该函数会等待直到已知有效的文件位置。当为复制通道设置了 CHANGE REPLICATION SOURCE TO 选项 GTID_ONLY,并且服务器重新启动或复制停止时,二进制日志文件位置可能被标记为无效。在事务成功应用超过给定文件位置之后,文件位置变为有效。如果应用程序未到达指定位置,该函数会等待直到超时。使用 SHOW REPLICA STATUS 语句可以检查二进制日志文件位置是否已被标记为无效。If the binary log file position has been marked as invalid, the function waits until a valid file position is known. The binary log file position can be marked as invalid when the CHANGE REPLICATION SOURCE TO option GTID_ONLY is set for the replication channel, and the server is restarted or replication is stopped. The file position becomes valid after a transaction is successfully applied past the given file position. If the applier does not reach the stated position, the function waits until the timeout. Use a SHOW REPLICA STATUS statement to check if the binary log file position has been marked as invalid.

    在多线程副本中,该函数会等待直到达到由 replica_checkpoint_group 或 replica_checkpoint_period 系统变量设置的限制时间,当调用检查点操作以更新副本状态时。因此,根据系统变量的设置,该函数可能会在指定位置到达后的一段时间才返回。On a multithreaded replica, the function waits until expiry of the limit set by the replica_checkpoint_group or replica_checkpoint_period system variable, when the checkpoint operation is called to update the status of the replica. Depending on the setting for the system variables, the function might therefore return some time after the specified position was reached.

    如果使用二进制日志事务压缩,并且在指定位置的事务负载是压缩的(作为 Transaction_payload_event),该函数会等待直到整个事务被读取并应用,并且位置已更新。If binary log transaction compression is in use and the transaction payload at the specified position is compressed (as a Transaction_payload_event), the function waits until the whole transaction has been read and applied, and the positions have updated.

    如果指定了timeout值,SOURCE_POS_WAIT()将在经过timeout秒后停止等待。timeout必须大于或等于 0。(当服务器在严格 SQL 模式下运行时,负的timeout值会立即被ER_WRONG_ARGUMENTS拒绝;否则函数返回NULL,并触发警告。)If a timeout value is specified, SOURCE_POS_WAIT() stops waiting when timeout seconds have elapsed. timeout must be greater than or equal to 0. (When the server is running in strict SQL mode, a negative timeout value is immediately rejected with ER_WRONG_ARGUMENTS; otherwise the function returns NULL, and raises a warning.)

    可选的channel值允许您指定该函数适用于哪个复制通道。有关更多信息,请参见第 19.2.2 节,“复制通道”。The optional channel value enables you to name which replication channel the function applies to. See Section 19.2.2, “Replication Channels” for more information.

    该函数在基于语句的复制中不安全。如果在 binlog_format 设置为 STATEMENT 时使用此函数,将记录一个警告。This function is unsafe for statement-based replication. A warning is logged if you use this function when binlog_format is set to STATEMENT.