mysql 5.5 中如何对SLAVE relay

57次阅读
没有评论

共计 2847 个字符,预计需要花费 8 分钟才能阅读完成。

这期内容当中丸趣 TV 小编将会给大家带来有关 mysql 5.5 中如何对 SLAVE relay-log 相关日志文件同步的强化,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

在 5.1 版本中,slave 从 MASTER 拿到日志后,写到 relay-log, 并进行 SQL 应用;
在这里注意,写到 RELAY-LOG,指的是先写到“OS cache”的 relay-log,而不是马上刷新到磁盘上;
什么时候刷新还依赖于操作系统的 CACHE 刷新时间;

[@more@]

如果在这期间,一个日志刚同步到 relay-log @os cache , 而没有被刷新到 relay-log @disk , OS CRASH, 那么这个日志将丢失;
(这个问题不用担心:MYSQL 会在重启后重新从 MASTER 获取日志)

同样存在一致问题的相关 SLAVE 文件还有:relay-log.info ; master.info;
如果这两个文件发生不一致,问题就不那么好办了;很可能发生重复执行 SQL 或重新读取日志;

在 V5.5 中,MYSQL 对这一块进行了强化,增加三个参数:
sync_relay_log_info # default 0
sync_master_info    # default 0
sync_relay_log      # default 0

让他们来控制,每隔多少个 SLAVE 日志“语句 / 事务”,触发同步一次相关文件;
———————————————————–

# sync_relay_log_info

If the value of this variable is greater than 0,
a replication slave synchronizes its relay-log.info file to disk (using fdatasync()) after every sync_relay_log_info transactions.
A value of 1 is the generally the best choice.
The default value of sync_relay_log_info is 0,
 which does not force any synchronization to disk by the MySQL server—in this case,
 the server relies on the operating system to flush the relay-log.info file s contents from time to time as for any other file.

# sync_master_info

If the value of this variable is greater than 0,
a replication slave synchronizes its master.info file to disk (using fdatasync()) after every sync_master_info events.

The default value of sync_relay_log_info is 0 (recommended in most situations),
which does not force any synchronization to disk by the MySQL server;
in this case, the server relies on the operating system to flush the master.info file s contents from time to time as for any other file.

# sync_relay_log

If the value of this variable is greater than 0,
the MySQL server synchronizes its relay log to disk (using fdatasync()) after every sync_relay_log writes to the relay log.
There is one write to the relay log per statement if autocommit is enabled, and one write per transaction otherwise.
The default value of sync_relay_log is 0, which does no synchronizing to disk—in this case,
the server relies on the operating system to flush the relay log s contents from time to time as for any other file.
A value of 1 is the safest choice because in the event of a crash you lose at most one statement or transaction from the relay log.
However, it is also the slowest choice (unless the disk has a battery-backed cache, which makes synchronization very fast).

他们的工作模式和效果有点像:sync_binlog 参数,在设置的时候我们要注意 IO 性能评估,特别是对 relay-log 的 sync;
一般的 SLAVE,即打开 BINLOG 写,现在又要频繁刷新 relay-log 写,对 IO 的压力有所增加;

比如:relay-log.info 的刷新:
假如我们最安全地设置 sync_relay_log_info=1,那么每执行完一个 SQL/ 事务,SLAVE 进程更新 relay-log.info 后,就需要刷到 DISK;
假设我们机器能执行 QPS=1000,这也就要求 relay-log.info 刷新 1000 次;(当然 DISK 如果有 RAID CACHE,并且 write-back 生效;情况会好很多)
算起来还是很吓人的;

但考虑到 SLAVE 一般不承载 SELECT 带来的压力;所以压力一般不会超过 MASTER;
只要 MASTER 与 SLAVE 硬件配置相当;应该是不用担心这个问题;

另外,v5.5 中还有一个参数:relay_log_recovery,
当被设置成 ENABLED,在 CRASH 后自动放弃所有未执行的 relay-log, 并且重新从 MASTER 获取日志;这样保证 relay-log 的完整;

在服务器启动后立即启用自动中继日志恢复,

这意味着复制从机将丢弃所有未处理的中继日志

并从复制主机检索它们。

这应该在复制从机崩溃后使用,以确保不会处理可能损坏的中继日志。

默认值为 0(已禁用)。

可以动态更改此全局变量,或者通过使用 –relay log recovery 选项启动从机来更改。

上述就是丸趣 TV 小编为大家分享的 mysql 5.5 中如何对 SLAVE relay-log 相关日志文件同步的强化了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注丸趣 TV 行业资讯频道。

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-19发表,共计2847字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)