raft

package
v0.0.0-...-ab99748 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Leader = iota
	Candidate
	Follower

	HBINTERVAL = 50 * time.Millisecond // 50ms

)
View Source
const Debug = 0

Debugging

Variables

This section is empty.

Functions

func DPrintf

func DPrintf(format string, a ...interface{}) (n int, err error)

Types

type AppendEntriesArgs

type AppendEntriesArgs struct {
	// Your data here.
	Term           int
	Name           int
	Prev_log_term  int
	Prev_log_index int
	Entries        []LogEntry
	Leader_commit  int
}

type AppendEntriesReply

type AppendEntriesReply struct {
	// Your data here.
	Name           int
	Term           int
	Success        bool
	Last_log_index int
	Last_log_term  int
}

type ApplyMsg

type ApplyMsg struct {
	CommandValid bool
	Command      interface{}
	CommandIndex int
	UseSnapshot  bool
	Snapshot     []byte
}

type InstallSnapshotArgs

type InstallSnapshotArgs struct {
	Name                int
	Term                int
	Last_included_index int
	Last_included_term  int
	Data                []byte
}

type InstallSnapshotReply

type InstallSnapshotReply struct {
	Name int
	Term int
}

type LogEntry

type LogEntry struct {
	Index   int
	Term    int
	Command interface{}
}

type Persister

type Persister struct {
	// contains filtered or unexported fields
}

func MakePersister

func MakePersister() *Persister

func (*Persister) Copy

func (ps *Persister) Copy() *Persister

func (*Persister) RaftStateSize

func (ps *Persister) RaftStateSize() int

func (*Persister) ReadRaftState

func (ps *Persister) ReadRaftState() []byte

func (*Persister) ReadSnapshot

func (ps *Persister) ReadSnapshot() []byte

func (*Persister) SaveRaftState

func (ps *Persister) SaveRaftState(state []byte)

func (*Persister) SaveStateAndSnapshot

func (ps *Persister) SaveStateAndSnapshot(state []byte, snapshot []byte)

Save both Raft state and K/V snapshot as a single atomic action, to help avoid them getting out of sync.

func (*Persister) SnapshotSize

func (ps *Persister) SnapshotSize() int

type Raft

type Raft struct {
	// contains filtered or unexported fields
}

func Make

func Make(peers []*labrpc.ClientEnd, me int,
	persister *Persister, applyCh chan ApplyMsg) *Raft

func (*Raft) AppendEntries

func (rf *Raft) AppendEntries(args AppendEntriesArgs, reply *AppendEntriesReply)

func (*Raft) GetPerisistSize

func (rf *Raft) GetPerisistSize() int

func (*Raft) GetState

func (rf *Raft) GetState() (int, bool)

func (*Raft) GetState2

func (rf *Raft) GetState2() int

func (*Raft) InstallSnapshot

func (rf *Raft) InstallSnapshot(args InstallSnapshotArgs, reply *InstallSnapshotReply)

func (*Raft) Kill

func (rf *Raft) Kill()

func (*Raft) RequestVote

func (rf *Raft) RequestVote(args RequestVoteArgs, reply *RequestVoteReply)

func (*Raft) Start

func (rf *Raft) Start(command interface{}) (int, int, bool)

func (*Raft) StartSnapshot

func (rf *Raft) StartSnapshot(snapshot []byte, index int)

type RequestVoteArgs

type RequestVoteArgs struct {
	// Your data here (2A, 2B).
	Name           int
	Term           int
	Last_log_index int
	Last_log_term  int
}

type RequestVoteReply

type RequestVoteReply struct {
	// Your data here (2A).
	Name         int
	Term         int
	Vote_granted bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL