redis 设计与实现(1)redis 数据结构
参考:https://wangcy6.github.io/post/2020/server_redis/
缘起



- 整数集合 



- hashtable 的 val 可能存储很多东西 

- 转换规则 

- 有序集合 zset(ziplist,shiplist) 


- 对比mysql索引设计(hash索引,b+索引) 


- 为什么字符串太长 64字节,进行转换?我也不清楚 

单机数据库如何存这些key


RDB持久化
思考:
- 如何持久化,废话不就是fork进程吗 
- 主备同步不是有复制积压缓冲区吗?为什么不采用这个。 
行动:


- 还有其他缓冲区吗? 
https://www.cnblogs.com/gangdou/p/7991754.html

描述:
output-buffer-limits这个参数的作用是:
当客户端来获取数据的时候,数据会被保存在output-buffer中,
等信息传输完后output-buffer中的数据会被清理掉,redis对output-buffer做了限制。
psync的命令超过了output-buffer-limits,master主动关闭了slave的连接。
然后slave被断开了和master的连接,然后slave又重新找master请求同步,然后就陷入了恶性循环,
slave找master做全同步的过程是一个很消耗cpu消耗io消耗带宽的过程,所以会一直持续的告警。




一个完整复制过程:
https://redis.io/topics/replication








https://github.com/redis-io/redis/issues/4316
https://redislabs.com/blog/the-endless-redis-replication-loop-what-why-and-how-to-solve-it/
Replication in Redis is like to a dialog between a slave, (or an apprentice), and its master.
This conversation runs along the these lines:
- Apprentice: “I want to learn and to become like you.” 
- Master: “PATIENCE YOU MUST HAVE my young padawan. Hmmmmmm.” 
- The Master forks itself, and…The forked process dumps the dataset to a disk file (RDB),The main process continues serving regular client requests, and Any changes made to the data are copied to a replication buffer on the main process. 
- Once the dump is done, the Master says: “Come and get it while, hot, is it.” 
- The apprentice reads the file over the network and writes it to its own disk. 
- Once it has the file stored locally, the apprentice loads it. 
- After loading is finished, the apprentice asks: “Well, I finished my circle. I’m ready.” 
- If there are any changes in the buffer, the Master says: “Ready you are? What know you of ready? Feel the Force!” and replays the stored changes to the slave. 
- After there are no changes left to replay from the buffer, the Master says: “No more training do you require. Already know you, that which you need.” 
- From that moment, any new change request that the master is given is then also replayed to the apprentice. 











 
    
评论 (1 条评论)