# raft-core **Repository Path**: tanjiancheng/raft-core ## Basic Information - **Project Name**: raft-core - **Description**: 分布式算法-共识算法-Raft学习-代码仓库 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2026-05-05 - **Last Updated**: 2026-05-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Raft Learn - 分布式共识算法学习项目 通过「手写协议 + 使用成熟库」两种方式学习 Raft 共识算法,分别用 Java 和 Go 实现。 ## 学习路线 ``` Phase 1: 基础概念 ───────────────────────────────────────── docs/01-raft-concepts.md Raft 核心概念速查 Phase 2: Java 手写 Raft ─────────────────────────────────── java/raft-core/ 节点状态机 → 选举 → 日志复制 → 持久化 → 快照 Phase 3: Java SOFAJRaft KV ──────────────────────────────── java/raft-kvstore/ 基于 SOFAJRaft 的分布式 KV 存储 Phase 4: Go 手写 Raft ───────────────────────────────────── go/raft-core/ goroutine + channel 实现核心协议 Phase 5: Go hashicorp/raft KV ───────────────────────────── go/raft-kvstore/ 基于 hashicorp/raft 的分布式 KV 存储 ``` ## 项目结构 ``` raft-learn/ ├── docs/ # 学习文档 ├── java/ │ ├── raft-core/ # 手写 Raft 协议 (Java) │ └── raft-kvstore/ # SOFAJRaft KV 存储 ├── go/ │ ├── raft-core/ # 手写 Raft 协议 (Go) │ └── raft-kvstore/ # hashicorp/raft KV 存储 └── scripts/ # 集群启动 & 测试脚本 ``` ## 环境要求 - Java 17+ (推荐 JDK 21) - Go 1.21+ - Maven 3.8+ - protobuf + protoc (用于 gRPC) ## 快速开始 ```bash # Java 手写模块 cd java/raft-core mvn clean test # Go 手写模块 cd go/raft-core go test ./... # 启动 KV 集群 (3 节点) ./scripts/start-cluster-java.sh ./scripts/test-kv.sh ``` ## 参考资料 - [Raft 论文 (In Search of an Understandable Consensus Algorithm)](https://raft.github.io/raft.pdf) - [MIT 6.5840 分布式系统课程](https://pdos.csail.mit.edu/6.824/) - [SOFAJRaft](https://github.com/sofastack/sofa-jraft) - [hashicorp/raft](https://github.com/hashicorp/raft) - [Raft 可视化](https://thesecretlivesofdata.com/raft/)