当前位置:网站首页>Redis master-slave replication - the underlying principle of partial resynchronization
Redis master-slave replication - the underlying principle of partial resynchronization
2022-06-13 07:34:00 【A hard-working dog】
Implementation of partial resynchronization
The partial resynchronization function consists of three parts :
- The replication offset of the primary server and the replication offset of the secondary server
- Replication backlog buffer for primary server
- Running the server ID
Copy offset
Both the master and slave servers executing replication will save a replication offset :
- Each time the master server propagates to the server N A byte of data , Just copy your own offset +N
- Each time the slave server receives a message from the master server N Bytes of data , Add the value of your copy offset to N
Start state
Suppose... Is transmitted 14 Status after bytes
By comparing the replication offsets of the master and slave servers, we can determine whether the master and slave servers are in a consistent state , Same in , The difference is not in .
Copy squash buffer
The replication squeeze buffer is a fixed length queue maintained by the server , The default size is 1MB( The length of a fixed length queue is fixed , Only when the number of queued elements is greater than the queue length , The first element to join the queue will be ejected , New elements will join the team ).
The replication buffer of the master server will hold some recently propagated write commands , And the copy squeeze buffer will record the corresponding offset for each byte in the queue
Offset | .... | 10087 | 10088 | 10089 | 10090 | 10091 | 10092 | 10093 |
Byte value | .... | '*' | 3 | '\r' | '\n' | 's' | 4 | 'T' |
When the secondary server reconnects to the primary server , The slave server will go through PSYNC Command to copy its own offset offset Send to the main server , The master server will determine what kind of synchronous replication to perform on the slave server based on this replication offset
- If offset Data after offset ( That is to say offset+1 The data of ) Still exists in the copy squeeze buffer , Then the master server will perform partial synchronization
- If there is no copy buffer inside , Then the master server enters the complete synchronization operation
Server running ID
Every Reids Every server has its own running ID, function ID Automatically generated when the server starts , from 40 Random hexadecimal characters .
When the primary server is replicated from the secondary server for the first time , The main server will run its own ID Send to slave , And the slave server will run this ID Save up , When the slave is disconnected and reconnected to a primary server , The slave server will send the previously saved run to the current master server ID:
- If Run saved from the server ID And the current connection to the main server running ID identical , So it means that the master server that is currently connected is the one that is copied before disconnection from the server , The primary server can try to perform partial resynchronization
- If the run saved from the server ID And the current connection to the main server running ID Is not the same , So the primary server copied before disconnection from the server is not the currently connected primary server , The master server will fully synchronize the slave server .
边栏推荐
- Why should two judgment expressions in if be written in two lines
- Pdf to word
- 11.29 Li Kou swipes questions every day
- 8. process status and transition
- China phosphate market in-depth analysis and investment prospect forecast report 2022-2028
- Questions about ETL: io trino. jdbc. TrinoDriver
- socket编程2:IO复用(select && poll && epoll)
- Wechat applet - positioning, map display, route planning and navigation
- Find the first and last positions of elements in a sorted array
- [log framework] add user-defined parameters to the MDC implementation log
猜你喜欢
Mui mixed development - when updating the download app, the system status bar displays the download progress
Redis learning journey master-slave replication
关于#数据库#的问题:PGADMIN4 编辑sql窗口问题
How worker threads in the thread pool are recycled
论文笔记: 多标签学习 BP-MLL
Problems encountered during commissioning of C # project
redis-2. Redis string type & bitmap
Redis learning journey sentinel mode
量化框架backtrader之一文读懂Analyzer分析器
Data desensitization tool advance tool Datamask
随机推荐
Real time lighting of websocket server based on esp32cam
redis-0. Introduction to redis and NiO principle (random talk)
RT thread simulator lvgl control: slider control
C # using multithreading
First graphical interface (modified version)
5xx series problem solving
How to stop PHP FPM service in php7
. Net code to implement get request and post request
mysql中时间字段 比较时间大小
[Yu Yue education] econometrics reference materials of Jiujiang University
Questions about ETL: io trino. jdbc. TrinoDriver
Functions about Oracle.
redis-2. Redis string type & bitmap
2021-10-20
关于c#委托、事件相关问题
Considerations for using redis transactions
思路清晰的软光栅小引擎和四元数结合案例
Performance tuning can't just depend on tapping the brain
It's called the next generation monitoring system. Let's see how awesome it is
Precautions for passing parameters with byte array