当前位置:网站首页>KV database based on raft consensus protocol
KV database based on raft consensus protocol
2022-07-26 08:33:00 【biyezuopin】
be based on Raft Consensus agreement KV database
Project introduction
Distributed consistency is the basis of building fault-tolerant systems , It enables some machines to work in clusters , And allow some of these nodes to fail .Raft It is a common distributed consensus protocol ,Raft First, elect a server As Leader, Then give it full responsibility for managing logs .Leader Receive log entries from the client , Copy to other server, And tell them when they can safely apply log entries to their state machine . To have a Leader Can be simplified replicated log Management of . for example ,leader You can decide where to put new log entries , Without asking other nodes , Data is always simple from leader Flow to other nodes .Leader May fail or disconnect , In this case, a new one will be selected leader. Specific algorithm details can refer to the paper 《In search of an Understandable Consensus Algorithm》.
This project is based on Raft Distributed consensus protocol , Implement a simple KV database . This database supports 3 Operations , namely GET、PUT、APPEND.GET Operation can get a Key Corresponding Value.PUT Operation can make a Key Corresponding Value write in .APPEND The operation can set Value Append a written Key Corresponding Value On .
System architecture
every last server There is a log that stores a series of instructions ,state machine Will execute these instructions in sequence . Each log holds the same instructions in the same order , So every one state machine Process the same instructions ,state machine It's the same , Therefore, it will eventually reach the same state and output .
Guarantee replicated log Consistency is the task of consistency algorithm .server The consistency module in receives the instructions from the client and adds them to its own log , It can also be compared with other server The consistency module in the communication to ensure that every log Can have the same content and order , Even if some of them server Downtime . Once the instruction is copied correctly , It can be called committed. every last server The state machine in is processed in log order committed Instructions , And return the output to the client .
Source code analysis
Client code :
With GET Operation as an example . Because in a cluster , Only to be Leader Our server can handle user requests , So the client will cache when sending requests to the server Leader Information about . If the error returned is NotLeader, Will try again , Send the request to other servers .
Server code :
The same to GET Operation as an example , The server is receiving Get When asked , Will check whether you are Leader, If so, register a callback function . In another cycle , The server will listen successfully Commit Of Raft journal , And back to GET The result to the client .
Raft Module code :
Raft Modules are the most complex place , It implements the description in the reference paper :
stay Raft layer , There are three RPC call , namely sendRequestVote, sendAppendEntries, sendInstallSnapshot. among sendRequestVote For election Leader,sendAppendEntries Used to synchronize Raft Log and send heartbeat sendInstallSnapshot For fast recovery .
Test part
In order to verify Raft The correctness of the implementation of distributed consensus algorithm has enabled the server to correctly handle requests from clients , There are a lot of test cases in the project . These tests simulate various server outages , Network isolation . The KV The database can all pass these tests .
The test will simulate various server downtime , Network isolation . The KV The database can all pass these tests .
边栏推荐
- Date and time function of MySQL function summary
- Flitter imitates wechat long press pop-up copy recall paste collection and other custom customization
- 2022-7-9 personal qualifying 6 competition experience
- QT note 2
- How to safely delete a useless activity in Android studio
- The second lesson is the construction of development environment
- Shell programming
- vscode国内的镜像服务器加速
- flink oracle cdc 读取数据一直为null,有大佬知道么
- A summary of practical websites that won't brighten people's eyes
猜你喜欢
小蜜蜂吉他谱 高八度和低八度
基于C语言的内存管理-动态分区分配方式模拟
Matplotlib learning notes
Special lecture 2 dynamic planning learning experience (should be updated for a long time)
Mysql8 one master one slave +mycat2 read write separation
Mysql/mariadb (Galera multi master mode) cluster construction
【C语言】程序员筑基功法——《函数栈帧的创建与销毁》
NLP (natural language processing) natural language processing learning
Dev gridcontrol captures key events
Lesson 3: gcc compiler
随机推荐
C # get the information of the selected file
The first ide overlord in the universe, replaced...
苹果强硬新规:用第三方支付也要抽成,开发者亏大了!
Why reserve a capacitor station on the clock output?
请问现在flinkcdc支持sqlserver实例名方式连接吗?
Summary of common skills
The most complete network: detailed explanation of six constraints of MySQL
Basic music theory rhythm connection problem, very important
Share high voltage ultra low noise LDO test results
22-07-14 personal training match 2 competition experience
How to safely delete a useless activity in Android studio
22-07-16 personal training match 3 competition experience
Status management bloc provider geTx
小蜜蜂吉他谱 高八度和低八度
23.10 Admin features
[endnote] compilation of document types and abbreviations of document types
QT uses QSS to make a beautiful login interface (hand-in-hand teaching)
Kotlin program control
Mysql8 dual master and dual slave +mycat2 read / write separation
Shell homework the next day