当前位置:网站首页>Distributed quorum NWR of the alchemy furnace of the Supreme Master
Distributed quorum NWR of the alchemy furnace of the Supreme Master
2022-06-25 07:28:00 【Wukong chat architecture】
“Too white Venus : I heard that Lao Jun is practicing the magic pill recently , Can you tell me ?
Lord Lao Zi : Lao Bai , I'm practicing six pills recently : Two pieces
Yannian Dan、 Two piecesJianbu Dan、 Two piecesRecovery Dan.Too white Venus : These three Eight Trigram furnaces must be used to practice these three magic weapons ?
Lord Lao Zi : It's just . And for the same pills , The efficacy and size must be exactly the same .
”
One 、 How are the three alchemy furnaces distributed
“Too white Venus : Lao Jun , How do you distribute your Bagua stove ?
”
Let's uncover Lao Jun's Alchemy furnace , See how the six pills are distributed .
First of all, it's easy for us to guess how the alchemy furnace distributes alchemy :
Two pills in No.1 Dan furnace Yannian Dan.Two pills in No.2 Dan furnace Jianbu Dan.Two in No.3 Dan furnace Recovery Dan.
So what's wrong with this distribution ?
Let's think about , If No.1 Dan furnace bursts because the fire is too high , So the two Yannian dans are bound to fail . It's the same thing as putting eggs in a basket . If the basket is upset , All the eggs fall out of it , It's all broken .
“Lord Lao Zi : Laobai , I'll show you the cover of the boiler .
”
One pill in No.1 Dan furnace Yannian DanAnd oneJianbu Dan.Make one in No.2 Dan furnace Yannian DanAnd oneRecovery Dan.Make one in No.3 Dan furnace Jianbu DanAnd oneRecovery Dan.
“Too white Venus : Lao Jun , Why distribute it like this , The temperature of each pill is not so easy to control ?
Lord Lao Zi : Laobai , I'm a master of alchemy , The heat can't beat me .
Too white Venus : I am worthy of being Lao Jun , In this way, even if there is a problem with a Dan furnace , At least one can be made into , Not both .
”
Mapping to our Internet system : Dan furnace is similar to server node or database node , Through multiple nodes to backup data to each other to ensure the stability of the system High availability (High Availability).
Two 、 How to ensure the same quality of pills
2.1 Uniformity
“Too white Venus : Lao Jun , You just mentioned , Two Yannian pills need to have the same effect , The same size ?
Lord Lao Zi : Such is the case , The quality of pills must be consistent , What I make are all nine kinds of pills , The efficacy of the medicine is different .
”
Taishanglaojun said that the quality of keeping consistent, in the end what's going on ?
How to ensure the same quality of Yannian pill in No.1 Dan furnace and Yannian pill in No.2 Dan furnace ?
That's what we often say Distributed consistency Do you ? Two pills are distributed in different furnaces , Need to be consistent in quality .
As shown in the figure below , These two Yannian pills are big and small , There are also different colors , That's why the quality is different .
And in architecture design , For example, request access to different databases , All the data are the same , This is consistency .
As shown in the figure below : The browser accesses the database 1 And the database 2 Data in A, It turns out that all of them are A = 1.
2.2 Final and strong consistency
Consistency in distribution is divided into Final consistency and Strong consistency .
So-called Strong consistency After the write operation is completed , Any subsequent access can read the updated value . This is it. CP Consistency and partition fault tolerance required by the system ..
How to understand it in alchemy ?
For example, Lao Jun added to Yannian Dan of No.1 Dan furnace Lotus This kind of Medicine , Yannian Dan, who gave it to No.2 Dan furnace, did the same thing , So the ingredients of the two Yannian pills that Lao Bai opened the stove cover were the same .
and Final consistency It doesn't guarantee that all subsequent visits can read the updated values , But after a while , Read it again , You get the same value . in other words , In the meantime , It's possible to read old data . This is it. AP Availability and partition fault tolerance required by the system .
How to understand it in alchemy ?
For example, Lao Jun added lotus to Yan Nian Dan of No.1 Dan stove , And after an hour , Just add snow lotus to No.2 Dan stove , So in this hour , The ingredients of the two Yannian pills are different . But after an hour , The final ingredients are the same .
3、 ... and 、 Controllable quality :Quorum NWR agreement
“If Yannian pill must ensure strong consistency of quality , Jianbu Dan only needs to ensure the final consistency of quality , How to control this ?
”
This is not difficult for Lao Jun , Because Lao Jun knows distributed protocol :Quorum NWR.
Quorum The meaning of this word :( Of the meeting ) A quorum . Mainly look at the last three capital letters :N、W、R. from NWR To control consistency .
3.1 Parameters N
Let's take a look at the situation in Dan furnace , The two Yannian pills are backup to each other , It's equivalent to having two copies .
N It's called the number of copies , It's also called replication factor (Replication Factor). How many copies of the same data are there , therefore : Yannian Dan's N = 2. By analogy : Jianbu Dan's N = 2, Restore Dan's N = 2. As shown in the figure below :
that N Can it change ?
As shown in the figure below : For example, I want to practice 3 Yan Nian Dan , That is to say, every Dan stove has a long life Dan , Then put N Change to 3 That's all right. . And Jianbu pill only needs to refine one, which is enough to , No.1 Dan furnace is OK , therefore N = 1.
3.2 Parameters W
Specifies the number of copies N after , You can read and write the replica data .
Read operations : Check the situation of pills in the furnace . Write operations : Add herbs to pills 、 Raise the temperature .
How can multiple pills read and write ? For write operations , We have W Parameters , For read operations , We have R Parameters .
W It's called the write consistency level (Write Consistency Level), It means successful completion W Copy updates , To complete the write operation .
For example, the setting of Yannian Dan W = 2, When writing to Yannian Dan , It's done 2 When a copy is updated , To complete the write operation .
As shown in the figure below : Yannian Dan capital in No. 1 and No. 2 Dan furnaces Joined the Lotus , And the longevity pill in No. 3 furnace Not joined Lotus . That is, only two copies have been updated , accord with W = 2 This condition , The write and play operation is complete .
But you found no problem , Yannian Dan of No.3 Dan furnace has not been added to lotus , Then how to ensure that when taishanglaojun looks at the pills , I know that I have joined lotus ? That is, how to ensure the strong consistency of reading and writing , This is going to use the third parameter :R.
3.3 Parameters R
R It's called the read consistency level (Read Consistency Level), When reading a data object , Need to read R Copies , Then return R The latest copy of the data in the copies .
Back to the problem of alchemy , Set Yannian Dan's R = 2, That is, when we look at the situation of Yannian Dan , Just look at the situation of Yannian Dan in the two Dan furnaces , Then go back to the latest situation of Yannian Dan .
Suppose you are looking at Yannian Dan in No. 1 and No. 2 Dan furnace , The return situation is : Joined lotus . This scenario is consistent .
Suppose you are looking at Yannian Dan in No. 1 and No. 3 Dan furnace , Yannian Dan of No.1 Dan furnace has joined lotus , No.3 Dan stove is without lotus , But the last operation time of Yannian Dan in No.3 Dan furnace was earlier than that of No.1 Dan furnace , So return to the situation of Yannian Dan in No.1 Dan furnace : Joined lotus . This scenario is also consistent .
Through the above two scenes , We know , By setting R = 2, Even if you read the third data that has not been updated , It can also return the updated data , Achieve strong consistency .
3.4 Parameter combination
Parameters N、W、R Different combinations of will bring different consistency effects .
Take the example above ,N = 3,W = 2,R = 2,W + R > N, For clients , The whole system can guarantee strong consistency , It must be able to return the updated data .
When W + R <= N when , For clients , The whole system can only guarantee the final consistency , Old data may be returned during data access .
Different parameters , Different effects , Distributed systems need to be configured according to different scenarios .
Four 、 application
InfluxDB Enterprise Edition is a time series database , It has four levels of write consistency :
any:W + R < N,W = 1, After any node writes successfully , Or write Hinted-handoff cache ( Wait for the next retransmission ), Return success to client . one:W + R < N,W = 1, After any node writes successfully , Return success to client immediately , Does not include writing Hinted-handoff cache quorum:W + R > N, After most nodes write successfully , Return the success to the client .( requirement N Greater than 2) all:W = N, After all nodes are successfully written , Return to success .
In addition to Time series database InfluxDB Come on , Read operations need to read a lot of data , To ensure efficient reading , It doesn't support read consistency levels (R = N), But you can set the write consistency level to all, To achieve strong consistency .
InfluxDb Realized Quorum NWR, When the online business needs to make some temporary consistency adjustments , Set different write consistency levels to achieve fast switching .
5、 ... and 、 summary
This article talks about alchemy between Taishang Laojun and Taibai Jinxing , The distributed protocol of custom consistency is extended :Quorum NWR agreement .
Dan furnace is a metaphor for node , Pills are compared to data , Multiple pills are called copies .
N Represents the number of copies ,W Represents how many copies to write ,R Represents how many copies to read .
When N Greater than the number of nodes , There will be multiple copies of a node , When this node fails , Multiple copies will be affected .
W + R > N when , Stands for strong consistency .
W = N when , Good reading performance .R = N, Good writing performance .
W = R = (N+1)/2, Good fault tolerance , Be tolerant of A few nodes ( That is to say (N-1)/2) Node failure .
How to set up N、W、R value , It depends on where our system should be optimized .
Quorum NWR Distributed algorithms provide flexibility for businesses to choose consistency levels on demand , Make up for AP The drawback of the lack of strong consistency of the system .
“Too white Venus : I wish you success in alchemy ! I want to go Share and Leaving a message. 了 !
”
- END -
Author's brief introduction : The wu is empty ,8 Years of experience in Internet development and architecture , Use stories to explain 、 Architecture design .《JVM Performance optimization practice 》 Columnist , Open source 《Spring Cloud actual combat PassJava》 project , Independently developed a PMP Brush topic small program . Pay attention to free brush topic .
This article is from WeChat official account. - Wukong chat structure (PassJava666).
If there is any infringement , Please contact the [email protected] Delete .
Participation of this paper “OSC Source creation plan ”, You are welcome to join us , share .
边栏推荐
- From perceptron to transformer, a brief history of deep learning
- Lotus v1.16.0-rc2 Calibration net
- The significance and proof of weak large number theorem
- [Shangshui Shuo series] day 5
- LTpowerCAD II和LTpowerPlanner III
- Lotus windowsost manually triggers space-time proof calculation
- [he doesn't mention love, but every word is love]
- What is the new business model of Taishan crowdfunding in 2022?
- 【C语言】给字符串增加分隔符
- Can we use function pointers in go- Can we have function pointers in Go?
猜你喜欢

Practice of hierarchical management based on kubesphere

The e-book "action guide for large organizations to further promote zero code application platform" was officially released!

分布式锁中的王者方案 - Redisson

Event registration Apache pulsar x kubesphere online meetup hot registration

Why use NoSQL with MySQL?

【批處理DOS-CMD命令-匯總和小結】-外部命令-cmd下載命令、抓包命令(wget)

Enter an integer with any number of bits, and output the sum of each bit of the number. For example: 1234 – > 10

Cocos学习日记3——api获取节点、组件

Advanced mathematics foundation_ Parity of functions

用动图讲解分布式 Raft
随机推荐
网络是怎样连接的?
Editing the date formatting of x-axis tick labels in Matplotlib - editing the date formatting of x-axis tick labels in Matplotlib
MySQL (12) -- Notes on changing tables
单片机IO详解(上拉 下拉 准双向 输入 输出 推挽 开漏)
Harmony food menu interface
Escape analysis of 982 golang
Pratique de gestion hiérarchique basée sur kubesphere
In depth analysis of Apache bookkeeper series: Part 3 - reading principle
Operate cnblogs metaweblog API
1W字|40 图|硬核 ES 实战
Icon already includes gloss effects
How do I know if mysqlnd is an active driver- How to know if MySQLnd is the active driver?
Practice of hierarchical management based on kubesphere
【xxl-job】池塘水绿风微暖,记得玉真初见面
为什么要“除夕”,原来是内存爆了!
13 `bs_duixiang.tag标签`得到一个tag对象
What is the new business model of Taishan crowdfunding in 2022?
Harmony美食菜单界面
Too beautiful promise because too young
Weimeisi new energy rushes to the scientific innovation board: the annual revenue is 1.7 billion, and the book value of accounts receivable is nearly 400million







