Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cs733
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sushant Mahajan
cs733
Commits
b045968a
Commit
b045968a
authored
Mar 23, 2015
by
Sushant Mahajan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
partial implementation of ClientAppend of leader
parent
ab7ec028
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
2 deletions
+21
-2
assignment3/src/raft/raft.go
assignment3/src/raft/raft.go
+21
-2
No files found.
assignment3/src/raft/raft.go
View file @
b045968a
...
...
@@ -58,7 +58,7 @@ type ClusterConfig struct {
}
type
ClientAppend
struct
{
logEntry
LogEntry
logEntry
*
LogEntry
}
type
VoteRequest
struct
{
...
...
@@ -103,6 +103,10 @@ type Raft struct {
voters
int
monitorVotesCh
chan
bool
et
*
time
.
Timer
isLeader
bool
lastApplied
int
nextIndex
[]
int
matchIndex
[]
int
}
// Log entry interface
...
...
@@ -184,6 +188,9 @@ func NewRaft(config *ClusterConfig, thisServerId int, commitCh chan LogEntry, ev
}
rft
.
monitorVotesCh
=
monitorVotesCh
getSingleDataFromFile
(
VOTED_FOR
,
thisServerId
,
rft
.
Info
)
//initialize the votedFor file.
rft
.
isLeader
=
false
rft
.
nextIndex
=
make
([]
int
,
len
(
config
.
Servers
))
rft
.
matchIndex
=
make
([]
int
,
len
(
config
.
Servers
))
return
rft
,
nil
}
...
...
@@ -293,9 +300,10 @@ func (rft *Raft) grantVote(reply bool, currentTerm int) {
if
reply
{
rft
.
voters
++
rft
.
Info
.
Println
(
rft
.
id
,
"got vote"
)
if
rft
.
voters
>
len
(
rafts
)
/
2
{
if
!
rft
.
isLeader
&&
rft
.
voters
>
len
(
rafts
)
/
2
{
rft
.
LogC
(
"got majority"
)
rft
.
monitorVotesCh
<-
true
rft
.
isLeader
=
true
}
}
}
...
...
@@ -474,6 +482,11 @@ func (rft *Raft) leader() int {
heartbeatReq
:=
new
(
AppendRPC
)
heartbeatReq
.
entries
=
[]
*
LogEntryData
{}
heartbeatReq
.
leaderId
=
rft
.
id
//reintialize nextIndex and matchIndex
for
i
:=
0
;
i
<
len
(
rft
.
nextIndex
);
i
++
{
rft
.
nextIndex
[
i
]
=
len
(
rft
.
LogArray
)
rft
.
matchIndex
[
i
]
=
0
}
for
{
select
{
...
...
@@ -489,6 +502,12 @@ func (rft *Raft) leader() int {
case
event
:=
<-
rft
.
eventCh
:
switch
event
.
(
type
)
{
case
*
ClientAppend
:
//write data to log
rft
.
LogL
(
"got client data"
)
entry
:=
event
.
(
*
ClientAppend
)
.
logEntry
rft
.
LogArray
=
append
(
rft
.
LogArray
,
entry
)
//todo:apply to state machine
//todo:respond to client
case
*
AppendRPC
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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