知识卡片
日志接口与内存实现
Storage 提供 Raft 所需的日志和快照查询接口,MemoryStorage 存放硬状态、快照与条目,并用互斥锁保护。内存实现可供 Raft 正常读写日志视图,但进程退出后要由外层 WAL 与快照恢复它;使用 Storage 这个接口名本身不能提供掉电持久性。
结构图:
classDiagram
class Storage {
<<interface>>
+InitialState() (pb.HardState,pb.ConfState,error)
+Entries(lo uint64,hi uint64,maxSize uint64) ([]pb.Entry,error)
+Term(i uint64) (uint64,error)
+FirstIndex() (uint64,error)
+LastIndex() (uint64,error)
+Snapshot() (pb.Snapshot,error)
}
class MemoryStorage {
+ApplySnapshot(snap pb.Snapshot) error
+Append(entries []pb.Entry) error
+Compact(compactIndex uint64) error
}
MemoryStorage ..|> Storage : Go隐式实现
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- etcd-raft模块详解 3.1.2 Storage接口及其实现 · 查看原书依据
MemoryStorage 是 etcd-raft 模块为 Storage 接口提供的一个实现,从名字也能看出,MemoryStorage在内存中维护上述状态信息(hardState字段)、快照数据(snapshot字段)及
参考来源
- 位置:《etcd技术内幕》第03章 etcd-raft模块详解 · 3.1.2 Storage接口及其实现(来源项目 book-source,extracted/etcd技术内幕/_epub-src/OEBPS/text00006.html)
- 结论依据:原文说明 MemoryStorage 的内存字段和锁。本章 raftexample 的 replayWAL 再建 MemoryStorage 支持该恢复边界。
- 原始内容:MemoryStorage 是 etcd-raft 模块为 Storage 接口提供的一个实现,从名字也能看出,MemoryStorage在内存中维护上述状态信息(hardState字段)、快照数据(snapshot字段)及