Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
djq2
ECE 428 - Distributed Systems
Commits
bb896bab
Commit
bb896bab
authored
Apr 04, 2022
by
djq2
Browse files
save
parent
36edf06d
Changes
1
Hide whitespace changes
Inline
Side-by-side
mp2/src/raft/raft.go
View file @
bb896bab
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment