From 894b201b330981c17c3d84f29e494f6d2ebdbfaa Mon Sep 17 00:00:00 2001 From: codico Date: Wed, 20 Jul 2022 13:40:47 +0200 Subject: [PATCH] WIP 998/1000 passing --- src/raft/raft.go | 44 +++++++------------------------------------- src/raft/tester.sh | 4 ++-- src/raft/util.go | 9 +++++++-- 3 files changed, 16 insertions(+), 41 deletions(-) diff --git a/src/raft/raft.go b/src/raft/raft.go index 2875c63..d156723 100644 --- a/src/raft/raft.go +++ b/src/raft/raft.go @@ -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 } @@ -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) diff --git a/src/raft/tester.sh b/src/raft/tester.sh index 8bcbf0b..aa55745 100755 --- a/src/raft/tester.sh +++ b/src/raft/tester.sh @@ -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 diff --git a/src/raft/util.go b/src/raft/util.go index 5b9e695..05528c1 100644 --- a/src/raft/util.go +++ b/src/raft/util.go @@ -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 ---") } } @@ -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) {