6

K8s | 写入etcd的过程

 2 years ago
source link: https://jiac3366.github.io/2021/11/17/Kubernetes/etcd%E5%86%99%E5%85%A5%E8%BF%87%E7%A8%8B/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

+c编程手记

Guangzhou, China
  • 写入etcd的过程

    • 1、预检查

      • 包大小检查

    • 2、 经过kvSever传到一致性模块(写请求发给了follower会被一致性模块转发给leader)

      基于Raft paper

      • 把请求放入raftLog(Memory暂存)

      • 然后同时做2个操作

        • MsgProp发给其他follower

        • 写一个WAL log(二进制的, 将y=9序列化),后台有异步操作落盘

    • 3、其他follower接收到请求也做写自己raftLog 和WAL,最后给leader返回一个MsgAppResp

    • 4、kvSever统计MatchIndex 是否超过半数follower确认,
      目前还是日志,没有写状态机

    • 5、当超半数确认,raftLog中的状态从unstable –>committed,写MVCC模块(状态机)

      • 写treeIndex key-value形式

        • key是对象的key, value是版本信息,main revision(eg 最后一次版本号是4)和sub revision(第0次操作), 所以可以get 某个key对应的revisionimg

        • Metadata的resourceVersion读的就是modified信息

        • generation历史变动:3版本创建 历史版本是3和4(有2版本)

      • 写BoltDB key-value形式

        • key是revision

        • value是这条记录的整个信息

      • 为什么要写WAL呢,直接写MVCC不行吗?

        • 放个地方临时持久化,因为需等待其他follower半数以上同意,又要防止内存断电

        • 当等到半数以上同意了,这时如果etcd挂了,大家已经确认的数据就可以直接从WAL中恢复

        • 所以WAL是写入状态机之前等待协商的过程保证数据安全用的

    • 6、落盘后,raftLog中的状态从committed–>applied


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK