当前位置:网站首页>Read the configuration, explain the principle and read the interview questions. I can only help you here...
Read the configuration, explain the principle and read the interview questions. I can only help you here...
2022-06-25 15:50:00 【InfoQ】
Master slave Topology


REPLICATION
replicaof
<masterip> <masterport>
- Redis Replication is asynchronous , It can be modified by master Configuration of , stay master Not associated with the given number of replica When the connection , The host stops receiving writes ;
- If the replication link is lost for a relatively short time ,Redis replica It can be done with master Perform partial resynchronization , Can use reasonable backlog Value to configure (See below);
- Replication is automatic , No user intervention is required . After the network partition ,replica Will automatically attempt to reconnect to master And with master To resynchronize ;
masterauth
<master-password>
replica-serve-stale-data yes
- replica-serve-stale-data:yes( The default value is ), be replica Will still respond to client requests , There may be expired data , Or if this is the first synchronization , Then the dataset may be empty .
- replica-serve-stale-data:no , replica All requested commands will be ( But does not contain INFO, replicaOF, AUTH, PING, SHUTDOWN, REPLCONF, ROLE, CONFIG, SUBSCRIBE, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, PUBLISH, PUBSUB, COMMAND, POST, HOST: and LATENCY) returnSYNC with master in progressError of .
replica-read-only
CONFIG SETrename-commandrepl-diskless-sync
- Disk-backed:Redis master Node creates a new process and will RDB File is written todisk, The file is then incrementally transferred to... Through the parent process replicas node ;
- Diskless:Redis master Node creates a new process and directly RDB The file is written to replicas Of sockets in , Do not write to disk .
- When doing disk-backed Replication time , RDB File generation finished , Multiple replicas adoptline upSynchronization RDB file .
- When doing diskless Replication time ,master The node will wait for some time ( The lower one repl-diskless-sync-delay To configure ) Retransmission to expect multiple replicas Connect in , such master The node canSimultaneous synchronizationTo more than one replicas node . If the waiting time is exceeded , You need to line up , Wait for the current replica After processing, proceed to the next replica To deal with .
repl-diskless-sync-delay
repl-ping-replica-period
repl-timeout
- from replica From the point of view of nodes SYNC In process I/O transmission —— Have not received master SYNC Transmission of rdb snapshot data ;
- from replica From the point of view of nodes master Of timeout( Such as data,pings)—— replica Have not received master Send packets or ping;
- from master From a node point of view replica Of timeout( Such as REPLCONF ACK pings)—— master Have not received REPLCONF ACK The confirmation of ; It should be noted that , This option must be greater than repl-ping-replica-period, Otherwise, in the master and replica It often happens when there is low traffic between timeout.
repl-disable-tcp-nodelay
- If you choose “yes”,Redis Will use less TCP Packets and less bandwidth replicas send data . But this will increase the data in replicas End display delay , For... Using the default configuration Linux kernel , Delay reachability 40 millisecond .
- If you choose “no”, Then the data appears in replicas The end delay will be reduced , But replication will use more bandwidth .
repl-backlog-size
repl-backlog-ttl
replica-priority
min-replicas-to-write
min-replicas-max-lag
// Indicates that at least 3 A delay <=10 A copy of seconds exists
min-replicas-to-write 3 // In the following N
min-replicas-max-lag 10 // In the following M
- replica Every second ping master, Confirm the number of replication streams processed ;
- master Will remember the last time from each replica All received ping Time for , Delay is based on master from replica Last time received ping Calculated ;
- The user can configure the minimum delay that does not exceed the maximum number of seconds replica Count ;
replica-announce-ip 5.5.5.5
replica-announce-port 1234
- IP: Connect to by automatic identification Socket Automatic acquisition of information
- Port: Generally speaking, this value is replicas The listening port used by the node to accept the connection of the client
principle
The operation of the system depends on three main mechanisms
- When one master Instance and a replica When the instance connection is normal , master A series of command streams will be sent to keep replica Update , In order to copy the changes of its own dataset to replica , Include client writes 、key Expired or expelled, etc .
- When master and replica After the connection between , Because of the network problem 、 Or master-slaveconsciousnessConnection to timed out , replica Reconnect on master And will try to do some resynchronization . This means that it tries to get only the command stream that was lost during the disconnect .
- When partial resynchronization is not possible , replica Full resynchronization will be requested . This involves a more complex process , for example master You need to create a snapshot of all the data , Send it to replica , After that, when the data set changes, the command stream will be continuously sent to replica .
Redis How replication works
Redis masterreplication IDReplication ID, offsetFull amount of synchronization

