Skip to content

Commit

Permalink
WIP 998/1000 passing
Browse files Browse the repository at this point in the history
  • Loading branch information
codicocodes committed Jul 20, 2022
1 parent 741f243 commit 894b201
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 41 deletions.
44 changes: 7 additions & 37 deletions src/raft/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,42 +367,6 @@ func (rf *Raft) decrementNextIndex(server int, args *RequestAppendEntriesArgs, r
if decrementedIdx < 0 {
decrementedIdx = 0
}

// check if the decrementIdx did not decrease since last time
if rf.nextIndex[server] <= decrementedIdx {
// if this situation happens, this node CANNOT accept messages from this leader
// all nodes should be able to replicate my messages from the leader
// we should consider stepping down as a leader node here
DPrintf("nextIndex=%d decrementedNextIdx=%d\n", rf.nextIndex[server] , decrementedIdx)
if rf.commitCommandTerm != rf.currentTerm {
// The leader never committed any commands
// It should be OK if the leader steps down here
DPrintf(
"[decrementNextIndex.%d.%d] The server=%d REFUSES to replicate. currentTerm=%d args.Term=%d nextIndex=%d decrementedNextIdx=%d\n",
rf.currentTerm,
rf.me,
server,
rf.currentTerm,
args.Term,
rf.nextIndex[server],
decrementedIdx,
)
fmt.Printf(
"[decrementNextIndex.%d.%d] The server=%d REFUSES to replicate. currentTerm=%d args.Term=%d nextIndex=%d decrementedNextIdx=%d\n",
rf.currentTerm,
rf.me,
server,
rf.currentTerm,
args.Term,
rf.nextIndex[server],
decrementedIdx,
)
rf.role = Follower
return
} else {
DPrintf("The server REFUSES to replicate, but I have committed... monkaHmmm nextIndex=%d decrementedNextIdx=%d\n", rf.nextIndex[server] , decrementedIdx)
}
}
rf.nextIndex[server] = decrementedIdx
}

Expand Down Expand Up @@ -609,7 +573,13 @@ func (rf *Raft) AppendEntries(
if args.PrevLogIndex >= 0 {
lastLogIndex := len(rf.log) - 1
if lastLogIndex < args.PrevLogIndex {
DPrintf("me=%d Not accepting log due to too high prev log index. loglen %d, prev index %d, leader commit ID %d", rf.me, len(rf.log), args.PrevLogIndex, args.LeaderCommitID)
DPrintf(
"me=%d Not accepting log due to too high prev log index. loglen =%d, args.PrevLogIndex=%d, leader commit ID %d",
rf.me,
len(rf.log),
args.PrevLogIndex,
args.LeaderCommitID,
)
DPrintf("me=%d My commit ID: %d", rf.me, rf.commitCommandID)
rf.calculateConflictInfo(args, reply)
rf.denyAppendEntry(args, reply)
Expand Down
4 changes: 2 additions & 2 deletions src/raft/tester.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
for i in {1..300}
for i in {1..1000}
do
go test -run Figure8Unreliable2C
# go test -run Figure82C
# go test -run Backup2B
# go test -run UnreliableChurn2C
echo Completed test $i/300
# echo Completed test $i/300
done
9 changes: 7 additions & 2 deletions src/raft/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func EnableLogger() {
fileName := time.Now().Format("2006-01-02") + "." + time.Now().Format("15:04") + ".logger"
filePath := currPath + "/logs/" + fileName
file, _ = os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
fmt.Printf("Opened log file: %s\n", fileName)
DPrintf("--- START OF TEST ---")
}
}
Expand All @@ -34,7 +33,13 @@ func Write(str string) {

func DPrintClose(){
fileName := file.Name()
fmt.Printf("Error in log file: %s\n", fileName)
msg := fmt.Sprintf("Error in log file: %s\n", fileName)
fmt.Println(msg)

currPath, _ := os.Getwd()
filePath := currPath + "/logs/" + "erroring.logs"
errFile, _ := os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
errFile.WriteString(msg)
}

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

0 comments on commit 894b201

Please sign in to comment.