Documentation
¶
Index ¶
- Constants
- func DPrintf(format string, a ...interface{}) (n int, err error)
- type AppendEntries
- type ApplyMsg
- type LogEntry
- type LogSnapshot
- type Persister
- func (ps *Persister) Copy() *Persister
- func (ps *Persister) RaftStateSize() int
- func (ps *Persister) ReadRaftState() []byte
- func (ps *Persister) ReadSnapshot() []byte
- func (ps *Persister) SaveRaftState(state []byte)
- func (ps *Persister) SaveStateAndSnapshot(state []byte, snapshot []byte)
- func (ps *Persister) SnapshotSize() int
- type Raft
- func (rf *Raft) ElectionLoop()
- func (rf *Raft) GetState() (int, bool)
- func (rf *Raft) Kill()
- func (rf *Raft) ReplicateLogLoop(peer int)
- func (rf *Raft) RequestAppendEntries(req *AppendEntries, resp *RespEntries)
- func (rf *Raft) RequestVote(req *RequestVoteArgs, reply *RequestVoteReply)
- func (rf *Raft) SaveSnapshot(index int, snapshot []byte)
- func (rf *Raft) Start(command interface{}) (index int, term int, isLeader bool)
- func (rf *Raft) Vote()
- type RequestVoteArgs
- type RequestVoteReply
- type RespEntries
Constants ¶
View Source
const CandidateDuration = HeartbeatDuration * 2
竞选周期
View Source
const Debug = 0
Debugging
View Source
const Fallower, Leader, Candidate int = 1, 2, 3
import "os" 节点状态
View Source
const HeartbeatDuration = time.Duration(time.Millisecond * 600)
心跳周期
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AppendEntries ¶
type AppendEntries struct { Me int Term int PrevLogTerm int PrevLogIndex int Entries []LogEntry LeaderCommit int Snapshot LogSnapshot //快照 }
日志复制请求
type Persister ¶
type Persister struct {
// contains filtered or unexported fields
}
func MakePersister ¶
func MakePersister() *Persister
func (*Persister) RaftStateSize ¶
func (*Persister) ReadRaftState ¶
func (*Persister) ReadSnapshot ¶
func (*Persister) SaveRaftState ¶
func (*Persister) SaveStateAndSnapshot ¶
Save both Raft state and K/V snapshot as a single atomic action, to help avoid them getting out of sync.
func (*Persister) SnapshotSize ¶
type Raft ¶
type Raft struct { EnableDebugLog bool //打印调试日志开关 LastGetLock string // contains filtered or unexported fields }
func (*Raft) RequestAppendEntries ¶
func (rf *Raft) RequestAppendEntries(req *AppendEntries, resp *RespEntries)
func (*Raft) RequestVote ¶
func (rf *Raft) RequestVote(req *RequestVoteArgs, reply *RequestVoteReply)
收到投票请求
type RequestVoteArgs ¶
投票请求
Click to show internal directories.
Click to hide internal directories.