温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

mysql 5.5 中如何对SLAVE relay-log相关日志文件同步的强化

发布时间:2021-11-16 16:36:45 来源:亿速云 阅读:152 作者:柒染 栏目:MySQL数据库

这期内容当中小编将会给大家带来有关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选项启动从机来更改。

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

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI