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
0b81ac78
Commit
0b81ac78
authored
Apr 04, 2022
by
djq2
Browse files
whatever
parent
a7058ab1
Changes
1
Hide whitespace changes
Inline
Side-by-side
mp2/src/raft/raft.go
View file @
0b81ac78
...
...
@@ -169,7 +169,9 @@ func (rf *Raft) RequestVote(args *RequestVoteArgs, reply *RequestVoteReply) {
func
(
rf
*
Raft
)
AppendEntries
(
args
*
AppendEntriesArgs
,
reply
*
AppendEntriesReply
)
{
// Refresh timeout
// print("append entries")
rf
.
mu
.
Lock
()
// print("grabed lock")
...
...
@@ -236,7 +238,7 @@ func (rf *Raft) AppendEntries(args *AppendEntriesArgs, reply *AppendEntriesReply
//add else statment later to handle optimization
reply
.
Success
=
false
}
reply
.
Term
=
rf
.
currentTerm
rf
.
mu
.
Unlock
()
return
...
...
@@ -257,12 +259,13 @@ func (rf *Raft) printLog() {
func
(
rf
*
Raft
)
handleCommitChannel
(){
for
range
rf
.
commitReadyChan
{
<-
rf
.
commitReadyChan
rf
.
mu
.
Lock
()
lastApplied
:=
rf
.
lastApplied
var
entries
[]
Entry
if
rf
.
commitIndex
>
rf
.
lastApplied
{
entries
=
rf
.
log
[
rf
.
lastApplied
+
1
:
rf
.
commitIndex
+
1
]
rf
.
lastApplied
=
rf
.
commitIndex
entries
=
rf
.
log
[
rf
.
lastApplied
+
1
:
rf
.
commitIndex
+
1
]
rf
.
lastApplied
=
rf
.
commitIndex
}
rf
.
mu
.
Unlock
()
...
...
@@ -359,7 +362,6 @@ func (rf *Raft) Follower() {
return
}
rf
.
mu
.
Unlock
()
}
}
...
...
@@ -626,7 +628,7 @@ func (rf *Raft) sendHeartbeat(){
count
:=
1
for
j
:=
0
;
j
<
len
(
rf
.
peers
);
j
++
{
if
j
!=
rf
.
me
{
if
rf
.
matchIndex
[
j
]
>=
i
{
if
rf
.
matchIndex
[
j
]
>=
i
{
count
++
}
}
...
...
@@ -700,7 +702,7 @@ func (rf *Raft) Start(command interface{}) (int, int, bool) {
go
rf
.
sendHeartbeat
()
}
index
=
len
(
rf
.
log
)
// Your code here (2B).
rf
.
mu
.
Unlock
()
return
index
,
term
,
isLeader
...
...
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