当前位置:网站首页>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 .
边栏推荐
- What languages can be decompiled
- Paper notes: multi label learning bp-mll
- Tree list under winfrom treelist related
- Station B crazy God notes
- A small soft raster engine with clear thinking and a case of quaternion combination
- redis-1. Install redis with pictures and texts
- [splashsplash] repeat the script that outputs splashsurf
- No configure file found when compiling PHP from source code
- Compilation and development process of Quanzhi v3s environment
- c#高級編程-特性篇
猜你喜欢
JMeter encryption interface test
C#合并多个richtextbox内容时始终存在换行符的解决方法
Redis learning journey sentinel mode
Find the first and last positions of elements in a sorted array
Considerations for using redis transactions
Department store center supply chain management system
Simple understanding of basic language of C language
redis-0. Introduction to redis and NiO principle (random talk)
redis-4. Redis' message subscription, pipeline, transaction, modules, bloom filter, and cache LRU
AQS - detailed explanation of reentrantlock source code
随机推荐
Tidb data migration (DM) Introduction
Classification of databases
Deploy RDS service
8. process status and transition
Department store center supply chain management system
P1434 [SHOI2002] 滑雪 (记忆化搜索
Hashtable source code analysis
JMeter encryption interface test
Some optimization for seckill project
C # using multithreading
Implementation of fruit mall wholesale platform based on SSM
redis-2. Redis string type & bitmap
平衡二叉树学习笔记------一二熊猫
A solution to the problem that there is always a newline character when C merges multiple RichTextBox contents
Calculate running total / running balance
oracle问题,字段里面的数据被逗号隔开,取逗号两边数据
Functions about Oracle.
A small soft raster engine with clear thinking and a case of quaternion combination
Questions about ETL: io trino. jdbc. TrinoDriver
2021-10-20