raft

package
v0.0.0-...-760e81f Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2020 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

raft-impl: An implementation of the Raft consensus algorithm Copyright (C) 2020 Yicheng Huang. All rights reserved.

A course assignment for Distributed System, Fall 2020, CS@NJU.

raft.go The core Raft implementation

Index

Constants

View Source
const (
	/*RaftElectionTimeoutMin is the minimum timeout of leader election*/
	RaftElectionTimeoutMin = 400 * time.Millisecond
	/*RaftHeartBeatLoop is the time period of sending heart beat*/
	RaftHeartBeatLoop = 100 * time.Millisecond
)
View Source
const DEBUG = 0

DEBUG for debug/run mode switch.

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 {
	Term         int
	LeaderID     int
	PrevLogIndex int
	PrevLogTerm  int
	Entries      []LogEntry
	LeaderCommit int
}

AppendEntriesArgs is the structure of AppendEntries RPC arguments

type AppendEntriesReply

type AppendEntriesReply struct {
	Term         int
	Success      bool
	ConflictTerm int
	FirstIDTerm  int
}

AppendEntriesReply is the structure of AppendEntries RPC reply

type ApplyMsg

type ApplyMsg struct {
	Index       int
	Command     interface{}
	UseSnapshot bool   // ignore for lab2; only used in lab3
	Snapshot    []byte // ignore for lab2; only used in lab3
}

ApplyMsg is the structure of apply message to state machine

type LogEntry

type LogEntry struct {
	Term  int
	Value interface{}
}

LogEntry is the structure of each log entry, composed by its term and value

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(data []byte)

func (*Persister) SaveSnapshot

func (ps *Persister) SaveSnapshot(snapshot []byte)

type RLogger

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

RLogger is the structure of logger used by Raft, for convenience of debugging

func (*RLogger) Printf

func (rl *RLogger) Printf(format string, v ...interface{})

Printf for printing with format string (using log.Logger)

func (*RLogger) Println

func (rl *RLogger) Println(v ...interface{})

Println for printing with \n ended (using log.Logger)

type RMutex

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

RMutex is the structure of mutex lock used by Raft, for convenience of debugging

func (*RMutex) Lock

func (mu *RMutex) Lock()

Lock for locking (using sync.Mutex)

func (*RMutex) Unlock

func (mu *RMutex) Unlock()

Unlock for unlocking (using sync.Mutex)

type Raft

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

Raft is the core structure of each server making consensus with RAFT

func Make

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

Make is used by clients or tester to create a Raft instance

func (*Raft) AppendEntries

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

AppendEntries is the handler of AppendEntries RPC

func (*Raft) GetState

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

GetState returns currentTerm and whether this server believes it is the leader

func (*Raft) Kill

func (rf *Raft) Kill()

Kill is used by tester to shutdown a Raft instance. Graceful shutdown is implemented.

func (*Raft) RequestVote

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

RequestVote is the handler of RequestVote RPC

func (*Raft) Start

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

Start is used by clients to start agreement on the next command to be appended to Raft's logs

type RequestVoteArgs

type RequestVoteArgs struct {
	Term         int
	CandidateID  int
	LastLogIndex int
	LastLogTerm  int
}

RequestVoteArgs is the structure of RequestVote RPC arguments

type RequestVoteReply

type RequestVoteReply struct {
	Term        int
	VoteGranted bool
}

RequestVoteReply is the structure of RequestVote RPC reply

Jump to

Keyboard shortcuts

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