Commit bb896bab authored by djq2's avatar djq2
Browse files

save

parent 36edf06d
......@@ -22,8 +22,8 @@ import "sync/atomic"
import "../labrpc"
import "math/rand"
import "time"
// import "fmt"
// import "strconv"
import "fmt"
import "strconv"
//
// as each Raft peer becomes aware that successive log entries are
// committed, the peer should send an ApplyMsg to the service (or
......@@ -205,6 +205,7 @@ func (rf *Raft) AppendEntries(args *AppendEntriesArgs, reply *AppendEntriesReply
if len(args.Entries) == 0 {
reply.Success = true
reply.Term = rf.currentTerm
return
} else if len(rf.log) == 0 {
for i := 0; i < len(args.Entries); i ++ {
......@@ -212,6 +213,9 @@ func (rf *Raft) AppendEntries(args *AppendEntriesArgs, reply *AppendEntriesReply
}
reply.Success = true
reply.Term = rf.currentTerm
fmt.Print("Follower " + strconv.Itoa(rf.me) + " log: ")
fmt.Println(rf.log)
// rf.lastApplied = len(rf.log) - 1
return
} else if args.PrevLogTerm == rf.log[args.PrevLogIndex].Term && len(rf.log) > args.PrevLogIndex {
......@@ -229,6 +233,8 @@ func (rf *Raft) AppendEntries(args *AppendEntriesArgs, reply *AppendEntriesReply
rf.applyCh <- msgOut
rf.mu.Unlock()
}
fmt.Print("Follower " + strconv.Itoa(rf.me) + " log: ")
fmt.Println(rf.log)
reply.Success = true
reply.Term = rf.currentTerm
// rf.lastApplied = len(rf.log) - 1
......@@ -543,6 +549,9 @@ func (rf *Raft) Commit(command interface{}) {
initialTerm := rf.currentTerm
rf.mu.Unlock()
fmt.Print("New Leader Log: ")
fmt.Println(rf.log)
numServers := len(rf.peers)
count := 1
majority := numServers/2
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment