Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ECE 428 - Distributed Systems
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
djq2
ECE 428 - Distributed Systems
Commits
0b81ac78
Commit
0b81ac78
authored
3 years ago
by
djq2
Browse files
Options
Downloads
Patches
Plain Diff
whatever
parent
a7058ab1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mp2/src/raft/raft.go
+8
-6
8 additions, 6 deletions
mp2/src/raft/raft.go
with
8 additions
and
6 deletions
mp2/src/raft/raft.go
+
8
−
6
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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment