Documentation ¶
Overview ¶
Raft一致性实现 选举
Raft一致性实现 日志复制
Raft一致性实现 RPC实现
Raft一致性实现 测试用例
Raft一致性实现 Raft服务器(节点管理)
Index ¶
- Constants
- Variables
- type BenchTest
- func (h *BenchTest) CheckCommitted(cmd string) (nc int, index int32)
- func (h *BenchTest) CheckCommittedN(cmd string, n int)
- func (h *BenchTest) CheckNoLeader()
- func (h *BenchTest) CheckNotCommitted(cmd string)
- func (h *BenchTest) CheckSingleLeader() (string, int32)
- func (h *BenchTest) CrashPeer(id string)
- func (h *BenchTest) DisconnectPeer(id string)
- func (h *BenchTest) ReconnectPeer(id string)
- func (h *BenchTest) RestartPeer(id string)
- func (h *BenchTest) Shutdown()
- func (h *BenchTest) Submit(cmd string) (string, bool)
- func (h *BenchTest) SubmitToServer(serverId string, cmd string) bool
- func (h *BenchTest) SubmitToServerNotForward(serverId string, cmd string) bool
- type CommitEntry
- type Config
- type FSM
- type LogEntry
- type MapStorage
- type Server
- type Storage
Constants ¶
View Source
const MethodAppendEntries = "/raft.message.Message/AppendEntries"
View Source
const MethodForwardMessage = "/raft.message.Message/ForwardMessage"
View Source
const MethodRequestVote = "/raft.message.Message/RequestVote"
Variables ¶
View Source
var ErrorContextCanceled = fmt.Errorf("context canceled")
View Source
var ErrorInvalidClient = fmt.Errorf("client was closed")
View Source
var ErrorServerAlreadyShutdown = fmt.Errorf("server already shutdown")
Functions ¶
This section is empty.
Types ¶
type BenchTest ¶
type BenchTest struct {
// contains filtered or unexported fields
}
BenchTest 测试用例
func (*BenchTest) CheckCommitted ¶
CheckCommitted 检查某条日志是否全部被提交
func (*BenchTest) CheckCommittedN ¶
CheckCommittedN 检查是否存在N个节点的提交记录
func (*BenchTest) CheckNotCommitted ¶
CheckNotCommitted 检查某条日志是否未提交
func (*BenchTest) CheckSingleLeader ¶
CheckSingleLeader 检查是否只有一个Leader
func (*BenchTest) DisconnectPeer ¶
DisconnectPeer 断开本地服务并且断开其他节点的该服务
func (*BenchTest) SubmitToServer ¶
SubmitToServer 测试向服务器提交日志
type CommitEntry ¶
type CommitEntry struct { // Command 客户端提交的命令 Command string // Index 提交的索引 Index int32 // Term 提交的生命周期 Term int32 }
CommitEntry 数据提交的通道,每次数据有变动时CommitChannel会触发结果
type Config ¶
type Config struct { // 选举最短超时时间 ElectionTimeoutMinMs int // 选举最长超时时间 ElectionTimeoutMaxMs int // Leader心跳间隔 HeartbeatMs time.Duration // rpc请求超时时间 RPCMsgTimeoutMs time.Duration // 是否打印日志 ShowLog bool // 是否自动转发消息(如果在Follower上提交日志,会自动转发到Leader) AutoRedirectMessage bool }
Config 配置
type MapStorage ¶
type MapStorage struct {
// contains filtered or unexported fields
}
func NewMapStorage ¶
func NewMapStorage() *MapStorage
func (*MapStorage) Len ¶
func (ms *MapStorage) Len() int
func (*MapStorage) Set ¶
func (ms *MapStorage) Set(key string, value []byte)
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(address string, commitChan chan<- CommitEntry, config *Config, nodeIDs ...string) *Server
NewServer 新建一个raft服务 address为TCP监听的地址,一般给个端口就可以如:8888 commitChan如果有数据新增,则会通知到这里,业务可以用于监听 config配置信息,需要确保electionMin比Max要小,并且heartbeat也要比electionMin小这三个参数才可生效 可根据实际情况调整时间,默认min(150ms), max(300ms), heartbeat(20ms) nodeIDs除自己以外的节点列表(新的节点把老的节点的地址都填上即可相互连接)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.