- replica Connect master, send out PSYNC command ;
- master perform bgsave Start a background save process , In order to produce a RDB file . At the same time, it starts buffering all new write commands received from the client .
- When the background save is complete , master Transfer the dataset file to all replica, And continue to record the write commands executed during the send ;
- replica received RDB After the document , Discard all the old data , Then load the new file into memory ;
- replica After loading , notice master Send all buffered commands to replica, This process is completed in the form of instruction flow and is similar to Redis The format of the agreement itself is the same ;
- replica Start receiving command requests , And execution from master Write command to buffer .
The incremental synchronization
- If not, give replica send out CONTINUE, wait for master take backlog The data in is sent to replica;
- If it exceeds, return FULLRESYNC runid offset,replica take runid Save up , And conduct full synchronization ;
Interview questions
In the master-slave replication process , close master What problems will be caused by the persistence of ?
- We set up nodes A by master And turn off its persistence settings , Set nodes B and C by replica;
- When master Crash Time , Because the script of automatic restart is configured in the system , here master It will restart automatically . But because persistence is turned off ,master After restart, its data set is empty ;
- here , If replica from master Data synchronization in , It will lead to replica The data in will also become an empty set .
Redis How to deal with replication key The expiration of
- replica Will not let key Be overdue , But wait master Give Way key Be overdue . When one master To make a key expire ( Or because of LRU The algorithm expels it ) when , It will synthesize a DEL Command and transfer to all replica;
- Due to the main drive ,master Unable to provide in time DEL command , So sometimes replica There may still be logically expired... In your memory key. In order to deal with this problem ,replica Use its logical clock to report without violating data consistency , Of the read operation key non-existent . by this means ,replica Avoid reporting logic that is out of date key There is still . in application , Use replica Program extension HTML Fragment cache , It will avoid returning data items that are already earlier than expected .
- stay Lua During script execution , Do not execute any key Expiration action . When one Lua Script runtime , conceptually ,master The time in is frozen , So when the script runs , A given key either exists or does not exist . This prevents key Expire in the middle of the script , Make sure to send the same script to replica , This produces the same effect in both data sets .
边栏推荐
- Free books! AI across the Internet paints old photos. Here is a detailed tutorial!
- golang reverse a slice
- Multithreading, parallelism, concurrency, thread safety
- 不要小看了积分商城,它的作用可以很大!
- 合宙Air32F103CBT6開發板上手報告
- Popular cross domain
- 免费送书啦!火遍全网的AI给老照片上色,这里有一份详细教程!
- Sword finger offer 06 Print linked list from end to end
- Resolve Visio and office365 installation compatibility issues
- 合宙Air32F103CBT6开发板上手报告
猜你喜欢

Globally unique key generation strategy - implementation principle of the sender

Binocular 3D perception (I): preliminary understanding of binocular

Talk about the creation process of JVM objects
Introduction to database transactions

不要小看了积分商城,它的作用可以很大!

基于神经标签搜索,中科院&微软亚研零样本多语言抽取式摘要入选ACL 2022
Check whether the port number is occupied

剑指 Offer 03. 数组中重复的数字

VectorDraw Developer Framework 10.1001 Crack

说下你对方法区演变过程和内部结构的理解
随机推荐
说下你对方法区演变过程和内部结构的理解
剑指 Offer 05. 替换空格
JS的注释
剑指 Offer 04. 二维数组中的查找
镁光256Gb NAND Flash芯片介绍
For the first time in Chinese universities! Unique in the world! Tongji students win international awards
Principle and implementation of MySQL master-slave replication (docker Implementation)
04. binary tree
Start using markdown
Super comprehensive custom deep copy function
基于神经标签搜索,中科院&微软亚研零样本多语言抽取式摘要入选ACL 2022
Talk about the creation process of JVM objects
QC, QA, IPQC, JQE, DQA, SQE, DQC, MQC, IQC, FQC, OQC
Lombok common notes
Open the box to experience rust, come on!!!
Globally unique key generation strategy - implementation principle of the sender
golang reverse a slice
Share the code technology points and software usage of socket multi client communication
TFIDF and BM25
MySQL修改字段语句