当前位置:网站首页>Redis 主从同步
Redis 主从同步
2022-07-01 22:58:00 【Mar丶流年】
概念
runID 每一个redis实例的唯一标识,不知道对方runID 则以?代替
offset 复制进度 -1 代表第一次复制
第一次主从同步
由从实例发送 pysnc 告知主实例第一次连接
主实例将offset,和runID发送给从库
主实例再通过bgsave生成全量RDB,生成RDB期间及之后的操作命令写入到repl buffer
将RDB发送给从实例
从实例执行完RDB后,主实例再将repl buffer发送给从实例
主从网络闪断的恢复过程(增量复制)
主实例和从实例上都有一个环形缓冲区(repl_back_log)
主实例中的repl_back_log记录自己写到那里
从实例中的repl_back_log记录自己读到那里
主实例每执行一条命令会往repl_buffer,repl_back_log中写入记录
当主从恢复连接后。从实例将自己的已经读取的位置(slave_repl_offset)发送给主实例
主实例根据自己写到的位置(master_repl_offset),找到从实例缺失的数据(master_repl_offset - slave_repl_offset 区间段的数据) 发送给从实例同步
主从级联
在一主多从的模式下,如果数据同步都由主实例去同步,主实例承担比较大的压力
这时候可以将部分的同步任务交给先同步的实例去同步给未同步的实例。
将主实例比喻成老板,从实例比喻成员工,老板给员工分配任务要一个一个分配
但是如果将员工提拔为(总经理,总裁),那么老板把任务分配给它两,它两再分配给员工,这样就减轻了老板的压力
注意事项
由于 repl_back_log 是环形缓冲区
环形缓冲写完一个周期就会开始覆盖数据
如果主实例的写入速度大于从实例的读取速度,可能造成从实例还未读取的数据被主实例新写的操作覆盖了
所以合理设置环形缓冲区的大小很重要(repl_backlog_size)
查了下资料,一般设置成 (主实例写入命令速度 * 操作大小 - 主从网络传输命令速度 * 操作大小) * 2
边栏推荐
猜你喜欢
[applet] realize the left and right [sliding] list through the scroll view component
神经网络物联网的发展趋势和未来方向
为什么PHP叫超文本预处理器
Compare the version number [double pointer to intercept the string you want]
会声会影2022智能、快速、简单的视频剪辑软件
The online beggar function of Japanese shopping websites
Development trend and future direction of neural network Internet of things
CKS CKA CKAD 将终端更改为远程桌面
2022 R1 fast opening pressure vessel operation test questions and answers
ARP报文头部格式和请求流程
随机推荐
Three development trends of enterprise application from the perspective of the third technological revolution
认识--Matplotlib
[MySQL] database optimization method
每日三题 6.30
Understanding threads
openresty 负载均衡
马赛克后挡板是什么?
STM32F030F4驱动TIM1637数码管芯片
The difference between timer and scheduledthreadpoolexecutor
2022 crane driver (limited to bridge crane) examination questions and simulation examination
Matplotlib common settings
微服务服务稳定性治理
Typescript enumeration
【微服务|Sentinel】sentinel整合openfeign
plain framework的实际应用和扩展
Notes on problems - /usr/bin/perl is needed by mysql-server-5.1.73-1 glibc23.x86_ sixty-four
What is the mosaic tailgate?
from pip._internal.cli.main import main ModuleNotFoundError: No module named ‘pip‘
Which securities company is better and which is safer to open a securities account
SWT/ANR问题--SWT 导致 low memory killer(LMK)