当前位置:网站首页>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
边栏推荐
- flutter Unable to load asset: assets/images/888. png
- Zero foundation tutorial of Internet of things development
- Programming English vocabulary notebook
- Some thoughts on game performance optimization
- mysql binlog的清理
- "35 years old, the boss of the company, with a monthly salary of 20000, give away takeout": the times abandoned you, not even saying goodbye
- SWT / anr problem - SWT causes kernel fuse deadlock
- Matplotlib common charts
- Three development trends of enterprise application from the perspective of the third technological revolution
- Is it safe to choose mobile phone for stock trading account opening in Shanghai?
猜你喜欢

mt管理器测试滑雪大冒险

Stm32f030f4 drives tim1637 nixie tube chip

AirServer最新Win64位个人版投屏软件

2022 examination questions and online simulation examination for safety management personnel of hazardous chemical business units

建模和影视后期有什么关联?
![[understanding of opportunity-35]: Guiguzi - flying clamp - the art of remote connection, remote control and remote testing](/img/08/9ecfd53a04e147022dde3449aec132.png)
[understanding of opportunity-35]: Guiguzi - flying clamp - the art of remote connection, remote control and remote testing

2022年R1快开门式压力容器操作考题及答案

AAAI22 | 结构标记和交互建模:用于图分类的“SLIM”网络

What is the relationship between modeling and later film and television?

The online beggar function of Japanese shopping websites
随机推荐
认识--Matplotlib
Redis~02 cache: how to ensure data consistency in MySQL and redis when updating data?
想请教股票开户要认识谁?在线开户是安全么?
众昂矿业:发展以氟化工为主的特色化工产业具有先天优势
CKS CKA ckad change terminal to remote desktop
Yunxin small class | common cognitive misunderstandings in IM and audio and video
Daily three questions 6.30 (2)
Leetcode(34)——在排序数组中查找元素的第一个和最后一个位置
flutter Unable to load asset: assets/images/888. png
Commemorate becoming the first dayus200 tripartite demo contributor
Is it safe to choose mobile phone for stock trading account opening in Shanghai?
云信小课堂 | IM及音视频中常见的认知误区
CKS CKA CKAD 将终端更改为远程桌面
Jielizhi Bluetooth headset quality control and production skills [chapter]
共享电商的背后: 共创、共生、共享、共富,共赢的共富精神
Who do you want to know when opening a stock account? Is it safe to open an account online?
认识线程
Daily three questions 6.28
玻璃马赛克
Why is PHP called hypertext preprocessor



