Fix comments of lab 3
This commit is contained in:
@@ -551,7 +551,7 @@ func (cfg *config) wait(index int, n int, startTerm int) interface{} {
|
|||||||
// if retry==true, may submit the command multiple
|
// if retry==true, may submit the command multiple
|
||||||
// times, in case a leader fails just after Start().
|
// times, in case a leader fails just after Start().
|
||||||
// if retry==false, calls Start() only once, in order
|
// if retry==false, calls Start() only once, in order
|
||||||
// to simplify the early Lab 2B tests.
|
// to simplify the early Lab 3B tests.
|
||||||
func (cfg *config) one(cmd interface{}, expectedServers int, retry bool) int {
|
func (cfg *config) one(cmd interface{}, expectedServers int, retry bool) int {
|
||||||
t0 := time.Now()
|
t0 := time.Now()
|
||||||
starts := 0
|
starts := 0
|
||||||
@@ -605,7 +605,7 @@ func (cfg *config) one(cmd interface{}, expectedServers int, retry bool) int {
|
|||||||
|
|
||||||
// start a Test.
|
// start a Test.
|
||||||
// print the Test message.
|
// print the Test message.
|
||||||
// e.g. cfg.begin("Test (2B): RPC counts aren't too high")
|
// e.g. cfg.begin("Test (3B): RPC counts aren't too high")
|
||||||
func (cfg *config) begin(description string) {
|
func (cfg *config) begin(description string) {
|
||||||
fmt.Printf("%s ...\n", description)
|
fmt.Printf("%s ...\n", description)
|
||||||
cfg.t0 = time.Now()
|
cfg.t0 = time.Now()
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import (
|
|||||||
// CommandValid to true to indicate that the ApplyMsg contains a newly
|
// CommandValid to true to indicate that the ApplyMsg contains a newly
|
||||||
// committed log entry.
|
// committed log entry.
|
||||||
//
|
//
|
||||||
// in part 2D you'll want to send other kinds of messages (e.g.,
|
// in part 3D you'll want to send other kinds of messages (e.g.,
|
||||||
// snapshots) on the applyCh, but set CommandValid to false for these
|
// snapshots) on the applyCh, but set CommandValid to false for these
|
||||||
// other uses.
|
// other uses.
|
||||||
type ApplyMsg struct {
|
type ApplyMsg struct {
|
||||||
@@ -43,7 +43,7 @@ type ApplyMsg struct {
|
|||||||
Command interface{}
|
Command interface{}
|
||||||
CommandIndex int
|
CommandIndex int
|
||||||
|
|
||||||
// For 2D:
|
// For 3D:
|
||||||
SnapshotValid bool
|
SnapshotValid bool
|
||||||
Snapshot []byte
|
Snapshot []byte
|
||||||
SnapshotTerm int
|
SnapshotTerm int
|
||||||
@@ -58,7 +58,7 @@ type Raft struct {
|
|||||||
me int // this peer's index into peers[]
|
me int // this peer's index into peers[]
|
||||||
dead int32 // set by Kill()
|
dead int32 // set by Kill()
|
||||||
|
|
||||||
// Your data here (2A, 2B, 2C).
|
// Your data here (3A, 3B, 3C).
|
||||||
// Look at the paper's Figure 2 for a description of what
|
// Look at the paper's Figure 2 for a description of what
|
||||||
// state a Raft server must maintain.
|
// state a Raft server must maintain.
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ func (rf *Raft) GetState() (int, bool) {
|
|||||||
|
|
||||||
var term int
|
var term int
|
||||||
var isleader bool
|
var isleader bool
|
||||||
// Your code here (2A).
|
// Your code here (3A).
|
||||||
return term, isleader
|
return term, isleader
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ func (rf *Raft) GetState() (int, bool) {
|
|||||||
// after you've implemented snapshots, pass the current snapshot
|
// after you've implemented snapshots, pass the current snapshot
|
||||||
// (or nil if there's not yet a snapshot).
|
// (or nil if there's not yet a snapshot).
|
||||||
func (rf *Raft) persist() {
|
func (rf *Raft) persist() {
|
||||||
// Your code here (2C).
|
// Your code here (3C).
|
||||||
// Example:
|
// Example:
|
||||||
// w := new(bytes.Buffer)
|
// w := new(bytes.Buffer)
|
||||||
// e := labgob.NewEncoder(w)
|
// e := labgob.NewEncoder(w)
|
||||||
@@ -98,7 +98,7 @@ func (rf *Raft) readPersist(data []byte) {
|
|||||||
if data == nil || len(data) < 1 { // bootstrap without any state?
|
if data == nil || len(data) < 1 { // bootstrap without any state?
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Your code here (2C).
|
// Your code here (3C).
|
||||||
// Example:
|
// Example:
|
||||||
// r := bytes.NewBuffer(data)
|
// r := bytes.NewBuffer(data)
|
||||||
// d := labgob.NewDecoder(r)
|
// d := labgob.NewDecoder(r)
|
||||||
@@ -119,7 +119,7 @@ func (rf *Raft) readPersist(data []byte) {
|
|||||||
// service no longer needs the log through (and including)
|
// service no longer needs the log through (and including)
|
||||||
// that index. Raft should now trim its log as much as possible.
|
// that index. Raft should now trim its log as much as possible.
|
||||||
func (rf *Raft) Snapshot(index int, snapshot []byte) {
|
func (rf *Raft) Snapshot(index int, snapshot []byte) {
|
||||||
// Your code here (2D).
|
// Your code here (3D).
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,18 +127,18 @@ func (rf *Raft) Snapshot(index int, snapshot []byte) {
|
|||||||
// example RequestVote RPC arguments structure.
|
// example RequestVote RPC arguments structure.
|
||||||
// field names must start with capital letters!
|
// field names must start with capital letters!
|
||||||
type RequestVoteArgs struct {
|
type RequestVoteArgs struct {
|
||||||
// Your data here (2A, 2B).
|
// Your data here (3A, 3B).
|
||||||
}
|
}
|
||||||
|
|
||||||
// example RequestVote RPC reply structure.
|
// example RequestVote RPC reply structure.
|
||||||
// field names must start with capital letters!
|
// field names must start with capital letters!
|
||||||
type RequestVoteReply struct {
|
type RequestVoteReply struct {
|
||||||
// Your data here (2A).
|
// Your data here (3A).
|
||||||
}
|
}
|
||||||
|
|
||||||
// example RequestVote RPC handler.
|
// example RequestVote RPC handler.
|
||||||
func (rf *Raft) RequestVote(args *RequestVoteArgs, reply *RequestVoteReply) {
|
func (rf *Raft) RequestVote(args *RequestVoteArgs, reply *RequestVoteReply) {
|
||||||
// Your code here (2A, 2B).
|
// Your code here (3A, 3B).
|
||||||
}
|
}
|
||||||
|
|
||||||
// example code to send a RequestVote RPC to a server.
|
// example code to send a RequestVote RPC to a server.
|
||||||
@@ -191,7 +191,7 @@ func (rf *Raft) Start(command interface{}) (int, int, bool) {
|
|||||||
term := -1
|
term := -1
|
||||||
isLeader := true
|
isLeader := true
|
||||||
|
|
||||||
// Your code here (2B).
|
// Your code here (3B).
|
||||||
|
|
||||||
|
|
||||||
return index, term, isLeader
|
return index, term, isLeader
|
||||||
@@ -219,7 +219,7 @@ func (rf *Raft) killed() bool {
|
|||||||
func (rf *Raft) ticker() {
|
func (rf *Raft) ticker() {
|
||||||
for rf.killed() == false {
|
for rf.killed() == false {
|
||||||
|
|
||||||
// Your code here (2A)
|
// Your code here (3A)
|
||||||
// Check if a leader election should be started.
|
// Check if a leader election should be started.
|
||||||
|
|
||||||
|
|
||||||
@@ -246,7 +246,7 @@ func Make(peers []*labrpc.ClientEnd, me int,
|
|||||||
rf.persister = persister
|
rf.persister = persister
|
||||||
rf.me = me
|
rf.me = me
|
||||||
|
|
||||||
// Your initialization code here (2A, 2B, 2C).
|
// Your initialization code here (3A, 3B, 3C).
|
||||||
|
|
||||||
// initialize from state persisted before a crash
|
// initialize from state persisted before a crash
|
||||||
rf.readPersist(persister.ReadRaftState())
|
rf.readPersist(persister.ReadRaftState())
|
||||||
|
|||||||
Reference in New Issue
Block a user