etcd raft介绍
etcd raft是目前使用最广泛的raft库,如果想深入了解raft请直接阅读论文 “In Search of an Understandable Consensus Algorithm”(https://raft.github.io/raft.pdf), etcd raft在etcd, Kubernetes, Docker Swarm, Cloud Foundry Diego, CockroachDB, TiDB, Project Calico, Flannel等分布式系统中都有应用,在生成环境得到了验证。 传统raft库的实现都是单体设计(集成了存储层、消息序列化、网络层等), etcd raft继承了简约的设计理念,只实现了最核心的raft算法, 这样更加的灵活。etcd将网络、日志存储、快照等功能分开,通过独立的模块实现,用户可以在需要时调用。etcd自身实现了自己的一套raft配套库:etcd-wal(用于存储日志),snap(用于存储快照),MemoryStorage(用于存储当前日志、快照、状态等信息以供raft核心程序使用)。
etcd wal介绍
WAL是write ahead log的缩写,etcd使用wal模块来完成raft日志的持久化存储,etcd对wal的所有实现都放在wal目录中。
wal数据结构
type WAL struct {
lg *zap.Loggerdir string // the living directory of the underlay files// dirFile is a fd for the wal directory for syncing on RenamedirFile *os.Filemetadata []byte // metadata recorded at the head of each WALstate raftpb.HardState // hardstate recorded at the head of WALstart walpb.Snapshot // snapshot to start reading

本文深入探讨了etcd的raft实现,包括wal数据结构、日志读写、日志切分、快照存储等内容。wal模块负责raft日志的持久化,采用64M文件切分策略;快照通过snap模块管理,根据特定条件触发创建。etcd raft的设计允许用户灵活选择存储和网络实现。
最低0.47元/天 解锁文章
3075

被折叠的 条评论
为什么被折叠?



