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
9bbecccb
Commit
9bbecccb
authored
Mar 21, 2015
by
Sushant Mahajan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved server.go in the raft package
parent
faa29612
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
19 deletions
+9
-19
assignment3/src/raft/raft.go
assignment3/src/raft/raft.go
+8
-8
assignment3/src/raft/server.go
assignment3/src/raft/server.go
+1
-11
No files found.
assignment3/src/raft/raft.go
View file @
9bbecccb
...
...
@@ -52,7 +52,7 @@ type ClusterConfig struct {
}
type
ClientAppend
struct
{
logEntry
LogEntry
}
type
VoteRequest
struct
{
...
...
@@ -316,17 +316,17 @@ func (raft *Raft) loop() {
func
(
raft
*
Raft
)
follower
()
{
//start candidate timeout
canTimeout
=
time
.
After
((
randGen
.
Intn
(
MAX_TIMEOUT
)
+
MIN_TIMEOUT
)
%
MAX_TIMEOUT
)
isCandidateChan
=
time
.
After
((
rand
.
Intn
(
MAX_TIMEOUT
)
+
MIN_TIMEOUT
)
%
MAX_TIMEOUT
)
for
{
//wrap in select
event
:=
<-
raft
.
eventCh
switch
event
.
(
type
)
{
case
ClientAppend
:
case
*
ClientAppend
:
// Do not handle clients in follower mode. Send it back up the
// pipe with committed = false
ev
.
logEntry
.
commited
=
false
commitCh
<-
ev
.
logentry
case
VoteRequest
:
event
.
(
*
LogEntry
)
.
SetCommitted
(
false
)
raft
.
commitCh
<-
event
.
(
*
LogEntry
)
case
*
VoteRequest
:
msg
=
event
.
msg
if
msg
.
term
<
currentterm
,
respond
with
if
msg
.
term
>
currentterm
,
upgrade
currentterm
...
...
@@ -334,7 +334,7 @@ func (raft *Raft) follower() {
reset
timer
reply
ok
to
event
.
msg
.
serverid
remember
term
,
leader
id
(
either
in
log
or
in
separate
file
)
case
AppendRPC
:
case
*
AppendRPC
:
reset
timer
if
msg
.
term
<
currentterm
,
ignore
reset
heartbeat
timer
...
...
@@ -345,6 +345,6 @@ func (raft *Raft) follower() {
respond
ok
to
event
.
msg
.
serverid
else
respond
err
.
case
Timeout
:
return
candidate
// new state back to loop()
case
*
Timeout
:
return
candidate
// new state back to loop()
}
}
\ No newline at end of file
assignment3/src/server.go
→
assignment3/src/
raft/
server.go
View file @
9bbecccb
...
...
@@ -37,8 +37,7 @@ func initLogger(serverId int, toDebug bool) {
func
main
()
{
rand
.
Seed
(
time
.
Now
()
.
UnixNano
())
sid
,
err
:=
strconv
.
Atoi
(
os
.
Args
[
1
])
ch1
:=
make
(
chan
bool
)
ch2
:=
make
(
chan
bool
)
if
err
!=
nil
{
Info
.
Println
(
"argument "
,
os
.
Args
[
1
],
"is not string"
)
}
...
...
@@ -60,13 +59,4 @@ func main() {
commitCh
:=
make
(
chan
raft
.
LogEntry
)
rft
,
_
=
raft
.
NewRaft
(
clusterConfig
,
sid
,
commitCh
,
Info
)
raft
.
InitKVStore
(
Info
,
sid
)
go
raft
.
MonitorCommitChannel
(
commitCh
)
//for kvstore
go
initClientCommunication
(
server
,
rft
,
ch1
)
go
initInterServerCommunication
(
server
,
rft
,
ch2
)
for
<-
ch1
&&
<-
ch2
{
}
}
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