etcd-0x05-模块化组件式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// golang的chan我觉得本质是队列 实际用途既可以当作普通队列的内存缓冲区 又可以退化成常量级别的内存占用的信号量
// 下面两个是典型的队列用途 用于解耦模块组件之间
// 客户端put->kv store构建kv键值对->发送到propose channel->raft node订阅propose channel负责同步和半数确认->发送到commit channel->kv store订阅commit channel后持久化
proposeC := make(chan string)
defer close(proposeC)
confChangeC := make(chan raftpb.ConfChange)
defer close(confChangeC)

// raft provides a commit stream for the proposals from the http api
var kvs *kvstore
// 内存中map序列化json
getSnapshot := func() ([]byte, error) { return kvs.getSnapshot() }
// 组件式思想 各司其职 raftNode负责raft算法实现 kvstore负责键值对数据库 httpKVAPI负责对客户端
commitC, errorC, snapshotterReady := newRaftNode(*id, strings.Split(*cluster, ","), *join, getSnapshot, proposeC, confChangeC)

kvs = newKVStore(<-snapshotterReady, proposeC, commitC, errorC)

// the key-value http handler will propose updates to raft
serveHTTPKVAPI(kvs, *kvport, confChangeC, errorC)

按照功能划分有3个核心模块


etcd-0x05-模块化组件式
https://bannirui.github.io/2025/06/06/etcd/etcd-0x05-模块化组件式/
作者
dingrui
发布于
2025年6月6日
许可协议