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
bb896bab
Commit
bb896bab
authored
3 years ago
by
djq2
Browse files
Options
Downloads
Patches
Plain Diff
save
parent
36edf06d
Branches
crumb
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mp2/src/raft/raft.go
+11
-2
11 additions, 2 deletions
mp2/src/raft/raft.go
with
11 additions
and
2 deletions
mp2/src/raft/raft.go
+
11
−
2
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
...
...
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