当前位置:网站首页>Etcd database source code analysis - brief process of processing entry records
Etcd database source code analysis - brief process of processing entry records
2022-07-04 23:16:00 【Tertium FATUM】
(1) When the client etcd After the cluster sends a request , Encapsulation in request Entry Records will be submitted to etcd-raft Module processing , among ,etcd-raft The module will first Entry Record saved to raftLog.unstable in .
We use ETCD Database source code analysis —— Server side PUT technological process For example ,kvServer Structure Put Function processing flow is as follows : First, all aspects of the request message will be checked , After checking, all the requests will be sent to the encapsulated RaftKV Interface for processing , After receiving the response message after the processing is completed , Will pass header.fill() Method to fill in the header information of the response , Finally, the complete response message is returned to the client . therefore , Track down srv.(KVServer).Put(ctx, in) In fact, it's called (s *EtcdServer) Put() function .
from raftRequestOnce The process sees that the final call is (s *EtcdServer) processInternalRaftRequestOnce(…) function , There is a key call in this function s.r.Propose(cctx, data).s yes EtcdServer, r Is its member variable raftNode, That's getting into raft The rhythm of the agreement . Through to Propose Function trace , We can see that the final function comes stepWithWaitOption
// raft/node.go
func (n *node) Propose(ctx context.Context, data []byte) error {
return n.stepWait(ctx, pb.Message{
Type: pb.MsgProp, Entries: []pb.Entry{
{
Data: data}}}) } // Here to Message Combined with the Type by pb.MsgProp,Entry For newcomers PutRequest
func (n *node) stepWait(ctx context.Context, m pb.Message) error {
return n.stepWithWaitOption(ctx, m, true) }
// Step advances the state machine using msgs. The ctx.Err() will be returned, if any.
func (n *node) stepWithWaitOption(ctx context.Context, m pb.Message, wait bool) error {
if m.Type != pb.MsgProp {
// It won't go here
select {
case n.recvc <- m: return nil
case <-ctx.Done(): return ctx.Err()
case <-n.done: return ErrStopped
}
}
ch := n.propc // Take out node Provided by the structure propc passageway
pm := msgWithResult{
m: m}
if wait {
pm.result = make(chan error, 1) }
select {
case ch <- pm: if !wait {
return nil } // Will have msg Of pm The structure is placed in propc passageway
case <-ctx.Done(): return ctx.Err()
case <-n.done: return ErrStopped
}
select {
case err := <-pm.result:
if err != nil {
return err }
case <-ctx.Done(): return ctx.Err()
case <-n.done: return ErrStopped
}
return nil
}
from raft/node.go Of run The function shows , When from propc Take it out of the channel msgWithResult, Taking messages out of it msg, Set up msg The source node of is this node id. And then call raft Modular Step Function driven state machine .
(2)etcd-raft The module will Entry The record is encapsulated into the above Ready In the example , Return to the upper module for persistence .
(3) When the upper module receives the to be persisted Entry After recording , It will be recorded to WAL Log file , And then do the persistence operation , The final notice etcd-raft Module processing .
(4) here etcd-raft The module will put this Entry Record from unstable Move to storage Kept in .
(5) To be Entry When records are copied to more than half of the nodes in the cluster , The Entry The record will be Leader The node is confirmed as submitted (committed), And encapsulate it into Ready The instance is returned to the upper module .
(6) At this time, the upper module can transfer the Ready To be applied carried in the instance Entry Records are applied to the state machine .
边栏推荐
- MariaDB的Galera集群-双主双活安装设置
- 【图论】拓扑排序
- CTF competition problem solution STM32 reverse introduction
- The small program vant tab component solves the problem of too much text and incomplete display
- Observable time series data downsampling practice in Prometheus
- Redis introduction complete tutorial: slow query analysis
- 数据库基础知识
- 【ODX Studio編輯PDX】-0.2-如何對比Compare兩個PDX/ODX文件
- Redis入门完整教程:Redis使用场景
- 高通WLAN框架学习(30)-- 支持双STA的组件
猜你喜欢

A complete tutorial for getting started with redis: transactions and Lua

【剑指offer】1-5题

法国学者:最优传输理论下对抗攻击可解释性探讨

Excel shortcut keys - always add

One of the commonly used technical indicators, reading boll Bollinger line indicators

Redis入门完整教程:有序集合详解

Galera cluster of MariaDB - dual active and dual active installation settings

colResizable. JS auto adjust table width plug-in

Redis getting started complete tutorial: Key Management

Analysis of the self increasing and self decreasing of C language function parameters
随机推荐
Pict generate orthogonal test cases tutorial
[ODX studio edit PDX] - 0.2-how to compare two pdx/odx files of compare
Mysql database backup and recovery -- mysqldump command
The Chinese output of servlet server and client is garbled
Redis getting started complete tutorial: Geo
Qt个人学习总结
Redis introduction complete tutorial: client communication protocol
A complete tutorial for getting started with redis: redis shell
Wechat official account solves the cache problem of entering from the customized menu
CTF competition problem solution STM32 reverse introduction
微信公众号解决从自定义菜单进入的缓存问题
壁仞科技研究院前沿技术文章精选
Galera cluster of MariaDB - dual active and dual active installation settings
【taichi】用最少的修改将太极的pbf2d(基于位置的流体模拟)改为pbf3d
字体设计符号组合多功能微信小程序源码
P2181 diagonal and p1030 [noip2001 popularization group] arrange in order
可观测|时序数据降采样在Prometheus实践复盘
A complete tutorial for getting started with redis: Pipeline
ffmpeg快速剪辑
ScriptableObject